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
arjuna Rajput 29arjuna Rajput 29 

can we solve this in trigger design pattern

trigger AccountCategory on Account (before insert,before update) { For (Account acc:Trigger.new){ if(acc.salary__c <=10000) acc.category__c='sample1'; else if (acc.salary__c>10000 && acc.Salary__c<=100000) acc.Category__c='sample2'; else acc.Category__c='sample3'; } }
arjuna Rajput 29arjuna Rajput 29
will you write handler code,helper class regarding this code
mukesh guptamukesh gupta
HI Arjuna,

Please follow below code:-
 
trigger AccountCategory on Account (before insert,before update) {
 
     TriggerHandler handler = new TriggerHandler();

   /* Before Insert */
    if(Trigger.isInsert && Trigger.isBefore){
        handler.OnBeforeInsert(Trigger.new);
    }/* Before Update */
    else if(Trigger.isUpdate && Trigger.isBefore){
        handler.OnBeforeUpdate(Trigger.old, Trigger.new, Trigger.newMap);
    }
 
 }
 
public class TriggerHandler{
 
     public void OnBeforeInsert(List<Account> newAcc){
        // EXECUTE BEFORE INSERT LOGIC
		For (Account acc:newAcc){
			if(acc.salary__c <=10000) 
			 acc.category__c='sample1'; 
			 else if (acc.salary__c>10000 && acc.Salary__c<=100000) 
			 acc.Category__c='sample2'; 
			 else acc.Category__c='sample3'; 
			 } 
			
    }

  
    public void OnBeforeUpdate(List<Account> oldObjects, List<Account> updatedObjects, Map<Id,Account>MapObjectMap){
        // BEFORE UPDATE LOGIC
    }
 
 }

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
arjuna Rajput 29arjuna Rajput 29
HELLO MUKESH,
method defining in helperclass(whether it is isupdate or isinsert).we call these method in Handler class.....Trigger in which we call our Handler class we also need...
We dont want for single record we do for multiple record so we do this program using Triggers design pattern in which we have Handler_class,Helper_class and Trigger.
arjuna Rajput 29arjuna Rajput 29
Will you send  these 3 code HELPER CLASS,HANDLER WITH TRIGGER