Skip to main content
2 of 2
Fix code block formatting
Daniel Ballinger
  • 103k
  • 40
  • 275
  • 601

As far as your declaration for gcamount, I think you would be OK putting it right after the for statement. You then need to remove the multiple declarations in the if statements and just have the assignment: gcamount = o.Amount;, etc.

Also, in the first if statement, check the logical operators in your code; they should be doubled up - && and ||.

Here is my modification on your for loop-

for (Opportunity o : trigger.new){

    decimal gcamount;  //consider setting a default value here
            
    //Is the opportunity in question have a gift certificate as one of the payment methods?
//remember to double up logical operators
    if ((o.Pay_Method__c == 'Gift Certificate') || (o.Pay_Method__c == 'Multiple Methods' && (o.Multiple_Methods_1__c == 'Gift Certificate' || o.Multiple_Methods_2__c == 'Gift Certificate' )) && o.CreatedById !== '**********' ){

        //Does the gift certifiacte code refer to a gift certificate with a 
        if(mymap.contains(o.Gift_Certificate__c)){

            //Depending on the payment method, set the gcamount
//double check the logic here to make sure one of these will always be true
//or add a final else statement to set value, if a default was not set in declaration
            if (o.Pay_Method__c == 'Gift Certificate'){
                gcamount = o.Amount;
            }
            else if (o.Multiple_Methods_1__c == 'Gift Certificate'){
                gcamount = o.Multiple_Methods_Amount_1__c ;
            }
            else if (o.Multiple_Methods_2__c == 'Gift Certificate'){
                gcamount = o.Multiple_Methods_Amount_2__c ; 
            }

            //Create New Gift Card Usage
            Gift_Card_Usage__c gcu = new Gift_Card_Usage__c();
            gcu.Journal_Gift_Card_Usage__c = mymap.get(o.Gift_Certificate__c) ;
            gcu.Amount_Used__c = gcamount;

            //add to list
            lstgcusToInsert.add(gcu); *****LINE 38 - WHERE THE ERROR EXISTS*****
        }   
    }
}

Hope this helps

zjeh
  • 755
  • 5
  • 12