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
si risi ri 

how to check what response is coming for this restrequest class ?

@RestResource(urlMapping='/installs/*')
global class InstallRestAPIs {   
    @HttpGet
    global static Installation__c getInstall( ){
        Installation__c instl;
        try{
               RestRequest req= RestContext.request;
               String accountId= req.requestURI.substring(req.requestURI.lastindexOf('/')+1);
               system.debug('sfAccountId: '+ accountId);
               instl = [select Time_Zone__c from Installation__c where id= :accountId and status__c = 'Installed'];               
           }catch(Exception e){
               system.debug('Error in fetching Account'+e.getMessage());
           }
           return instl;
    }
}

Can anyone help? Thanks in advance
Best Answer chosen by si ri
GovindarajGovindaraj
Also, I have one doubt on your SOQL.

SELECT Time_Zone__c from Installation__c WHERE Id= :accountId and Status__c = 'Installed'

Actually, In WHERE condition you're filtering the records with Id (Installation object Id) with Account Id. I believe that cannot be same.

Confirm this from your side too.

All Answers

Raj VakatiRaj Vakati
You need to use  RestRequest Class and restresponse classes 


Refer this link 

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_restrequest.htm?search_text=restreq
@RestResource(urlMapping='/installs/*')
global class InstallRestAPIs {   
    @HttpGet
    global static Installation__c getInstall( ){
        Installation__c instl;
        try{
               RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
		
			   System.debug('res'+res);
			   System.debug('req'+req);
			   
               String accountId= req.requestURI.substring(req.requestURI.lastindexOf('/')+1);
               system.debug('sfAccountId: '+ accountId);
               instl = [select Time_Zone__c from Installation__c where id= :accountId and status__c = 'Installed'];               
           }catch(Exception e){
               system.debug('Error in fetching Account'+e.getMessage());
           }
           return instl;
    }
}

 
GovindarajGovindaraj
Hi si,

You can use workbench to check response for this Apex webservice.

1. login to : https://workbench.developerforce.com/login.php
2. Goto : Utilities --> REST Explorer
3. Choose : Method --> GET
4. URL : /services/apexrest/installs/<AccountID>

Let us know if this will help you.

Thanks,
Govindaraj.S
si risi ri
Hi Govinda Raj S, 
         I'm getting error by the above URL : /services/apexrest/installs/<AccountID>


I'M getting error by using the Url
si risi ri

Hi Raj Vakati, 
 I have tested your code in Anonymous window like :
 InstallRestAPIs obj= new InstallRestAPIs ();
 InstallRestAPIs .getInstall();
 but in log file the response is showing Null


 
GovindarajGovindaraj
Hi Sri,

In the URL : /services/apexrest/installs/<AccountID>

<AccountID> : You need to give the id of the Account which used for testing. for generic purpose i mentioned <AccountId>

For example : /services/apexrest/installs/00128000002jrWf

Thanks,
Govindaraj.S
GovindarajGovindaraj
Also, I have one doubt on your SOQL.

SELECT Time_Zone__c from Installation__c WHERE Id= :accountId and Status__c = 'Installed'

Actually, In WHERE condition you're filtering the records with Id (Installation object Id) with Account Id. I believe that cannot be same.

Confirm this from your side too.
This was selected as the best answer
GovindarajGovindaraj
Hi Sri,

Provide the Apex class access to the profile (the one which you used to login the workbench).

This might help you : https://developer.salesforce.com/forums/?id=9060G0000005qPYQAY

Thanks,
Govindaraj.S
si risi ri
Hi! 
 Govinda Raj S 
      Your tip was very helpful, i have done my work.
Thank you