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
vb13vb13 

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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:partner.soap.sforce.com" xmlns:ns2="urn:sobject.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header><ns1:SessionHeader><ns1:sessionId>511500D80000000LY4g!ARYAQG_TG0xCEstjK2Kou1cnpI3.HAUkxEwZOGtaQ6a2hBngygs0_SPOu0cvZMwvlmgTiihBuX9mJKFgc8z4pejdC0m9oRCR</ns1:sessionId></ns1:SessionHeader></SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:upsert><ns1:externalIDFieldName>Publisher__c</ns1:externalIDFieldName><ns1:sObjects>
<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.
werewolfwerewolf
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.
vb13vb13
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:

Account><type>Account</type><Publisher_NUM__c>PD00013</Publisher_NUM__c></Account>


Publisher_NUM__c is an external id field on the Account
SuperfellSuperfell
The account relationship is for the accountId foreignkey field, you need to use the what relationship instead.
vb13vb13
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?
SuperfellSuperfell
use exactly the same thing you did with account, except call the element what instead of account.
vb13vb13
Excellent, this works. Thank you.
banders5144banders5144

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