You need to sign in to do that
Don't have an account?

HTTP Callout Request
Hello Fellow Salesforce Developers!
I have a apex class that are not covered and was hoping to get help in writing the codes for it. I'm at 35% and have been working on this for about a week now and cannot figure it out. Any help that you could provide is greatly appreciated, thank you in advance. :) The lines that I need to cover are as followed:
public void execute(SchedulableContext ctx) {
refreshMetrics(null);}
---
HttpRequest req = new HttpRequest();
String url = INSTANCE + '/services/data/v33.0/actions/standard/metricRefresh';
req.setEndpoint(url);
req.setMethod('POST');
req.setHeader('Authorization', 'OAuth ' + sessionId);
req.setHeader('Force-Instance-Url', INSTANCE);
req.setHeader('Force-User-Id', userId);
req.setHeader('Accept', 'application/json');
req.setHeader('Content-Type', 'application/json');
req.setBody('{"inputs":[{"metricId":"' + metricId + '"}]}'); // metric id
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
}
I have a apex class that are not covered and was hoping to get help in writing the codes for it. I'm at 35% and have been working on this for about a week now and cannot figure it out. Any help that you could provide is greatly appreciated, thank you in advance. :) The lines that I need to cover are as followed:
public void execute(SchedulableContext ctx) {
refreshMetrics(null);}
---
HttpRequest req = new HttpRequest();
String url = INSTANCE + '/services/data/v33.0/actions/standard/metricRefresh';
req.setEndpoint(url);
req.setMethod('POST');
req.setHeader('Authorization', 'OAuth ' + sessionId);
req.setHeader('Force-Instance-Url', INSTANCE);
req.setHeader('Force-User-Id', userId);
req.setHeader('Accept', 'application/json');
req.setHeader('Content-Type', 'application/json');
req.setBody('{"inputs":[{"metricId":"' + metricId + '"}]}'); // metric id
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
}

Use test.isRunningTest() in your controller itself and generate a sample response in your test class. Would look something like below: