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
kaustubh chandratre 2kaustubh chandratre 2 

trigger on Account object that will insert a new Account with same name when the value of Active__c field is change from true to false.

Sai PraveenSai Praveen (Salesforce Developers) 
Hi ,

If the Account is changed twice from True to False means two Accounts need to be created?

Can you check the below trigger.
 
trigger ActiveChange on Account (before update) {
    List<Account> newaccounttocraete= New List<Account>();
    for(Account acc:Trigger.new){
        Account oldacc= Trigger.oldmap.get(acc.id);
        if(!acc.Active__c && oldacc.Active__c ){
            Account accnew= new Account();
            accnew.Name= acc.name;
            newaccounttocraete.add(accnew);
        }
        
    }
 insert newaccounttocraete;
}
 

Let me know if you face any issues.

 

If this solution helps, Please mark it as best answer.

 

Thanks,