0

I have written this method to get accesstoken when I send Id & password given(Which I havent Hardcoded Below). I am saving my access token in custom setting and want it to expire, call this method again and save a new token at 12:01am every night. Any suggestions?

public static string Login(){
   HttpRequest req = new HttpRequest();
   req.setEndpoint('xyz');
   req.setMethod('POST');
   req.setHeader('Content-Type', '');
   req.setBody('{ "id" : "+Id+", "password" : "+Password+" }');

 Http http = new Http();
 HTTPResponse res = http.send(req);
 System.debug(res.getBody());

 if(res.getstatuscode()==200)
 {
     Map<string,string> result=(map<string,string>) 
   JSON.deserializeUntyped(res.getbody());
     access_token =string.valueOf(result.get(access_token));
    AccessToken__c At = AccessToken__c.getorgdefaults();
     at.Token__c = access_token;
 }
  return access_token;
}

1 Answer 1

2

You could use the Schedulable interface to make the schedulable and schedule this class to run at 12:01 AM everyday.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .