Create a Personalized Email with Standard Object Data

For this Marketing Cloud Connect for Marketing Cloud Engagement tutorial example, create a personalized email from a case with standard object data using AMPscript.

  1. In Engagement, go to Email Studio.
  2. Click Content.
  3. Click Create.
  4. Click HTML Paste.
  5. Enter a name and a subject.
  6. In the email content area, insert this AMPscript.
    %%[ 
    Set @mySObject = SObject
    Set @myRecordId = RecordId
    set @Case = RetrieveSalesforceObjects(SObject,"Subject,Status","Id", "=", RecordId)
    Set @CaseRow = Row(@Case, 1)
    Set @Subject = FIELD(@CaseRow, "Subject")
    Set @Status = FIELD(@CaseRow, "Status") 
    ]%% 
    <br>
    <br>
    SObject From API Call: %%=v(@mySObject)=%% 
    <br>
    RecordId From API Call: %%=v(@myRecordId)=%% 
    <br>
    Subject From RetrieveSalesforceObjects: %%=v(@Subject)=%% 
    <br>
    Status From RetrieveSalesforceObjects: %%=v(@Status)=%% 
    <br>
  7. Save the email.
  8. Modify the AMPscript example to include extra customizations. To add more fields from the case, follow this format. For example, include the Description field.
    set @Case = RetrieveSalesforceObjects(SObject,"Subject,Status,Description","Id", "=", RecordId)
  9. To set the Description variable, add another line of code. For example, under line 6 add this code.
    Set @Description = FIELD(@CaseRow, "Description").

    Add this code within the closing tag ]%%.

  10. To print the Description field in an email, add another line of code under the last line.
    Status From RetrieveSalesforceObjects: %%=v(@Description)=%% <br>

New AMPscript looks like this example.

%%[ 
Set @mySObject = SObject 
Set @myRecordId = RecordId 
set @Case = RetrieveSalesforceObjects(SObject,"Subject,Status","Id", "=", RecordId) 
Set @CaseRow = Row(@Case, 1) 
Set @Subject = FIELD(@CaseRow, "Subject") 
Set @Status = FIELD(@CaseRow, "Status") 
Set @Description = FIELD(@CaseRow, "Description") 
]%% 
<br>
<br> 
SObject From API Call: %%=v(@mySObject)=%% 
<br> 
RecordId From API Call: %%=v(@myRecordId)=%% 
<br> 
Subject From RetrieveSalesforceObjects: %%=v(@Subject)=%% 
<br> 
Status From RetrieveSalesforceObjects: %%=v(@Status)=%% 
<br>
Description From RetrieveSalesforceObjects: %%=v(@Description)=%% 
<br>
Tip
Tip Validate a newly created email containing AMPscript against the newly created data extension. Triggered sends don’t activate if the email content doesn’t pass validation.