+ Start a Discussion
Sam MalhotraSam Malhotra 

Trigger to Insert new record

Create a Trigger on Account to insert a new record and make a custom field..when trigger save a record after that record id will show in custom field on Account..
Best Answer chosen by Sam Malhotra
v varaprasadv varaprasad
Hi Sam ,

Please check once below code : 
 
trigger ShowAccountId on Account (after insert) {
    list<account> lstAcc = new list<account>();
    
    for(account a : trigger.new){
        system.debug('account ID '+a.id);
        if(a.id != null){
            account acc = new account();
            acc.id = a.id;
            acc.Description = a.id;
            lstAcc.add(acc);
        }
    }
    update lstAcc;
}
Hope this helps.
If this is the answer please mark it As Best Answer.

Thanks
Varaprasad​

All Answers

v varaprasadv varaprasad
Hi Sam ,

Please check once below code : 
 
trigger ShowAccountId on Account (after insert) {
    list<account> lstAcc = new list<account>();
    
    for(account a : trigger.new){
        system.debug('account ID '+a.id);
        if(a.id != null){
            account acc = new account();
            acc.id = a.id;
            acc.Description = a.id;
            lstAcc.add(acc);
        }
    }
    update lstAcc;
}
Hope this helps.
If this is the answer please mark it As Best Answer.

Thanks
Varaprasad​
This was selected as the best answer
Sam MalhotraSam Malhotra
Thanks!!! 
Mr. Varaprasad​