1

I am trying to run a class in execute anonymous window to test, but am encountering an odd error.

Here is a simplified version of the class:

public class AddEmailProduct1 {

     public static void AddEmailAndSchedule (Opportunity Op){

        OpportunityLineItem OLI = new OpportunityLineItem (); 
         OLI.OpportunityId=Op.id;
         OLI.PricebookEntryId=Op.Pricebook2Id;
         OLI.Quantity=1;
         OLI.dclk__DSM_ProdName__c='Email';
         OLI.dclk__LI_StartDate__c=System.now();
         OLI.dclk__LI_EndDate__c=System.now();

         Database.insert(OLI,false);

    }

}

Here is my Execute Anon window:

AddEmailProduct1.AddEmailAndSchedule(0063D000002Oe6k);

Here is the error:

Line: 1, Column: 41 expecting a right parentheses, found 'D000002Oe6k'

How do I call this class from Execute Anon window ?

6

You need to wrap your string in single quote characters (''):

someMethod('0063D00...')
//         ^          ^ You need these single quote characters

You also need to look at the signature, it accepts an Opportunity instance, not Id. In your particular case, you just need to construct a record and pass it in:

AddEmailProduct1.AddEmailAndSchedule(new Opportunity(Id='006...'));

You could also overload or re-write your method to just accept an Id:

public static void foo(Opportunity record)
{
    foo(record.Id);
}
public static void foo(Id recordId)
{
    // do stuff
}

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.