I am just running of the assumption that method2() will be called after method1() as per your question, you concatenate the error messages as a string and add the error message in the method2.
concatenatedstring = '';
Method1(casesList){
concatenatedstring += 'my first error method /n';
}
Method2(casesList){
concatenatedstring += 'my second error method /n';
eadderror(concatenatedstring);
}
Update:
- I relooked into the code and realized the method1() and method2() are accepting list params, so my previous code is absurd as adrian pointed out.
- This should be after insert in my opinion ( if you want this to be before insert then you can modify the key by adding other info like caseinfo, casenumber etc,, and make the key unique in the error map. Make sure to check if the field that you are using to generate the key is not null or even better form the key using a required field) because you need to know the id of the record to associate the errors to the account, Id is not available in a before insert context.
I created a small POC in my dev box with account rewrite your code for your usecase/object.
trigger beforeinserttest on Account (after insert) {
accounttrighandler ac_handler = new accounttrighandler();
ac_handler.method1(trigger.new);
ac_handler.method2(trigger.new);
}
public class accounttrighandler{
public map<string,string> errormap = new map<string,string>();
public void method1(List<account> acc1){
for(account a1: acc1){
if(!errormap.containsKey(a1.id)){
errormap.put(a1.id,'METHOD 1: adding error 1 '+a1.id);
}
}
}
public void method2(List<account> acc2){
for(account a2: acc2){
if(errormap.containsKey(a2.id)){
a2.adderror('Account '+a2.id+ ' contains errors ' + errormap.get(a2.id) + ' METHOD 2: adding erorr 2 '+a2.id);
}
}
}
}