Custom Cloning of Object using dynamic SOQL
If you want to clone custom object along with its child objects then standard won’t work. Standard cloning only clone the object record itself and does not clone its child objects.
In order to fulfil that requirement you have create custom clone button and invoke a webservice. Javascript which needs to be written to call webservice is not included in this example.
Standard Clone method only copy the fields which are queried from object and as you know fields may change during developmemt so in order to make a solution flexible and not dependent on fields we can make dynamic SOQL for quering the fields.
The below example will clone object (Clone_Object__c) record along with its child (Clone_Object_Child__c) record and redirect the user to new cloned record without having dependency of fields.
Code Snippet