Is there a better way to handle callouts in Salesforce?

Recently, I was doing an integration and was faced with a situation that lead me to think, is there a better way to do this, i.e. handle callouts in Salesforce?

Well. Yes. There is, was the answer I found.

You must be wondering what I am talking about. Well,

  • I didn’t want to hardcode my API Credentials in code which is not the CORRECT way to go about, and which would also cause issues when deploying to Production
  • Was looking at a better way to store credentials and make it more secure than using Custom Settings
  • etc.

So, this lead me in search of a BETTER WAY to achieve this within Salesforce, and well, I found my answer – Named Credentials.

 

Named Credentials allows to define the Callout URL endpoint and any required authentication parameters in one definition, and Salesforce handles the rest for us. This means,

  • I didn’t have to hardcode any credentials in code which is NOT the correct way to go
  • I didn’t have to use Custom Settings
  • etc.

This also saved me a lot of trouble of not needing to define a Remote Site Setting entry to white list my endpoint URL, which I would have to use if I had used the traditional way of using the endpoint URL in code, or handle authentication within code which would cause it to be less secure, etc.

Happy coding… Named Credentials #Simple #Easy #Secure #Better

 

Popular Salesforce Blogs