Module salesforce.soap
ballerinax/salesforce.soap Ballerina library
Overview
Salesforce SOAP API provides CRUD operations for SObjects and allows you to maintain passwords, perform searches, and much more.
This module supports Salesforce v48.0 SOAP API Enterprise WDSL.
Setup guide
-
Create a Salesforce account with the REST capability.
-
Go to Setup --> Apps --> App Manager
-
Create a New Connected App.
- Here we will be using https://test.salesforce.com as we are using sandbox environment. Users can use https://login.salesforce.com for normal usage.
-
After the creation user can get consumer key and secret through clicking on the
Manage Consumer Details
button. -
Next step would be to get the token.
-
Log in to salesforce in your preferred browser and enter the following url.
https://<YOUR_INSTANCE>.salesforce.com/services/oauth2/authorize?response_type=code&client_id=<CONSUMER_KEY>&redirect_uri=<REDIRECT_URL>
-
Allow access if an alert pops up and the browser will be redirected to a Url like follows.
https://login.salesforce.com/?code=<ENCODED_CODE>
-
The code can be obtained after decoding the encoded code
-
-
Get Access and Refresh tokens
- Following request can be sent to obtain the tokens
curl -X POST https://<YOUR_INSTANCE>.salesforce.com/services/oauth2/token?code=<CODE>&grant_type=authorization_code&client_id=<CONSUMER_KEY>&client_secret=<CONSUMER_SECRET>&redirect_uri=https://test.salesforce.com/
- Tokens can be obtained from the response.
- Following request can be sent to obtain the tokens
Quickstart
To use the Salesforce connector in your Ballerina application, update the .bal file as follows:
Step 1: Import connector
Import the ballerinax/salesforce.soap
module into the Ballerina project.
import ballerinax/salesforce.soap;
Step 2: Create a new connector instance
Create a soap:ConnectionConfig
with the OAuth2 tokens obtained, and initialize the connector with it.
oap:ConnectionConfig config = { baseUrl: baseUrl, auth: { clientId: clientId, clientSecret: clientSecret, refreshToken: refreshToken, refreshUrl: refreshUrl } ; oap:Client salesforce = check new (config);
Step 3: Invoke connector operation
- Now you can use the operations available within the connector. Note that they are in the form of remote operations.
Following is an example on how to convert lead using the connector.
public function main() returns error? { soap:ConvertedLead response = check soapClient->convertLead({leadId = "xxx", convertedStatus: "Closed - Converted"}); }
- Use
bal run
command to compile and run the Ballerina program.