Monday 2 May 2011

(Describe Information)How to retrieve all the fields in an Object


Recently i had a requirement of merging two accounts(Say one as "Parent" Account and other as "Child" Account).Following is one of the point listed out in requirement

If a parent Account field doesn’t contain a value and child Account contains that value, then the child Account field's value is populated in the parent field. ( On a lighter note ,how do people get these ideas  Note :This sentence is not a part of requirement though :) :) )

We have nearly 250+ fields(:O ..i dnt even remember 10% of those) in Account and according to the requirement almost all writable fields should be queried and checked for the blank/null value.

Requirement at
1) First we used the describe calls to get the list of fields available for the Object.
2) Looped through the fields available for the object and constructed the soql string for quering the records .
3) Returned the Parent record and child record based on the query constructed
4) Compared Parent and child account fields by using sobject method and updated accordingly


Please find the code snippet for this





Any better solution for this is highly appreciated :)

No comments:

Post a Comment