I am trying to update a field on a custom object called Partnership in Salesforce using AMPScript code. I have a source Data Extension which has around 4500 unique Salesforce Ids to update. But when the access the cloud page to run the code, it give Runtime error after few minutes. My AMPscript code looks like:

Set @rows = LookupOrderedRows("TestFieldDE",DataExtensionRowCount("TestFieldDE"), "rNum asc", "lookupKey","1")  
Set @count = RowCount(@rows)  
if @count != 0 then  
for @i = 1 to  do  
Set @row = Row(@rows,@i)  
Set @pId = Field(@row,"TestField")  
Set @update = UpdateSingleSalesforceObject('Partnership__c',@pId,'Test_MC_field__c', 'test')  
next @i  

CloudPage scripts timeout after two minutes. You could try using SSJS in an Automation Studio Script activity to do this, but the 15 minute timeout on Script Activities would almost certainly be exceeded. What you're trying to do just won't scale that well. Salesforce AMPScript functions are very slow and you're running them serially in a loop - each iteration probably taking 3-4 seconds.

As an alternative, consider one of the following patterns:

  1. Middleware - If you have access to a middleware, like Mulesoft, Informatica, Jitterbit etc, use this
  2. Extracts & Dataloader - Output the content of your TestFieldDE to flat file using Automation Studio and script import into Sales Cloud using a dataloader
  3. Journey Builder - Inject your TestFieldDE data into a Journey and use an Update Object activity to manipulate records in your Partnership__c object. You'll need to make TestFieldDE sendable to allow use in Journey Builder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.