function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Developer postDeveloper 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?"
AshwaniAshwani
There is a clone method for all sObjects look at following link: http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_methods_system_sobject.htm

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