function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raja Narendra 5Raja Narendra 5 

Create a RestFul WebService, to Fetch all the Opportunities based on the Specified Account Name? below code is correct? i

@RestResource(URLMapping = '/OpportunityService/*')
global class OpportunityRecord 
{
    @HttpGet()
    global static list<Opportunity> GetOpportunityRelated ()
    {
        
      Map<string, string> inputParams = RestContext.request.Params;
        
        list<Opportunity> lstOpportunity = [select id,name, amount, stagename, closedate, accountId, Account.Name
                                             from Opportunity where Account.Name =: inputParams.Get('accName')];
        
        return lstOpportunity;
        
    }
}
Maharajan CMaharajan C
Hi Raja,

Please try the below code:

/services/apexrest/OpportunityService?accName=MentionYourAccountNameHere
 
@RestResource(URLMapping = '/OpportunityService/*')
global class OpportunityRecord 
{
    @HttpGet()
    global static list<Opportunity> GetOpportunityRelated ()
    {
                
        RestRequest req = RestContext.request;
        
        String accountName = req.params.get('accName');
                
        system.debug(' ++++ ' + accountName);
        
        list<Opportunity> lstOpportunity = [select id,name, amount, stagename, closedate, accountId, Account.Name
                                            from Opportunity where Account.Name =: accountName];
        
        return lstOpportunity;
        
    }
}
Reference Link : https://www.biswajeetsamal.com/blog/read-rest-api-get-parameters-in-apex-class/

Thanks,
Maharajan.C