How to Integrate Your Application With Salesforce

Reggie Pangilinan
Station Five
Published in
4 min readJan 11, 2019

In a project I’m currently working on, one of the requirements is to integrate our application to a Salesforce organisation instance. Basically, I’ll need to pass some data from Salesforce to our application through API calls and vice-versa. I’ve been a javascript and .net developer my whole life and this will be my first time working with Salesforce.

Salesforce is a huge platform and it’s very easy to get lost in the mountain of outdated articles and documentation out there, so this guide is for anyone who is planning or doing any integration project with Salesforce. At the time of this writing, I am working with Salesforce Spring ’19 release.

Salesforce Spring ’19 Loading Screen

Apex

If you are doing Salesforce (SF) development you definitely need to learn Apex. In a nutshell, Apex is like Java or C# for Salesforce. It is the SF programming language.

Apex is a development platform for building software as a service (SaaS) applications on top of Salesforce.com’s customer relationship management (CRM) functionality.
Apex allows developers to access Salesforce.com’s back-end database and client-server interfaces to create third-party SaaS applications.

https://searchsalesforce.techtarget.com/definition/Apex

Here are just some of the things that Apex can be used for:

  • It can be used to create custom SF objects,
  • Intercept object lifecycles with triggers
  • Implement your own business logic
  • Call external SOAP or REST Apis
  • Expose custom endpoints that your applications can integrate to
  • Unit test your code

To read more check out the Apex Developer Guide.

Salesforce Environments

I think we can all agree that it’s pretty dangerous to develop, test and deploy directly in production. This isn’t just for SF, but for development in general. Hence, you will need to understand how the SF environment works. It’s a plus if you’re familiar with how git branches work — it’s very similar to that.

A sandbox environment can be created based on the existing production organisation. Once created, feel free to test your ideas there. Once tested and validated, create a changeset and promote that into the production org.

To learn how to set up a sandbox environment check this link.

Tooling

I personally love vscode. For anyone else who feels the same I have good news — you can use it for SF development! The same editor you use for your Javascript, Java or .Net development can also handle Apex, how awesome is that?!

Just add the Salesforce Dx extension for vscode

With vscode and salesforce dx extension you can:

  • Connect your codes into a version control system like git
  • Easily manage your custom objects, apex classes. View the actual codes in a code editor which is more natural to developers rather than a web portal.
  • Code completion!
  • Deploy directly to the connected organisation. (It is highly recommended though NOT to deploy directly to prod, Use development environments)
    Salesforce environment

To learn how to properly set up your machine with vscode check the step by step guide here. If you want to see it in action, here are some of the videos I recommend you watch.

Getting Started in VS Code with Salesforce Dx
Be An Efficient Salesforce Developer with VS Code

Apex Triggers

One nice development approach or paradigm that is available at your disposable in SF are Apex Triggers. They are like hooks or events that you can subscribe with whenever there are changes to your Salesforce object.

You can implement a simple logic after your object has been inserted or updated through triggers. In the project that I am working on after the record has been inserted or updated a trigger will fire that will dispatch an API callout (more on callouts later).

Here is a sample trigger that is executed after an `insert`

Learn more about triggers here.

SOQL

Salesforce Object Query Language (SOQL) — Is basically, SQL for Salesforce objects. If you’re familiar with SQL statements like SELECT, then you’re good to go. Just understand that instead of tables you will be querying salesforce objects.

A sample SOQL:

SELECT one or more fields 
FROM an object
WHERE filter statements and, optionally, results are ordered

Callouts

Nowadays, API to API communication is a pretty common scenario. SF supports these use cases through callouts. SOAP and REST integrations are supported out of the box.

I used callout in the project that I am working in together with Apex Triggers, SOQL and the dispatch a Callout.

In summary, the sequence flow is:

  1. I insert or update a salesforce object through the UI
  2. An Apex Trigger will then be executed and I will pass the Id of the object to a custom apex class
  3. Using the Id I will then query the object that was inserted or updated and I will select all the relevant fields
  4. After I will run some validations and use case specific logic
  5. Then dispatch a Callout to an external API service endpoint that SF is integrating with.

To learn more about Callouts click this link.

Deployment

To deploy your changes to the production organisation, make sure your sandbox environment is connected to the organisation you want to deploy in.
Also, make sure that the production org is configured to accept inbound changesets.

Please check this article for step by step guide make sure your environment is ready for deployment.

Conclusion

Hopefully, this article has given you an insight into the massive world of Salesforce development and has pointed you in the right direction.

Other tools that might be useful
Workbench — A free tool to access your Salesforce environment, invoke SOAP and Restful endpoints to test integration points.

Postman — You can also use postman to invoke Salesforce endpoints

--

--