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

Need a help on the get request apex class

our client is supposed to send us notification after the resuts has been reviewd. 
1) approval notification 
2)Results  are  availble
these are the urls they asked me to  set up in our end{id}&status=approved{id}&status=resulted[&result_type={result}]

For that . I need to setup up an apex class as a REST endpoint for an HTTP GET request that an external system is sending notification.
Please le me know is the right way do or please guide me 
global without sharing class  Rest_Approval_Notification {

    global static void doGet() {
        restresponse res=restcontext.response;
        String notification_id = RestContext.request.params.get('id');
        String notification_status = RestContext.request.params.get('status');
		//hadling error code and logic for processing 


Amit Singh 1Amit Singh 1
give it a try
private class MyFirstRestAPIClassTest{
    static testMethod void testGetMethod(){        
        RestRequest request = new RestRequest();
        request.requestUri ='/services/apexrest/sample/approvalnotifications';
        request.httpMethod = 'GET';
        request.addParameter('id', '12324434');
        request.addParameter('status', 'Status Value Here');
        RestContext.request = request;

Hi Amit ,  Thank you .I cheked that using this test method and postmal as well. it seems woking 
I have question on this folowwing and how do i use the paarameter for this  [&result_type={result}]. parynot undestanding properly.{id}&status=resulted[&result_type={result}]
Amit Singh 1Amit Singh 1
HI Sasham,
We use addParameter method of RestRequest class when we want to add the parameter into the URL of the request and addPetemer is basically map which takes Key Value where Key is the parameter and value is the value that we are passing to that param.
In your case use 
request.addParameter('result_type', 'result_type value here');
We use addHeader method of RestRequest Class when we want to add the values into the header and it also takes the parameters in the form of Key Value pair. For example, if we want to add Authorization, Content-Type then we should go for addHeader.
Hope this will help you :)

Hi Amit, Thank you for the details. I disd not undestand why the [] brackets - [&result_type={result}] in the end point{id}&status=resulted[&result_type={result}]
Is it the smae as{id}&status=resulted&result_type={result}
any difference.
One mre question :
When i want to authenticate the request comming to saleforce from external system without using OAuth . 
How to validate the rquest to make sure that it is coming from the source that we expect(Ex- XY company making request to our salesforce)
Isit possible to valdate using 
 String hostname = RestContext.request.Header('Host');. even thoung if they (xyc company) are adding the header for 'Host'