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
yaakovyaakov 

INVALID_FIELD_FOR_INSERT_UPDATE on accountId field when trying to create Task

I am trying to create tasks through the webservice API. I have code that looks something like this:

List<sObject> objs = new List<sObject>;
foreach ... {
  Task task = new Task();
  task.AccountId = accountID;
  task.WhatId = opportunityID;
  task.Subject = subject;
  task.Description = description;
  task.ActivityDate = date;
  task.IsClosed = isComplete;
  task.Priority = "Normal";
  task.Status = (isComplete) ? "Completed" : "In Progress";
  objs.Add(task);
}

sObject[] objArray = objs.ToArray();
SaveResult[] resArray = new SaveResult[objs.Count];
DebuggingInfo debInfo = binding.create(sessionHeader, new AssignmentRuleHeader(), new MruHeader(), new DebuggingHeader(), new EmailHeader(), objArray, out resArray);


The accountIds and opportunityIds were retrieved earlier in the code through the API. I have confirmed that they are valid IDs, referring to the correct accounts and opportunities that already exist in the DB.

For each task that I try to inset, I receive the following error message:
Error code is: INVALID_FIELD_FOR_INSERT_UPDATE
Error message: Unable to create/update fields: AccountId. Please check the security settings of this field and verify that it is read/write for your profile.
The error code and message seem to imply that I cannot create a task with an accountId. This seems strange, as I want to relate the task to the accountId.

Any idea on what the error message means, and how I can fix this so that I can insert tasks into the DB through the API? (And regarding the instruction to check the security settings of this field, etc, I have done some poking around in my account and I could not find where to do this, if this would indeed solve my problem).

Thanks!


Message Edited by yaakov on 03-04-2008 11:26 PM
Best Answer chosen by Admin (Salesforce Developers) 
yaakovyaakov
I was able to solve the problem by not setting task.AccountId. Apparently, all I needed to set was the task.WhatId value, and upon import, the API webservice automatically detects and sets the AccountId based on the WhatId value.

All Answers

yaakovyaakov
I was able to solve the problem by not setting task.AccountId. Apparently, all I needed to set was the task.WhatId value, and upon import, the API webservice automatically detects and sets the AccountId based on the WhatId value.
This was selected as the best answer
BlurryBlurry
Thank you very much for explaining your solution. I had exactly the same problem.
learnSFlearnSF
Thanks you very muck.It solved my problem too.
SnowMoreSnowMore

 

Thanks very much for posting this, as this is obviously not correctly documented.

 

Here's my followup question: Suppose you want the task to be associated with both an account an an opportunity?.  If you assign the AccountID to the WhatID field, what field do you assign the OpportunityID to?

SuperfellSuperfell
you set it to the opportunityId, and accountId will be automatically set to the accountId of the opportunity.
erbiserbis

There's no opportunityId in Task object.

 

Does anyone know how to accomplish the original request? Which is to update a task in a way that it has a reference to an opportuniy and a reference to an account.

 

Thanks,

SuperfellSuperfell

You'd set the WhatId to be the id of the opportunity.

MIKE_DAYMIKE_DAY

Hi,

 

If you set the WhatId to a 'Case' it does not pickup the AccountID automatically but it does with all other objects.  I have had this support ticket open with Support for over 2 weeks.  Does anyone know why or if there is a work around?

 

Thanks