Skip to content

Instantly share code, notes, and snippets.

@katydorjee
Last active March 6, 2023 13:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katydorjee/818912244f95c49c0bf52c175d00cfe8 to your computer and use it in GitHub Desktop.
Save katydorjee/818912244f95c49c0bf52c175d00cfe8 to your computer and use it in GitHub Desktop.
Update Salesforce Object Using SSJS
<script runat="server">
Platform.Load("core","1.1.1");
var sfUpdateString;
var targetDE = DataExtension.Init('External Key').Rows.Retrieve();
for (var i = 0; i < targetDE.length; i++)
{
var Field1 = targetDE[i].Field1;
var Field2 = targetDE[i].Field2;
sfUpdateString = '';
sfUpdateString = '%'+'%[SET @uso = UpdateSingleSalesforceObject("Contact","'+Field1+'"';
sfUpdateString += ',"Field2","'+Field2+'")]%'+'%';
Platform.Function.TreatAsContent(sfUpdateString);
Write(Platform.Variable.GetValue("@uso"));
}
</script>
@katydorjee
Copy link
Author

Credit: Jay Lee

@Akash223-sf
Copy link

I am new to SFMC hence not sure whether this code will handle the bulk update. As we know in salesforce update, insert, and delete we can not use inside the for loop(as per best practice), instead we will add the first data into the list and then will update the whole list, hence want to confirm if I have 10 records then using the above code it's fine to update one by one or need to add first in the list and then update, please help me to understand as i want to use the above code in my current implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment