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.
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.