I have written a REST API endpoint for Account object for GET operation. The code is below -
@httpget
global static list<Account> doget(){
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
list<Account> accountList = new list<Account>();
String searchtext = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
IF (searchtext !=null && searchtext !=''){
accountList = [select ID,
Email__c,
Name,
Phone,
Send_Owner_Reminders__c,
ZTS_EU_Opt_Out_Email__c,
ZTS_EU_Opt_Out_Date_Email__c,
ZTS_EU_City__c,
ZTS_EU_Zip_Postal_Code__c,
ZTS_EU_District__c,
ZTS_EU_Sub_Type__c,
RecordType.Name,
Type,
ZTS_EU_Country__c,
ZTS_EU_Market__c,
Email_Preference__c,
ZTS_EU_Address_Line_1__c,
ZTS_EU_Address_Line_2__c,
ZTS_EU_Account_Status__c,
ZTS_EU_Rep_Account_Status__c,
ZTS_EU_TSF_PBC__c,
OwnerID,
ZTS_EU_Account_Count__c,
ZTS_EU_Preferred_Language__c,
ZTS_EU_Potential_Region__c,
ZTS_EU_Customer_ID__c,
ZTS_EU_Zoetis_SFDC_ID__c from Account where ZTS_EU_Customer_ID__c =:searchtext or Email__c =:searchtext];
return accountList;
}
else{
system.debug(searchtext);
accountList = [select ID,
Email__c,
Name,
Phone,
Send_Owner_Reminders__c,
ZTS_EU_Opt_Out_Email__c,
ZTS_EU_Opt_Out_Date_Email__c,
ZTS_EU_City__c,
ZTS_EU_Zip_Postal_Code__c,
ZTS_EU_District__c,
ZTS_EU_Sub_Type__c,
RecordType.Name,
Type,
ZTS_EU_Country__c,
ZTS_EU_Market__c,
Email_Preference__c,
ZTS_EU_Address_Line_1__c,
ZTS_EU_Address_Line_2__c,
ZTS_EU_Account_Status__c,
ZTS_EU_Rep_Account_Status__c,
ZTS_EU_TSF_PBC__c,
OwnerID,
ZTS_EU_Account_Count__c,
ZTS_EU_Preferred_Language__c,
ZTS_EU_Potential_Region__c,
ZTS_EU_Customer_ID__c,
ZTS_EU_Zoetis_SFDC_ID__c from Account limit 40];
return accountList;
}
}
Now when I am testing with Workbench REST Explorer I am seeing some fields are not coming in response, because those fields are having null values in that specific Record. I want to show all fields irrespective of its values.
Please let me know what I need to change in code.