0

I wrote the below code to store the form information directly into the salesforce contact object but it is not working. The cloud page is showing the 500 - Internal server error.

%%[VAR @fname,@lname,@status]%% 
%%[SET @fname=RequestParameter('fname')]%% 
%%[SET @lname=RequestParameter('lname')]%% 
%%[SET @status="True"]%%  
%%[SET @status=CreateSalesforceObject('Contact', 2, 'FirstName', @fname,'LastName', @lname)]%% 
<p>Thank You! %%=v(@fname)=%% %%=v(@lname)=%% for registering with us.Hope to see you at the Marathon. Keep Running and Have Fun!! </p>

But if the hard code the values it is working fine. Can anyone tell where I am going wrong.

1 Answer 1

3

The formatting is a bit off - you don't need to close the AMPscript block after each line, but that really shouldn’t be an issue.

Not sure why you are setting the @status twice - the first one will get overwritten by the second one anyway. To be able to troubleshoot, you can wrap your block in a try/catch statement.

Try below - my guess is that you have some required fields on a Contact which are not present in your script, eg. email address. Also, make sure you are using the correct API names of the fields on the Contact object.

You should be able to troubleshoot using below:

<script runat="server">
    Platform.Load("core","1");
    try {
</script>

%%[
VAR @fname, @lname, @contactId

SET @fname = RequestParameter("fname")
SET @lname = RequestParameter("lname")
SET @contactId = CreateSalesforceObject("Contact", 2, "FirstName", @fname, "LastName", @lname)

]%%

<script runat="server">
        }
        catch (err) {
            Write("Error Message: " + Stringify(err.message) + Stringify(err.description));
        }
</script>


Thank You! %%=v(@fname)=%% %%=v(@lname)=%% for registering with us.Hope to see you at the Marathon. Keep Running and Have Fun!!

If this doesn’t help, can you paste the whole code, including the form. Maybe the values from the form are not being passed correctly - you can read more about Salesforce integrated forms in Marketing Cloud here.

You must log in to answer this question.

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