Play Games

Search This Blog

Showing posts with label get the source record from which the current record is cloned from in salesforce apex. Show all posts
Showing posts with label get the source record from which the current record is cloned from in salesforce apex. Show all posts

Thursday, June 23, 2022

get the source record from which the current record is cloned from in salesforce apex - SalesforceGlobe4U

Solution: Use the getCloneSourceId() to get the source record from which the current record is cloned from.

Example: In the below piece of code,initially I created one account and then created another account by cloning the first account.

Run the code from the developer console.

Account objAccount = new Account(Name = 'Test Account');

insert objAccount;

system.debug('Account Record Id :'+objAccount.Id);

system.debug('Is this account Cloned? :'+objAccount.isClone());

Account objAccount2 = objAccount.clone();

system.debug('Is this account Cloned? :'+objAccount2.isClone());

insert objAccount2;

system.debug('Account Record Id :'+objAccount2.Id);

system.debug('Source account from which it is cloned :'+objAccount2.getCloneSourceId());

Output: