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 ?
static
keyword beforeString OppId;
and that should solve the issue. You can reference onlystatic
variables inside thestatic
block and any variable without thestatic
keyword is assumed asinstance
variable.