I am pretty new to SFDC. I am trying to implement a clone functionality of a custom object by which when I am cloning an object, the object as well as all the object in its related list are to be cloned. I have implemented the part of cloning a object but stuck how to get the object list associated with a object's related list. pls let me know , how to implement this.

  • 1
    This library might give you what you need, salesforce.stackexchange.com/questions/8493/…. If not you can study the code to figure out how to use Apex Describe to get the child relationship information. Sorry don't have time to do a full answer on this at present, but thought I'd post this in the meantime. – Andrew Fawcett Nov 6 '13 at 1:31

If the related list is already in memory you can clone it directly. For example:

List<Related_List_Object__c> relatedList = [SELECT Id, Field1__c, ... WHERE ParentId =: ...]

Then you can deepClone that list and save the results:

List<Related_List_Object__c> newList = relatedList.deepClone(false, false, false);
insert newList;

Details of deepClone should help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.