You need to sign in to do that
Don't have an account?
Your code coverage is 0%. You need at least 75% coverage for deployment. (?)
Hello world~
I am very new to Apex. I am currently working on the code below that would allow a lead to be removed from a cadence when deemed fit:
public class RemoveTargetFromSalesCadence {
@InvocableMethod(label='Remove Target From Sales Cadence' description='Uses REST Invocable Action to remove a Target to a Sales Cadence')
public static void removeTarget(List<RemoveTargetRequest> targetsToRemove) {
System.debug('*** Targets to remove *** ' + targetsToRemove);
if (targetsToRemove != null) {
for (RemoveTargetRequest req : targetsToRemove) {
System.debug('*** request *** ' + req);
System.debug('\ttarget: ' + req.targetId);
System.debug('\tcompletion reason code: ' + req.completionReasonCode);
sendRequest(req.targetId, req.completionReasonCode);
}
} else {
System.debug('*** null targetsToRemove received ***');
}
}
@future(callout = true)
private static void sendRequest(String targetId, String completionReasonCode) {
String sfdcURL = URL.getSalesforceBaseUrl().toExternalForm();
String actionsRestURL = sfdcURL + '/services/data/v45.0/actions';
String removeTargetRESTUrl = actionsRestURL + '/standard/removeTargetFromSalesCadence';
HttpRequest httpReq = new HttpRequest();
httpReq.setMethod('POST');
httpReq.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
httpReq.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
httpReq.setEndpoint(removeTargetRESTUrl);
httpReq.setHeader('Content-Type', 'application/json');
httpReq.setBody('{"inputs" : [{"completionReasonCode" : "' + completionReasonCode + '", "targetId" : "' + targetId + '"}]}');
String response = '';
try {
Http http = new Http();
HttpResponse httpResponse = http.send(httpReq);
if (httpResponse.getStatusCode() == 200) {
response = JSON.serializePretty(JSON.deserializeUntyped(httpResponse.getBody()));
} else {
System.debug('http response: ' + httpResponse.getBody());
throw new CalloutException(httpResponse.getBody());
}
} catch (System.Exception e) {
System.debug('ERROR! ' + e);
throw e;
}
System.debug('response: ' + response);
}
public class RemoveTargetRequest {
@InvocableVariable(required=true)
public Id targetId;
@InvocableVariable(required=true)
public String completionReasonCode;
}
}
I am getting this error message after deploying it to my production and I don't know what this means. Could somebody please clarify and help me out?

Thanks so much.
I am very new to Apex. I am currently working on the code below that would allow a lead to be removed from a cadence when deemed fit:
public class RemoveTargetFromSalesCadence {
@InvocableMethod(label='Remove Target From Sales Cadence' description='Uses REST Invocable Action to remove a Target to a Sales Cadence')
public static void removeTarget(List<RemoveTargetRequest> targetsToRemove) {
System.debug('*** Targets to remove *** ' + targetsToRemove);
if (targetsToRemove != null) {
for (RemoveTargetRequest req : targetsToRemove) {
System.debug('*** request *** ' + req);
System.debug('\ttarget: ' + req.targetId);
System.debug('\tcompletion reason code: ' + req.completionReasonCode);
sendRequest(req.targetId, req.completionReasonCode);
}
} else {
System.debug('*** null targetsToRemove received ***');
}
}
@future(callout = true)
private static void sendRequest(String targetId, String completionReasonCode) {
String sfdcURL = URL.getSalesforceBaseUrl().toExternalForm();
String actionsRestURL = sfdcURL + '/services/data/v45.0/actions';
String removeTargetRESTUrl = actionsRestURL + '/standard/removeTargetFromSalesCadence';
HttpRequest httpReq = new HttpRequest();
httpReq.setMethod('POST');
httpReq.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
httpReq.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
httpReq.setEndpoint(removeTargetRESTUrl);
httpReq.setHeader('Content-Type', 'application/json');
httpReq.setBody('{"inputs" : [{"completionReasonCode" : "' + completionReasonCode + '", "targetId" : "' + targetId + '"}]}');
String response = '';
try {
Http http = new Http();
HttpResponse httpResponse = http.send(httpReq);
if (httpResponse.getStatusCode() == 200) {
response = JSON.serializePretty(JSON.deserializeUntyped(httpResponse.getBody()));
} else {
System.debug('http response: ' + httpResponse.getBody());
throw new CalloutException(httpResponse.getBody());
}
} catch (System.Exception e) {
System.debug('ERROR! ' + e);
throw e;
}
System.debug('response: ' + response);
}
public class RemoveTargetRequest {
@InvocableVariable(required=true)
public Id targetId;
@InvocableVariable(required=true)
public String completionReasonCode;
}
}
I am getting this error message after deploying it to my production and I don't know what this means. Could somebody please clarify and help me out?
Thanks so much.
Actually, in order to deploy any apex class, it needs have the minimum code coverage of 75%. For which we need to write a test class to test the functionality of the particular apex class.
Did you write any test class for the above functionality.?
I have not written a test class. Would you be able to point me in the right direction to write a correct one for my apex class?
As i see you are currently working on Rest, to make a web services call out, we need to go for mock test classes or static resource method.
Can you take a look at below resource. Hopefully it will help you.
https://trailhead.salesforce.com/content/learn/modules/apex_integration_services/apex_integration_rest_callouts
You have to make a test class to test your Apex class because you cannot deploy any class to your production if it doesn't have a test class and also the test class should cover 75% of your code.
For more information about test class please refer to the link below.
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com