Skip to main content
added 288 characters in body
Source Link
Daniel Ballinger
  • 103k
  • 40
  • 275
  • 601

Declare gcamount so it is in scope within the if statement.

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

            // Declaring gcamount here will make it in-scope within the above if statement.
            // A wider scope risks other iterations of the for loop changing the value.
            // Set a suitable default value here
            decimal gcamount = 0; 

            //Depending on the payment method, set the gcamount
            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) ;
            
            // Error was most likely here in the question
            gcu.Amount_Used__c = gcamount;

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

Declare gcamount so it is in scope within the if statement.

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

            decimal gcamount = 0;
            //Depending on the payment method, set the gcamount
            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*****
        } 

Declare gcamount so it is in scope within the if statement.

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

            // Declaring gcamount here will make it in-scope within the above if statement.
            // A wider scope risks other iterations of the for loop changing the value.
            // Set a suitable default value here
            decimal gcamount = 0; 

            //Depending on the payment method, set the gcamount
            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) ;
            
            // Error was most likely here in the question
            gcu.Amount_Used__c = gcamount;

            //add to list
            lstgcusToInsert.add(gcu);
        } 
Source Link
Daniel Ballinger
  • 103k
  • 40
  • 275
  • 601

Declare gcamount so it is in scope within the if statement.

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

            decimal gcamount = 0;
            //Depending on the payment method, set the gcamount
            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*****
        }