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
AMIT KUMAR 73AMIT KUMAR 73 

Managing Authentication in REST Callout

Hi,

Kindly suggest the best practice to configure Authentication details (like username / password) inside Salesforce for REST call out using HttpRequest class.

User-added image
sfdcFanBoysfdcFanBoy
You need to use Named Credential for that.  Here's the code and how to set up.  This is very easy.

Named Credentials - Setup (https://sfdcfanboy.com/2018/01/15/named-credentials-setup/)

Named Credentials - Code (https://sfdcfanboy.com/2018/01/15/named-credentials-code/)
 
HTTPRequest feedRequest = new HTTP Request();
feedRequest.setEndpoint('callout:SalesforceNC/services/data/v32.0');
feedRequest.setMethod('GET');