daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top