function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Can not Create a Task Using Upsert: Unable to create/update fields: AccountId. Error

I need to create a task and link it to an Account based on the account external id.

I use the example from the manual - upsert() call, the section on upset and foreign keys.

I generate the following XML request:
<Subject>User vb16Save and Send Password</Subject><Description>User vb16 sent password and welcome email by tremor_sa</Description><ActivityDate>2008-11-19+15:58</ActivityDate><Status>Completed</Status><Publisher__c>PD00013</Publisher__c><Account><type>Account</type><Publisher_NUM__c>PD00013</Publisher_NUM__c></Account>

where Publisher__c is the Task externalid and Publisher_NUM__cis the account external id

Wraped in SOAP it becomes:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:ns1="" xmlns:ns2="" xmlns:xsi=""><SOAP-ENV:Header><ns1:SessionHeader><ns1:sessionId>511500D80000000LY4g!ARYAQG_TG0xCEstjK2Kou1cnpI3.HAUkxEwZOGtaQ6a2hBngygs0_SPOu0cvZMwvlmgTiihBuX9mJKFgc8z4pejdC0m9oRCR</ns1:sessionId></ns1:SessionHeader></SOAP-ENV:Header>
<ns2:type>Task</ns2:type><ns2:Id xsi:nil="true"/><Subject>User vb16Save and Send Password</Subject><Description>User vb16 sent password and welcome email by tremor_sa</Description><ActivityDate>2008-11-19+15:58</ActivityDate><Status>Completed</Status><Publisher__c>PD00013</Publisher__c><Account><Publisher_NUM__c>PD00013</Publisher_NUM__c></Account></ns1:sObjects></ns1:upsert></SOAP-ENV:Body></SOAP-ENV:Envelope>

However I get a SF error:

Unable to create/update fields: AccountId. Please check the security settings of this field and verify that it is read/write for your profile.

Can someone help?

Again, this is specifically for a task.
I can't quite read that SOAP message, but I can tell you that the AccountId field on Task is not settable, it's derived.  Set the WhatId field instead.
Thank you, werewolf.

But I am not setting neither the AccountId nor the WhatId field. I am using an external id on the Account as in the xml excerpt:


Publisher_NUM__c is an external id field on the Account
The account relationship is for the accountId foreignkey field, you need to use the what relationship instead.
I am not sure I understand.

If use WhatId, it requires me to pass an AccountId. But I want to pass the account external id. Am I missing something?
use exactly the same thing you did with account, except call the element what instead of account.
Excellent, this works. Thank you.

I am trying to do the same thing but I am still getting an error. Can you show me what worked for you?