Guest User

Untitled

a guest
Jul 11th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. Map<String, String> childListMap = new Map<String,String>();
  2. List<Schema.Childrelationship> childList = Schema.getGlobalDescribe().get('Account').getdescribe().getChildRelationships();
  3. for(Schema.ChildRelationship cr : childList){
  4. //system.debug(cr.getChildSObject());
  5. //system.debug(cr.getField());
  6. childListMap.put(String.valueOf(cr.getChildSObject()),String.valueOf(cr.getField()));
  7. }
  8. System.debug(childListMap.size());
  9. for(String s : childListMap.keySet()){
  10. System.debug('Obj: ' + s + ' Field: ' + childListMap.get(s));
  11. }
  12.  
  13. String obj,field;
  14. String queryString;
  15. Map<String,List<SObject>> objMap = new Map<String,List<SObject>>();
  16. for(String s : childListMap.keySet()){
  17. obj = s;
  18. field = childListMap.get(s);
  19. queryString = 'SELECT ' + field + ' FROM ' + obj + ' WHERE ' + field + ' = ' + accId;
  20. List<SObject> objResult = Database.query(queryString);
  21. if(obj.size() > 0){
  22. objMap.put(obj,objResult);
  23. }
  24. }
Add Comment
Please, Sign In to add comment