Skip to main content
3 of 3
add marketing-cloud tag
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

How can I order the rows that I pull from a Salesforce object using ampscript?

I've got this looping ampscript retrieving rows from Salesforce object below. And I'm trying to figure out if we can retrieve them in an ordered lookup? Like a LookUpOrderRows function would work.

screen capture of looping email content attached

%%[ 
Var @RackPrice, @RackPriceRow, @BatchID__c, @Effective_Date__c, @Terminal_Number__c, @Terminal_Name__c, @Rack_Notification_Sold_To__c, @i

Set @RackPrice = RetrieveSalesforceObjects("rack_price_notification__c","Terminal_Number__c,Effective_Date__c,Terminal_Name__c,Rack_Notification_Sold_To__c","Rack_Notification_Sold_To__c", "=", @AccountId,"BatchID__c", "=", @BatchID) 

if RowCount(@RackPrice) > 0 then 
For @i=1 TO RowCount(@RackPrice) DO 
Set @RackPriceRow = Row(@RackPrice, @i) 

Set @Effective_Date__c = FIELD(@RackPriceRow,"Effective_Date__c")
Set @Terminal_Number__c = FIELD(@RackPriceRow,"Terminal_Number__c")
Set @Terminal_Name__c = FIELD(@RackPriceRow,"Terminal_Name__c")
Set @Rack_Notification_Sold_To__c = FIELD(@RackPriceRow,"Rack_Notification_Sold_To__c")
]%% 

Effective_Date__c: %%=FormatDate(@Effective_Date__c, 'mm-d-yyyy')=%%<br>
Terminal_Number__c: %%=v(@Terminal_Number__c)=%%<br>
Terminal_Name__c: %%=v(@Terminal_Name__c)=%%<br>
Rack_Notification_Sold_To__c: %%=v(@Rack_Notification_Sold_To__c)=%%
<br><br>

%%[
/* nested loop for links data retrieve */ 
NEXT @i endif ]%% 

Any ideas are appreciated. Thank you!