You need to sign in to do that
Don't have an account?
System.HttpResponse[Status=Unauthorized, StatusCode=401]
Hi,
I am Calling future method from schedule apex, getting an error: System.HttpResponse[Status=Unauthorized, StatusCode=401]
I think we are getting because of UserInfo.getSessionId() null, If I comment hilighted line also I am getting same error. Is there any solution for this. or Can I schedule the callouts?
Thanks
Venkat
I am Calling future method from schedule apex, getting an error: System.HttpResponse[Status=Unauthorized, StatusCode=401]
I think we are getting because of UserInfo.getSessionId() null, If I comment hilighted line also I am getting same error. Is there any solution for this. or Can I schedule the callouts?
public class Sample { @future(Callout = true) public static void getCoverageforClasses() { String objectIdQuery = 'SELECT ApexClassorTriggerId, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate'; String environmentURL = URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v28.0/tooling/query/?q=' + EncodingUtil.urlEncode(objectIdQuery, 'UTF-8'); HttpRequest req = new HttpRequest(); req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); req.setHeader('Content-Type', 'application/json'); req.setEndpoint(environmentURL); req.setMethod('GET'); Http h = new Http(); return h.send(req).getBody(); } }
Thanks
Venkat
1.Bad request URL. Copy-pasting URL from your code to a browser may validate.
2.Wrong protocol. If the endpoint requires HTTPS and your URL uses HTTP.
3.Bad IP. You said that the provider has whitelisted the SFDC IPs, but perhaps they made an error. If you are able to test from a browser from a non-4.whitelisted IP (e.g., from home), you can determine if you get the same error.
5.Some other error at the endpoint. If everything else fails, you may need to ask the provider to check their logs.
Future Method Considerations
• Remember that any method using the future annotation requires special consideration because the method does not
necessarily execute in the same order it is called.
• Methods with the future annotation cannot be used in Visualforce controllers in either getMethodName or
setMethodName methods, nor in the constructor.
• You cannot call a method annotated with future from a method that also has the future annotation. Nor can you call
a trigger from an annotated method that calls another annotated method.
• The getContent and getContentAsPDF PageReference methods cannot be used in methods with the future
annotation
and we can schedule the callouts from scheduler class.
Thanks,
RAmesh
Thanks!
Can you please send me the sample code to schedule the callouts from scheduler class.
Thanks
Venkat.
Please send any code on Tooling API objects for scheduling http callouts.
Thanks
Venkat
the above code will calculate the logitide and latitude values of account address.
Thanks,
Ramesh
Did you get resolution of this issue? I'm also getting exactly same issue with same code lines in one of the org. In other orgs it is working fine.
Thanks
CP Chouksey