[SalesForce] Error: Method does not exist or incorrect signature: void getInstance() In trigger;

I'm with a requirement to populate two fields in Oppty, with the value of one field on Lead, only after the Lead conversion. One of those fields is already mapped through the native conversion of Lead, and the requeriment is to populate the other one with a before trigger.

We use a trigger framework with a trigger for Object, a TriggerHandler and a ObjectDomain.

But I'm receiving the error descripted in the Original Post.

Can you guys help me to understand what's the error I'm receiving and if there's anything that can be improved in the code.

Thanks in advance

public class OpportunityDomain {
    
    public void method1(List<Opportunity> newOpportunity, Map<Id, Opportunity> mapOldOpportunity){
        for (Opportunity Opp : newOpportunity){
            
            Opportunity OpportunityOld = (mapOldOpportunity != null) ? mapOldOpportunity.get(Opp.Id) : null;
            
            if(OpportunityOld == null){
                if(String.isNotBlank(Opp.fieldToPopulate__c)){
                    Opp.fieldToCopy__c = Opp.fieldToPopulate__c;
                }
            }
            else{
                if(String.isBlank(OpportunityOld.fieldToPopulate__c) && String.isNotBlank(Opp.fieldToPopulate__c)){
                    Opp.fieldToCopy__c  = Opp.fieldToPopulate__c;
                }
            }
        }
    }
}
public class OpportunityTriggerHandler extends TriggerHandler{
    
    public override void beforeInsert() {
        OpportunityDomain.getInstance().method1((List<SObject>) Trigger.new, (Map<Id, Opportunity>) Trigger.oldMap);
        
    }
public override void beforeUpdate() {
        OpportunityDomain.getInstance().method1((List<SObject>) Trigger.new, (Map<Id, Opportunity>) Trigger.oldMap);
trigger OpportunityTrigger on Opportunity (before insert, before update, before delete, after insert, after update, after delete, after undelete) {
    new OpportunityTriggerHandler().run();

Best Answer

You're missing the getInstance method in OpportunityDomain.

You should have:

static OpportunityDomain self = new OpportunityDomain();
public static OpportunityDomain getInstance() {
  return self; 
}

In your class.