You need to sign in to do that
Don't have an account?
"Changing return type" of a custom REST Webservice
Hello
I have a simple webservice that returns opportunities link to a field of a given account (id of account is sent in request)
I would like to return list of opportunities if account id is correct and an error message 'Incorrect account id' if account id sent in request in incorrect
How can I do that knowing that return of WS is specified in definition
Here would be my code
@RestResource(urlMapping='/xxxx/*')
global with sharing class MyWLResource {
@HttpPost
global static list <Opportunity> doPost(String accountid)
{
Account myaccount;
list <Opportunity> myresult;
try
{
myaccount = [select website from Account where id=:accountid];
myresult=[select id from Opportunity where website__c=:myaccount.website limit 10];
return myresult;
}
catch (Exception e)
{
return 'Incorrect account id';
}
}
}
Thanks for your help
Is there a simple solution without building a new class object ?
Regards
Hi Alex,
You can change the return type of your web service method to void, then set the response body with any string you like. In your case, this would be the JSON encoding of the opportunity list or the error message as appropriate:
Cheers,
Pat
All Answers
Hi Alex,
You can change the return type of your web service method to void, then set the response body with any string you like. In your case, this would be the JSON encoding of the opportunity list or the error message as appropriate:
Cheers,
Pat
Thanks : that's perfect
Regards