hi I am learning Salesforce. I have created trigger for my custom object. I have an error the following type:
Error: Compile Error: No such column 'Theme__c' on entity 'Task'. If
you are attempting to use a custom field, be sure to append the '__c'
after the custom field name. Please reference your WSDL or the
describe call for the appropriate names. at line 14 column 44
My code:
trigger Status_completed on Transport__c (before update) {
Set<id> taskids = new Set<Id>();
for (Transport__c u : Trigger.new) {
if ( u.Status__c = 'Maintainace finished')
{
if(u.TaskLookupField!=null)
taskids.add(u.TaskLookupField);
}
}
List<Task> taskstoupdate = new List<Task>([Select id,Theme__c from Task
where
id in: taskids]);
for(Task t : taskstoupdate){
if(t.Theme__c=='Revision')
t.Theme__c='Complete';
}
update taskstoupdate;
}
I think I have to relate my transport object with the Task object through the field Whatid in the select statement, but I dont know how to do it . I cant find corresponding field in my custom object Transport should I created it
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_task.htm#topic-title
I have doubts can I relate this field whatId with my custom field directly or I have to do it through the Account as intemediate object ?
Best Answer
If your aim is to update Tasks that are related to to your
Transport__c
custom object, then theTask
WhatId
field will contain theId
values of any relatedTransport__c
objects. So to change the status of theTask
objects when theTransport__c
object statuses change you would use code like this: