In this guide, we will walk through the essential steps required to build a Salesforce integration using the Cobalt platform. This process involves three major steps i.e. User Authentication with Salesforce, Creating Workflows and Using workflows for users.
A Linked Account in Cobalt represents the end-users or customers who will use the integration through the platform. Each Linked Account requires a unique linked_account_id, which typically corresponds to an ID from your internal data model (e.g., a user or account ID).
After creating a Linked Account, the next step is to generate a session token. Session tokens help protect your Cobalt API key and manage end-customer tokens more securely.
To create a session token, use the following API call:
Next, you will need to generate a Hosted URL that your users will use to authenticate with Salesforce. Cobalt securely stores the credentials and handles API calls on behalf of your users.
Use the following API call to generate the Hosted URL:
The response will return a Hosted URL that your users can visit to authenticate and connect their Salesforce accounts.
Hosted Portal is a no-code solution provided by Cobalt that removes the need to build your own UI for handling integration authentication and configuration.
Consider a use-case where you want to sync all the opportunities present in Salesforce to your system.
In the Salesforce integration, go to Workflows and create a new workflow by clicking on +Add Workflow button and name it as Sync Opportunities.
Follow the steps given to build the workflow:
1
Add Trigger in Start Node
All workflows start with a trigger, which determines when the workflow will run and how data is passed into the workflow.
For this workflow we will use the Event Based trigger.
Click on the Start Node, select your native app option and click on + Create New Event.
Give a name to your event and keep the payload as an empty object.
2
Add Salesforce Node
Now to fetch all the opportunities present in your user’s account, we need to call Salesforce API.
Click on Nodes option in the top right and drag the Salesforce Node from Native Apps section to the workflow builder. Connect this node with Start Node.
3
Fetch Opportunities from Salesforce using Action
Click on the Salesforce Node and select Get Entity with SOQL action.
Add the following under SOQL query field and click on Save.
SELECT Id,Amount,AccountId, CloseDate,ContactId,Description,ExpectedRevenue,LeadSource, Name, OwnerId, Probability,StageName,Type FROM Opportunity
You can provide any additonal fields that you want to fetch about opportunities from Salesforce by adding it to this query.
4
Add Custom Code node
We have fetched all the opportunities, but you might require to structure it as a payload which your platform can receive. Let’s do this using Custom Code node.
Drag the Custom Code from the Utility Nodes section onto the workflow builder and connect it with Salesforce node.
5
Mapping Opportunity fields
Click on + Map Fields under Input Parameters, add key name as deals and in value we will provide the response received through Salesforce node which will be restructured.
In Value, select Nodes tab under Insert Variable and click on + of the Salesforce Node.
You can now do mapping using JavaScript code. Try the sample code provided below:
function yourFunction(params) {const res = params.deals.map(ele=>{ const output = { id: ele.Id, title: ele.Name, description: ele.Description || 'Description not available', close_date: ele.CloseDate, amount: ele.Amount, expected_revenue: ele.ExpectedRevenue, status: ele.StageName } return output }) return {"result": res || [] }}
6
API Proxy in Workflow
You have successfully fetched all opportunities and structured the payload. Now to receive it in your server, you need to configure an API Proxy.
In Cobalt Dashboard, navigate to Developer > API Proxies and click on New Action. Configure an API endpoint, where you want to receive the response.
If you want to test, go to webhook.site and copy Your unique URL and configure this as a POST Request and Save.
Consider a use-case where you want to create a contact present in your system to Salesforce.
This workflow will be fired when you send an Event with the payload of the contact to be added.
In the Salesforce integration, go to Workflows and create a new workflow by clicking on +Add Workflow button and name it as Create New Contact.
Follow the steps given to build the workflow:
1
Add Trigger in Start Node
All workflows start with a trigger, which determines when the workflow will run and how data is passed into the workflow.
For this workflow we will use the Event Based trigger.
Click on the Start Node, select your native app option and click on + Create New Event.
Give a name to your event and provide all the data related to the contact in the payload.
2
Add Salesforce Node
Now to create a new contact in Salesforce, we need to call Salesforce API.
Click on Nodes option in the top right and drag the Salesforce Node from Native Apps section to the workflow builder. Connect this node with Start Node.
3
Add Action in node
Click on Salesforce Node and add the Create Contact action.
To provide the data in all the fields from your Event payload, just click on a field and from the Event tab under Insert Variable, select the fields from the body that you sent as payload.
Ensure that all the mandatory fields in the action are filled, else the Salesforce API will give error.
Hurray!!
You have successfully created a Salesforce workflow to create a new contact.
Workflow to update records in your system whenever a contact gets created or updated in Salesforce.
To perform a real time update whenever a change happens in Salesforce, we will use Salesforce Webhook as a trigger for our workflow.
Follow the steps given below to setup your workflow:
1
Add Salesforce Webhook as trigger
In the Start Node, select Salesforce as the trigger and select Contact Created event.
Similarly, you can use the Contact Updated event to get notified whenever a contact is updated in Salesforce.
By using the Contact Created trigger, you will receive data as an event payload about any new contact created in Salesforce in real time.
2
Send New Contact data to your system
Send the data that we received about the new contact to your system to perform real time sync.
From Native Apps nodes, add your org’s Node and connect it with Start Node.
Click on the node and select the API Proxy that you created from the Actions to receive new contact info. Add the response from Event using Insert Variables and click on Save.
Ensure that you add a field in the API Proxy where you can pass the data and then added it to the API Call body as well in the POST request.
Hurray!
You have successfully created a workflow which will inform you whenever a new contact is created in Salesforce.
You have successfully created the workflows for your use case.
Next step is to enable and execute those workflows for your Linked Accounts.
You can create config for the Linked Account through the Cobalt Connect SDKs or using the APIs.
You can use the .config() method or the Create Config API which returns the specified config or creates one if it doesn’t exist for the Linked Account.
Make a request with the Application Slug and linked_account_id as mandatory fields for it. You can request in the following way:
It will return information about config of the application for the Linked Account and provides you with all the published workflows and settings input for the user required to execute the workflow.
Now you need to enable the workflow for your Linked account. You can either ask the user to enable them or you can do so for them by using the Update Config API or .updateconfig() method.
In response, you get the updated config information for the application.
3
Third Step
Once the required workflows are enabled, you need to fire event to start execution. You can use the Trigger Event for app API with the following request: