I have a handler class that processes all actions from a custom object trigger. In the class I have a method for after insert and another method for after update. When a record is inserted I have a method to create new records that works great. When a record is updated I want to have some logic check if there were changes and then do some actions. Then go and create new records, it doesn't make sense to write two identical sections for creating new records so I want to reuse the same method. I don't know what the wording is for a google search so how do you pass data from one method to another within the same class?
Example:
public override void afterInsert(Map<Id, SObject> newMap){
createRecords(newMap);
}
public override void afterUpdate(Map<Id, SObject> newMap){
checkRecords(newMap);
}
public void createRecords(Map<Id, SObject> newMap){
// some logic
insert records;
}
public void checkRecords(Map<Id, SObject> newMap, oldMap){
// logic checks changes between newMap oldMap
// If true send to delete method else nothing
deleteRecords();
}
public void deleteRecords(Map<Id, Sobject> newMap){
// get record id from checkRecords
delete records;
// send to createRecords method to create new records
createRecords();
}
When I write the checkRecords method and try to call the deleteRecords it says
Method does not exist or incorrect signature:
deleteSchedule(List Revenue_Pipeline__c>)
public void checkUpdate(Map<Id, Revenue_Pipeline__c> newMap, Map<Id, Revenue_Pipeline__c> oldMap)
{
List<Revenue_Pipeline__c> revPipeline = new List<Revenue_Pipeline__c>();
// Check if the fields changed
for(Revenue_Pipeline__c revPipe : newMap.values())
{
if(
revPipe.Product_Start_Date__c != oldMap.get(revPipe.Id).Product_Start_Date__c ||
revPipe.Product_End_Date__c != oldMap.get(revPipe.Id).Product_End_Date__c ||
revPipe.Product_Price__c != oldMap.get(revPipe.Id).Product_Price__c ||
revPipe.Opportunity__r.Probability != oldMap.get(revPipe.Id).Opportunity__r.Probability)
{
revPipeline.add(revPipe);
}
}
deleteSchedule(revPipeline);
}
// Delete Revenue_Pipeline_Schedule records
public void deleteSchedule(Map<Id, Revenue_Pipeline_Schedule__c> revPipeline)
{
}