You need to sign in to do that
Don't have an account?
Salesforce Developer 60
how to scheduler this webservicecall class daily 10 AM
Hello Team,
I created following class now i want to schedule this class to run daily at 10 AM . I already created a scheduler class and it schedule correctly but when it run it will give error like arguments not be null .
Here is my webservice class.
here is Scheduler class
I created following class now i want to schedule this class to run daily at 10 AM . I already created a scheduler class and it schedule correctly but when it run it will give error like arguments not be null .
Here is my webservice class.
public with sharing class WebserviceCall { public WebserviceCall(ApexPages.StandardController controller) { } public String message {get; set;} public PageReference getaccesstoken() { string jsonstring ='userName=test@gmail.com&Password=123&grant_type=password'; HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); // req.setClientCertificateName('Client Certificate'); req.setEndpoint('http://google.com'); req.setMethod('POST'); // req.setHeader('SOAPAction', 'Soap Action'); //req.setHeader('Authorization','Auth Token'); req.setBody(jsonstring); try { res = http.send(req); message = res.getBody(); TokenInformation token = new TokenInformation(); token =(TokenInformation)System.JSON.deserialize(message, TokenInformation.class); // JSONParser parser = JSON.createParser(res.getBody()); System.debug(token.access_token); //HttpServletResponse httpResponse = (HttpServletResponse)response; string s = token.access_token; string a1 = s.substring(0,255); string a2 = s.substring(255,510); string a3 =s.substring (510,s.length()); //Here SessionData__c is custom setting used for store access_token SessionData__c objToken = new SessionData__c(); objToken.Name ='token2'; objToken.Id ='a0G28000000ENAI'; objToken.Access_Token1__c =a1;objToken.Access_Token2__c =a2; objToken.Access_Token3__c =a3; upsert objToken; } catch(System.CalloutException e) { System.debug('Callout error: '+ e); message = res.toString() + res.getBody(); System.debug(res.toString()); } return null; } }
here is Scheduler class
global class scheduledWebServiceCall implements Schedulable { global void execute(SchedulableContext sc) { Account acc = new Account(); Apexpages.Standardcontroller controller_inv = new Apexpages.Standardcontroller(acc); WebserviceCall b = new WebserviceCall(controller_inv); b.getaccesstoken(); system.debug( b.getaccesstoken()); } }
Might be you response returned as null. I just added few condition in your code. Can you try your schedule with the below code,
Is your webservice call working in vf? or totally your class not working?
could you please elobarte what you are trying to do ?