0

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();

1 Answer 1

0

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.

3
  • Thanks it Worked nicely!!! I'd like to ask you a question If I may... What is the getInstance Method? I searched somethings about it, and read about it being similar to getValues(), both used when dealing with custom permissions.
    – RedMan
    Jun 25, 2020 at 19:00
  • @Growred It's just a custom method to return a singleton. This is pretty common in many trigger frameworks.
    – sfdcfox
    Jun 25, 2020 at 19:01
  • Thanks Again!!!
    – RedMan
    Jun 25, 2020 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.