You need to sign in to do that
Don't have an account?
Jim Montgomery
adding account id to task on custom object
I have a custom object names Project. When I log a call as a task, the related to is the project Id. I assume that is the WhatId field on the task object. I need to be able to also have this task show up on the accounts activity history related list as well. I have a trigger, but get the error "Field is no writeable Task.AccountId."
Can you please paste your code here to check the issue.
Thanks,
Prem
if(trigger.isUpdate && trigger.isBefore){
For (Task T : trigger.new){
if(T.Task_AccountId__c != NULL || T.Task_AccountId__c != '')
{
T.AccountId = T.Task_AccountId__c;
}
}
}
if(Trigger.isInsert && trigger.isafter){
Task T = [select Id,WhatID,AccountID from task where Id=:trigger.new[0].Id];
if(T.Task_AccountId__c != NULL || T.Task_AccountId__c != '')
{
T.AccountId = T.Task_AccountId__c;
update t:
}
}
}
As per salesforce you can't use AccountId field in apex code. When you are updating whatId as account then this particular field will update automatically in backend. We can use only WhatId and WhoId to relate with task object.
If you want to integrate with more than one object you can go for custom lookup field which you have already created.
Thanks,
Prem
Field
Account Id
Type
reference
Properties
Group, Sort, Filter, Nillable
Description
Represents the ID of the related Account. The AccountId is determined as follows.
If the value of WhatId is any of the following objects, then Salesforce uses that object’s AccountId.
Account
Opportunity
Contract
Custom object that is a child of Account
If the value of the WhatId field is any other object, and the value of the WhoId field is a Contact object, then Salesforce uses that contact’s AccountId. (If your organization uses Shared Activities, then Salesforce uses the AccountId of the primary contact.)
Otherwise, Salesforce sets the value of the AccountId field to null.