I'm trying to create a Sales Cloud task using AMPscript. There's not much detailed documentation out there so I'm trying different API field names and haven't figured it out. Here's my code:

    var @createtask
    set @createtask = CreateSalesforceObject(
        'Task', 6,
        'Priority', 'High',
        'Status', 'Not Started',
        'OwnerId', 'xxxx',
        'WhoId', @ID,
        'WhatId', 'xxxxx',
        'Subject', 'Task 123'
  • What is your question? What issues are you encountering? are you defining @id somewhere?
    – EazyE
    Jul 26, 2019 at 17:55
  • Yes contact or lead ID is defined. I've been unable to successfully create a task with the above code. Jul 26, 2019 at 17:58

2 Answers 2


This can be frustrating indeed.

ask these questions:

  • Are you using the API Name of all Sales Cloud fields, not the label?

  • Do you have all mandatory fields included for, in your case, task?

I found it helpful to limit myself to only mandatory fields. Once this works, advance field by field. While doing that, don't forget the next point...

  • is the number of fields stated in the call correct? (in your case, 6 looks correct)

  • for picklists: are all the field values you are trying to set exactly matching an existing picklist value?

  • for text fields: is your value you within the defined maxlength?

  • Are you including date fields? If yes, Format(@mydate,iso) helps.

    • For lookups: is the ID (still) valid in this org (careful with sandboxes)

all of this can be fixed in your code. Also check creating the record manually with a user that has equivalent permissions as your API user, to test against this:

  • Are there any validations within Sales Cloud that forbid the creation?

  • In the connector, do you have read and write access on the object (normally, you should)?

To isolate: Can you create another object (e.g. lead?)- again, note that you need all mandatory fields like lastname, company and have the correct number of fields specified.


Here is a code example that worked for me:

set @id=CreateSalesforceObject('task', 5, 'OwnerId', @myOwnerId, 'Subject', @mySubject, 'Status', 'Open', 'Priority','High', 'Description', @myComment)

The OwnerId has to start with "005". It is also quite handy to write your ampscript in an email as you get a feedback in the email preview about your ampscript.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .