0

This is my class

global class ProjectCalloutService1  {

String OppId;

@InvocableMethod
public static void postOpportunityToPMS(List<Id> oids)
{

     OppId = oids[0];

}

global class QueueablePMSCall implements Queueable, Database.AllowsCallouts
{
   public void execute(QueueableContext context)
   {

    Opportunity o = [SELECT ID,Name,Account.Name,CloseDate,Amount FROM Opportunity WHERE Id = '1'];

    ServiceTokens__c s = ServiceTokens__c.getValues('ProjectServiceToken');
    System.debug(s.Token__c);

    String jsonInput = '{\n' +
    ' "opportunityId" : "'+o.Id+'",\n'+
    ' "opportunityName" : "'+o.Name+'",\n'+
    ' "accountName" : "'+o.Account.Name+'",\n'+
    ' "closeDate" : "'+String.ValueOf(o.CloseDate).mid(0,10)+'",\n'+   
    ' "amount" : '+o.Amount+'\n'+
    '}';

    HTTPRequest req = new HTTPRequest();
    req.setEndPoint('callout:ProjectService');
    req.setMethod('POST');
    req.setHeader('Content-Type', 'application/json');
    req.setHeader('Token', s.Token__c);
    req.setBody(jsonInput);

    HTTP h = new HTTP();
    HTTPResponse res = h.send(req);
    System.debug('~~~ REQ BODY '+req.getBody());
    System.debug('~~~ REQUEST '+req.toString());
    System.debug('~~~ RESPONSE '+res);

    if(res.getStatusCode() == 201)
    {
      o.Type = 'Submitted Project';
      update o;
    }

   }

} 


}

I still have not finished developing this class so kindly excuse if it does not make sense.

My concern is with respect to compiler error that I am getting which says below

Error: Compile Error: Variable does not exist: OppId at line 9 column 6

I have tried adding global and public access modifiers in front of "String OppId" without success.

I thought as per OO principles a member variable can be accessed by all member methods within the same class.

When that being the case why my method "postOpportunityToPMS" complains that the variable "OppId" does not exist ?

  • 1
    Add static keyword before String OppId; and that should solve the issue. You can reference only static variables inside the static block and any variable without the static keyword is assumed as instance variable. – javanoob Jan 31 '17 at 5:46
2

You are trying to reference instance variable inside a static method, which is not allowed.

This is Instance variable:

String OppId;

This is static variable:(this variable now can be used in static methods.)

Static String OppId;

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.