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;
}