• Amel MECHALIKH
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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