You need to sign in to do that
Don't have an account?

How to clone any Sobject with Related lists(including chatter) and attachments in Salesforce Lightning
Hi Everyone,
I have a requirement to deep clone/ super clone a custom object with it's related lists (related lists includes chatter), and attachments links that directs to original attachment( don't want to duplicate attachments). For this requirement I used a custom code that supports on any sobject but, it's doing just basic clone not deep/super clone.
Please see below:
I have a requirement to deep clone/ super clone a custom object with it's related lists (related lists includes chatter), and attachments links that directs to original attachment( don't want to duplicate attachments). For this requirement I used a custom code that supports on any sobject but, it's doing just basic clone not deep/super clone.
Please see below:
public class CloneSingleRecord { @AuraEnabled public static String cloneAnySobjet(String recordId){ Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); List<Attachment> attachments = new List<Attachment>(); list<Attachment> attachlist = new list<Attachment>(); String objectAPIName = ''; String keyPrefix = recordId.substring(0,3); for( Schema.SObjectType obj : schemaMap.Values() ){ String prefix = obj.getDescribe().getKeyPrefix(); if(prefix == keyPrefix){ objectAPIName = obj.getDescribe().getName(); break; } } Set <String> fieldMap = schemaMap.get(objectAPIName).getDescribe().fields.getMap().keySet(); String soqlQuery = 'SELECT ' ; for (String s :fieldMap ){ if(schema.getGlobalDescribe().get(objectAPIName).getDescribe().fields.getMap().get(s).getDescribe().isAccessible()){ soqlQuery += + s+','; } } soqlQuery = soqlQuery.removeEnd(','); soqlQuery += ' FROM ' +objectAPIName +' WHERE ID = \'' + recordId +'\'' ; System.debug('soqlQuery'+soqlQuery); SObject record = Database.query(soqlQuery); SObject clondedParentRecordID= record.clone(false, true, true, false); try{ insert clondedParentRecordID ; return clondedParentRecordID.id ; }catch(Exception e){ return '' ; } } }How can I modify this code to get my requirement done ?
Thank you for your time, but I have used https://rajvakati.com/2018/10/17/lightning-component-clone-with-related-records/ . Because our team decided not to built a nw visualforce page.
Thank you so much for your help and time.
All Answers
I've gone through your requirement and you can refer the below code for creating the clone button on yusing vf page:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Thank you so much for taking time and looking into the code, I will try your method and check. Meanwhile can I know if there is any possibility to clone attachments link from parent Id rather than cloning entire attachment and creating duplicates.
Thanks in advance.
Thank you for your time, but I have used https://rajvakati.com/2018/10/17/lightning-component-clone-with-related-records/ . Because our team decided not to built a nw visualforce page.
Thank you so much for your help and time.