Full error message:
AddRelatedRecord: execution of AfterInsert caused by: line 2, column 42: Method does not exist or incorrect signature: void addRecords() from the type AddRelatedRecordTriggerHandler
My TriggerHandler Class:
public class AddRelatedRecordTriggerHandler {
public static void addRecords(List<Opportunity> newOpportunities) {
System.debug(newOpportunities);
List<Opportunity> oppList = new List<Opportunity>();
for (Account a : [SELECT Id, Name FROM Account
WHERE Id IN :newOpportunities AND
Id NOT IN (SELECT AccountId FROM Opportunity)]) {
oppList.add(new Opportunity(Name=a.Name + ' Opportunity',
StageName='Prospecting',
CloseDate=System.today().addMonths(1),
AccountId=a.Id));
}
if (oppList.size() > 0) {
insert oppList;
}
}
}
The trigger:
trigger AddRelatedRecord on Account (after insert, after update) {
AddRelatedRecordTriggerHandler().addRecords(Trigger.new);
}
I have tried every workaround am aware of to no avail... Please enlighten me...
Hi Nathan, when calling static methods you should instantiate the class. Just use the class name to call the static methods.
This should solve your error . Change your code on the trigger like below
AddRelatedRecordTriggerHandler.addRecords(Trigger.new);