Problem statement:
If the customer phone number was enrolled in free water scheme for 2020, status field in 2021 scheme object should ''You cannot avail this scheme in 2021, as you have already received free water in 2020'.
Error on Trigger:
Method does not exist or incorrect signature: void CheckPreviousYearEntryByPhoneNumber(list) from type FreeWaterSchemeClass
APEX CLASS:
public class FreeWaterSchemeClass{
public static list<2021_Scheme__c> 2021SchemeList = [SELECT Phone__c FROM 2021_Scheme__c];
public static list<2020_Scheme__c> 2020SchemeList = [SELECT Phone__c FROM 2020_Scheme__c];
public static set<string> 2020_Scheme_Set = new set<string>();
// function to check if the customer has been enrolled in the 2020 scheme, before data entry into 2021 scheme.
public static void CheckPreviousYearEntryByPhoneNumber()
{
for (2020_Scheme__c s: 2020SchemeList)
{
2020_Scheme_Set.add(s.Phone__c);
}
//if the phone number is found
for(2021_Scheme__c s : 2021SchemeList)
{
if(2020_Scheme_Set.contains(s.Phone__c))
{
s.Status = 'You cannot avail this scheme in 2021, as you have already received free water in 2020';
}
else
{
s.Status = 'You are eligible for free water in 2021.';
}
}
}
}
TRIGGER:
trigger 2021FreeWater_Trigger on 2021_Scheme__c (before insert) {
if(Trigger.IsInsert == true)
{
FreeWaterSchemeClass.CheckPreviousYearEntryByPhoneNumber(Trigger.new);
}
}