You need to sign in to do that
Don't have an account?
Denis O'Leary
APEX Rest Class
Hi,
I am trying to write my first Apex test class and I keep on getting an error:
Non-void method might not return a value or might have statement after a return statement.
Can someone see what I have done wrong?
I am trying to write my first Apex test class and I keep on getting an error:
Non-void method might not return a value or might have statement after a return statement.
Can someone see what I have done wrong?
public with sharing class AccountToFACustomer { public class Response{ public integer code {get; set;} public String body {get; set;} public boolean success {get; set;} public String errorText {get; set;} public Response (integer code, String body){ this.code = code; this.body = body; this.success = (code == 200 || code == 201); } } public class customerResponse{ public string uuid {get; set;} public string link {get; set;} public string location {get; set;} } public Response CreateCustomer (string description){ Response resp; string endpoint = 'https://apis.website.net/'; string token = 'Token XXXXX'; string method = 'POST'; HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http h = new http(); req.setEndpoint(endpoint); req.setMethod(method); req.setHeader('Autorization', token); req.setHeader('Content-Type', 'application/json'); req.setHeader('Accept-Type', 'application/json'); req.setBody( '{"name":"'+ Account.Name +'","email":"'+ Account.Email__c + '",'+ '"phone":"'+ Account.Phone +'",'+ '"website":"'+ Account.Website +'",'+ '"location":{'+ '"name":"Account No: '+ Account.Sage_ID__c +'",'+ '"streetName":"'+ Account.BillingStreet +'",'+ '"locality":"'+ Account.BillingCity +'",'+ '"postcode":"'+ Account.BillingState +'",'+ '"country":"'+ Account.BillingCountry +'" }}' ); try{ res = h.send(req); resp = new Response(res.getStatusCode(), res.getBody()); if (resp.success) { customerResponse custResp = (customerResponse)JSON.deserialize(res.getBody(), customerResponse.class); } } catch(System.CalloutException e) { System.debug('Callout error: '+ e); } } }
1) http://amitsalesforce.blogspot.com/search/label/Rest%20API
2) http://amitsalesforce.blogspot.com/2016/04/rest-api-in-salesforce-execute-rest-api.html
Update your code like below
All Answers
However, you never return any response object. Try adding
to the end of your method and see if that works.
1) http://amitsalesforce.blogspot.com/search/label/Rest%20API
2) http://amitsalesforce.blogspot.com/2016/04/rest-api-in-salesforce-execute-rest-api.html
Update your code like below
@Amit - Thanks for the links, I will read through them now
Thanks Amit/James!