hi I am beginer with Sales Force . Please dont judge me strictly . I am trying to create trigger for customer object .

Initial data: custom object with field: status type pickup list "maintanace finished", "open", "in progress".

test organisation . One of the task of this organozation has theme "Revision" and all tasks are related to custom object "transport".

The idea of trigger is following:

I need to switch trigger when one of the fields status of transport ( transport is my custom object) will be changed for "maintainace finished". The trigger should change status of All tasks of the test organization with the subject of open activity "Revision" for "completed". My problem that I cant find api for all these elements of Organizations ( tasks, task's status).

My code is following :

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')

  List<Task> taskstoupdate = new List<Task>([Select id,Theme__c from Task    
    id in: taskids]);

  for(Task t : taskstoupdate){

  update taskstoupdate;

The problem that I dont know how to work with Task object (t.Status_c t.Theme_c dont exist) . I think I have to work with field WhatId of Task object . But I dont know how .

1 Answer 1


As long as Theme__c is a custom field on your Task object then there's nothing wrong with that part of your code.

As for accessing Status, it's a standard field, so you don't need the __c suffix. Custom fields use __c and custom relationships use __r if you're traversing them.

Just add Status to your query:

List<Task> taskstoupdate = new List<Task>([select Id, Theme__c, Status from Task where Id in: taskids]);

and then set it as your are, but with the correct field name:

t.Status = 'Complete';

Otherwise things look ok, though I'm assuming where you have TaskLookupField you're actually referencing a custom lookup field so it'll be TaskLookupField__c or similar, based on the field's API name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .