You need to sign in to do that
Don't have an account?
Developer post
trigger for cloning record of standard object Account
rigger cloningAccount on Account (after insert) {
if(clsStaticVar.blnIsOppInsert == false) {
return;
}
set<id> aid = new set<id>();
for(Account ac : Trigger.new){
if(ac.Name != null){
aid.add(ac.Id);
System.debug('cloningvalues:' + aid);
}
}
list<Account> alist = [select Name,Fax,Type,Active__C from Account Where Id in:aid];
if(clsStaticVar.blnIsOppInsert == true) {
clsStaticVar.blnIsOppInsert = false;
for(Account acc :alist){
Account a = new Account();
a.Name=acc.Name;
a.Fax=acc.Fax;
a.Type=acc.Type;
System.debug('cloningvalues1:'+a.Type );
System.debug('cloningvalues1:'+a.Rating );
System.debug('cloningvalues1:'+a.Industry);
insert a;
}
}
}
"The above trigger clones the records but only the fields mentioned in the code n not all. How can we clone it dynamically?"
if(clsStaticVar.blnIsOppInsert == false) {
return;
}
set<id> aid = new set<id>();
for(Account ac : Trigger.new){
if(ac.Name != null){
aid.add(ac.Id);
System.debug('cloningvalues:' + aid);
}
}
list<Account> alist = [select Name,Fax,Type,Active__C from Account Where Id in:aid];
if(clsStaticVar.blnIsOppInsert == true) {
clsStaticVar.blnIsOppInsert = false;
for(Account acc :alist){
Account a = new Account();
a.Name=acc.Name;
a.Fax=acc.Fax;
a.Type=acc.Type;
System.debug('cloningvalues1:'+a.Type );
System.debug('cloningvalues1:'+a.Rating );
System.debug('cloningvalues1:'+a.Industry);
insert a;
}
}
}
"The above trigger clones the records but only the fields mentioned in the code n not all. How can we clone it dynamically?"
However, You should use Apex describe to copy field values. This would help: http://christopheralunlewis.blogspot.in/2012/04/clone-plus-clone-salesforce-objects.html