You need to sign in to do that
Don't have an account?
Sujji
Http.Send not working
Hi,
I am trying to make a callout from a Queuable Class that allows callouts.
public without sharing class ClassA implements Queueable, Database.AllowsCallouts {
public void execute(QueueableContext context) {
sendRef(varA, varB);
}
public static void sendRef(String varA, String varB) {
HTTP call1 = new HTTP();
HTTPRequest request1 = new HTTPRequest();
.....
response = call1.send(request1)
...
}
This class is called from a) Batch process and also from b) Custom Button.
When called from batch:
System.enqueueJob(
new ClassA(Parm1, Parm2)
);
When called from button:
ClassA.sendRef(Parm1, Parm2);
Now the issue is that the statement http.send(request) is not working recently from Batch. Can anyone please help.
The same piece of code is working when submitted as a queuable .
I am trying to make a callout from a Queuable Class that allows callouts.
public without sharing class ClassA implements Queueable, Database.AllowsCallouts {
public void execute(QueueableContext context) {
sendRef(varA, varB);
}
public static void sendRef(String varA, String varB) {
HTTP call1 = new HTTP();
HTTPRequest request1 = new HTTPRequest();
.....
response = call1.send(request1)
...
}
This class is called from a) Batch process and also from b) Custom Button.
When called from batch:
System.enqueueJob(
new ClassA(Parm1, Parm2)
);
When called from button:
ClassA.sendRef(Parm1, Parm2);
Now the issue is that the statement http.send(request) is not working recently from Batch. Can anyone please help.
The same piece of code is working when submitted as a queuable .
Thanks for reply. Heres the complete code.
The class where the call out is happening:
public without sharing SendQueueable implements Queueable, Database.AllowsCallouts {
public SendQueueable(String varA, String varB) {
this.varA = varA;
this.varB = varB;
}
public void execute(QueueableContext context) {
requestCallout(varA, varB);
}
public static void requestCallout(String varA, String varB) {
Logger logger = new Logger();
try {
HTTP call1 = new HTTP();
HTTPRequest request1 = new HTTPRequest();
HTTPResponse response1 = new HTTPResponse();
String endPointURL = End_Point_URL__c;
String reqBodyForAuth =
'grant_type=password&client_id=' + EncodingUtil.urlEncode(Consumer_Key__c, 'UTF-8') +
'&client_secret=' + EncodingUtil.urlEncode(Consumer_Secret__c, 'UTF-8') +
'&username=' + EncodingUtil.urlEncode(User_Name__c, 'UTF-8') +
'&password=' + EncodingUtil.urlEncode(Password__c, 'UTF-8');
String securityToken = Security_Token__c;
if (securityToken != null && securityToken != '') {
reqBodyForAuth = reqBodyForAuth + securityToken;
}
System.debug('reqBodyForAuth:'+ reqBodyForAuth);
request1.setBody(reqBodyForAuth);
request1.setMethod('POST');
request1.setTimeout(30000);
request1.setEndpoint(endPointURL + '/services/oauth2/token');
String body;
System.debug('@@@Before call for access token: '+request1.getBody());
body = call1.send(request1).getBody();
}
} catch (Exception e) {
logger.error(e);
} finally {
logger.flush('Log - ' + Date.today());
}
}
}
The Trigger code where this class is called:
public static void callQueueable(varA varB) {
if (callFromCustomButton) {
System.enqueueJob(new ClassA(varA, varB));
}
else if (callFromBatchClass) {
SendQueueable.requestCallout(varA, varB);
}
}
defined below variable in class before constructor
String varA,varB;
and can You tell me where you defined in class varible 'End_Point_URL__c'.
If this is sObject then how you getting these value in class