+ Start a Discussion
GauravTrivediGauravTrivedi 

Sort given object in parent child fashion

I have given number of objects in set need to order them according to their lookup objects. For example, I have a set of following objects:
  1. Lead
  2. Account
  3. Campaign
  4. Contact
From the above object I have to find their refrence fields and then create a set from parent to their child, like this:
  1. Account
  2. Contact
  3. Lead
  4. Campaign
I am using Schema class to find their refrences but not able to sort then in the proper order.
Any help will be greatly appreciated. Thanks!
pconpcon
I'm not sure I really follow what you have and what you are trying to do.  You say you have "objects in set", are you saying you have them in apex like Set<sObject>?  Can you provide the code that you currently have to get them in the unordered way?  Then we can help you get them in the order you want.

NOTE: When including code please use the "Add a code sample" button (icon <>) to increase readability and make referencing code easier.