We can connect to salesforce using 2 ways:
Make sure to enable the required api’s and grant the necessary roles to the service account. Follow the link below before you begin.
Prerequisites:https://cloud.google.com/integration-connectors/docs/connectors/salesforce/configure#before-you-begi...
We can connect to salesforce using 2 ways:
Step 1:Creating private key and X509 certificate
Step 2:Creating connected app in Salesforce
Step 3:Prior Approval of the Client App
Step 4:Create Salesforce Connection
You can use openssl to generate private keys and public certificates.
Sample openssl command to generate the private key. You can open the cloud shell and enter this command.
openssl genrsa -out privatekey.pem 1024
openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 3650
Now list the files generated:
ls -lrt
Download these files from the gcloud to your local system by clicking the download and selecting the privatekey.pem and publickey.cer files
Note:Salesforce is always an evolving product, some terminologies and screenshots might differ.
Login to salesforce domain and go to setup under settings
Go to Platform Tools->Apps->App Manager->New Connected App
Fill in Connected App Name, email, phone, description etc.
Tick ‘Enable OAuth Settings’. Fill Callback URL = ‘https://oauthdebugger.com/debug’ // we are using a great online debugger. Tick ‘Use digital signatures’.Upload <publickey.cer from Step 1>
Selected OAuth Scopes = Perform request at any time(refresh_token, offline access) and Manage user data via APIs (api). If required, then you can add more scopes.
Save the connected app you created. Then click on Manage Consumer Details to save the Client_ID.
This needs to be performed once per salesforce user(or profile) This will be a backend administrative approval action
Note: If we don't perform Step 3, we will get the following error in step 5 {"error":"invalid_grant","error_description":"user hasn't approved this consumer"}
Let us pretend to be an admin and approve this app/consumer to access a specific user’s data associated with a specific profile.
Go to Platform Tools->Apps->Connected Apps->Manage Connected Apps and click edit against your app.
Choose ‘Permitted Users’ = ‘Admin approved users are pre-authorized’ and click on Save .
Go to Settings > Setup->Administration->Users->Profiles. Edit the profile associated with the user(In my case the user is associated with the System administrator profile.
Under profile search for the property “Connected App Access” and “Tick” and then save the profile
Under profile search for the property “Connected App Access” and “Tick” and then save the profile
In your Google Cloud project search for Integration Connector and click on create new connection.
Specify the location where your connection will run. Here I’m specifying it as us-west1.
Provide the Connection Details(connector, version, connection name, description and service account)
Make sure to grant the following roles to the service account that you want to use to create the connection:
Click Next and provide destination details. In this case I’m using a trial account and it will default to https://login,salesforce .com. If you are using a custom domain then you need to specify the custom domain login endpoint.
Under Authentication click on OAuth 2.0-JWT Bearer and provide Connected App Client ID under Connected App Consumer Key, The username that is associated with the connected app you created in salesforce and create the secret manager secret by providing the private key generated in the Step 1.
While creating the secret make sure to copy the complete content of the private key. Below is the expected format.
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCf1nlnhQa5gYX
...
...
-----END PRIVATE KEY-----
Review the connection and create. This might take a couple of minutes to create the connection and activate it.
To verify the connection, you can go to Salesforce->Settings->Setup->Users->My user and click on the user email id and scroll down to the login history.
Now, you should have the connection status as active under connections.
@Mamatha : Could you please explain the steps for the second method as well? 2. UserName and Password
@Mamatha , thanks for this excellent writeup, I have the connector working thanks to you!
Now... if I wanted to use the connected Salesforce org as the endpoint for a push notification from the Google Admin SDK Directory API, as described here, what additional steps are needed to set that up? I am trying to figure out how to generate the proper certificate and install it. Which platform stores it?
Great post, direct to the point. I have my connection working, thanks