Monday, August 28, 2023

#983 SFDC User Sync with OIC and other things SFDC adapter

Simple use case here - users created in SFDC are pushed to a downstream app. If a user is deleted/deactivated in the app, the SFDC pendant needs to be deactivated.

But this post will cover more features of the adapter, including use of the SFDC Bulk API - however, you have to use the Resource Owner Password Credentials security policy or Authorization Code Credentials in order to use V2 of the SFDC Bulk API.



I take this as an opportunity to check out this security policy - 


For ROPC, I will need the SFDC client id / secret. 

This is how I get such - 
I begin by creating a new Connected App in SFDC - 



The callback url has the following format - https://hostname from EndpointURL/icsapis/agent/oauth/callback

Now to the scopes - essentially specifying what the app will be allowed to do in SFDC.

I just give full access, at this stage - 


I click Save and then - 




Now back to the connection definition in OIC - I use the key and secret.


So why would I use Resource Owner Password Credentials? Again back to us wanting to use v2 of the SFDC Bulk API.

Here is the difference, compared to Salesforce Username Password Policy

Actions available are the same - 



















but let's check out the Bulk Data Operations
here are the options - Bulk v2.0 will be used later on in this post.














Compare this to Salesforce Username Password Policy - 


Great that we got that started. The next section details a simple example of updating an SFDC user. Essentially, I retrieve the user using SOQL and update it via the adapter CRUD functionality. Net, net a simple select and update.

Updating User in SFDC

So t the simple user update - this can be done easily using the OIC adapter for SFDC - 

In the following sample, I retrieve active users from SFDC - one of these, Julius Martov, will be updated -


As you can see, Julius is active - 







Here is the simple integration flow - 


GetSFDCUsers is configured with the following SOQL - 



SELECT ID, CommunityNickname, EMAIL, FirstName, LastName, IsActive from User

Note the testing capabilities of the adapter wizard - 


The Switch action filters out the Mencheviks and sets them to deactivated - 




I also set the alias, just for the sake of it.

The Active flag is set as follows - 


Let's test it out - 



Validate in SFDC -

Julius is now known informally as the mart, and yes, the user has been deactivated.



Now let's do the same using the SFDC Bulk api v2.

Updating User in SFDC using Bulk API

Now to the Bulk API implementation -  The ROPC based connection I created earlier, will be used.
Bulk api is essentially asynchronous file upload. My first challenge was getting the correct file format for SFDC Users. In the end, I did an export, selecting only the User object - 


 Per default, include all data is checked. I de-selected this and just select User - 


The exported file is as follows - 

I make one change to the file, setting alias to "the martian".

This will now be my input file for bulk load. I copy this to the OIC File Server -


Now to the upload integration - 





































Here I read the file using the ftp adapter, then invoke the bulk load via the SFDC adapter. The latter is configured as follows - 



















I map a couple of fields - ID, Alias, IsActive etc.
I then add another Bulk API invoke via the adapter - Final Batch - indicating I have no more files to process. SFDC Bulk API has a size limit on files, so you could end up having multiple input files, hence FinalJob



I run a test - and check in SFDC -


Looks like we have an issue, so let's create another integration to check out the error.



Simple logic here, we invoke the SFDC bulk api - getFailedRecords - this returns the error(s) and data as a .csv file. This file is stored in the OIC VFS (virtual file system), hence the next action being Stage File - List Files. Then each error file is written to the OIC File Server via the ftp adapter.

The SFDC Invoke is configured as follows - 


  
Let's try it out - 


I check out the ftp directory - 


I check out the error.csv file - 


Ok, so Alias is limited to 8 characters,
I'll amend it to Jmart in the input file and reload.


I check out the user in SFDC - 


I just have to set the active value in the input file to 0, in order to deactivate the user.









  


No comments:

Post a Comment