Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger CloneAccount on account (after insert) {
list<Account> accToClone = new list<Account>();
list<Account> accToSave = new list<Account>();
Set<Id> AccountIds = new Set<Id>();
For(account acc : trigger.new)
{
AccountIds.add(acc.id);
accToClone.add(acc);
}
Map<Id,Account> accountMap = new Map<Id,Account>([
select Id, Name, Description,Type, Phone, Fax from Account where Id IN: AccountIds]);
for (Account acc :accToClone)
{ Account Clone = new Account();
Clone.Name = accountMap.get(acc.id).Name;
Clone.Type = accountMap.get(acc.id).Type;
Clone.Phone = accountMap.get(acc.id).Phone;
Clone.Fax = accountMap.get(acc.id).Fax;
Clone.Description = accountMap.get(acc.id).Description;
accToSave.add(Clone);
}
if(CloneAccountRecursive.isTrigger == True){
CloneAccountRecursive.isTrigger = False;
insert accToSave;
}
}
Class Code: -
public class CloneAccountRecursive{
public static boolean isTrigger = true;
}
Use this code to clone your account
All Answers
You can do this task with the help of trigger and Process Builder.
To get Inf. refer this link:
http://automationchampion.com/2015/02/16/getting-started-with-process-builder-part-3-clone-a-record/
Thanks
trigger CloneAccount on account (after insert) {
list<Account> accToClone = new list<Account>();
list<Account> accToSave = new list<Account>();
Set<Id> AccountIds = new Set<Id>();
For(account acc : trigger.new)
{
AccountIds.add(acc.id);
accToClone.add(acc);
}
Map<Id,Account> accountMap = new Map<Id,Account>([
select Id, Name, Description,Type, Phone, Fax from Account where Id IN: AccountIds]);
for (Account acc :accToClone)
{ Account Clone = new Account();
Clone.Name = accountMap.get(acc.id).Name;
Clone.Type = accountMap.get(acc.id).Type;
Clone.Phone = accountMap.get(acc.id).Phone;
Clone.Fax = accountMap.get(acc.id).Fax;
Clone.Description = accountMap.get(acc.id).Description;
accToSave.add(Clone);
}
if(CloneAccountRecursive.isTrigger == True){
CloneAccountRecursive.isTrigger = False;
insert accToSave;
}
}
Class Code: -
public class CloneAccountRecursive{
public static boolean isTrigger = true;
}
Use this code to clone your account