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
SFDC16SFDC16 

WhatId error

Below are trigger and error.


Error: Compile Error: Variable does not exist: whatId at line 13 column 14

trigger LinkdTaskToIncident on BMCServiceDesk__Incident__c (before insert) 
{

    List<BMCServiceDesk__Task__c>  task=new  List<BMCServiceDesk__Task__c>();
        
        for(BMCServiceDesk__Incident__c c:Trigger.new)
        {
           if(c.BMCServiceDesk__Is_New_Record__c==true)
           {    
            
             BMCServiceDesk__Task__c t = new BMCServiceDesk__Task__c();
             t.BMCServiceDesk__taskDescription__c=c.BMCServiceDesk__incidentDescription__c;
             whatId=c.id;

             task.add(t);
           }
        }
          
             insert task;    
}
Best Answer chosen by SFDC16
SecondID PatelSecondID Patel
Hi,

In the code of your custom trigger you are initiatiing your custom object after the if condition and then on line no. 13 you are assigning the value to WhatId which is not the field of your custom object...In short you are trying to write trigger on Custom object and using one of the fields of task object which is not correct.

WhatId is the field of Task and not your custom object.

Waiting for your response if this might solve your issue.

 

All Answers

SecondID PatelSecondID Patel
Hello SFDC16,

Just update your line no. 13 of code from whatId = c.id ------------ t.whatId = c.id...

The notation is missing everything else is fine.

Also, please Mark it as the best answer.
SFDC16SFDC16
Still, it is not working. [image: image.png]
SecondID PatelSecondID Patel
What's your new error?
 
SFDC16SFDC16
Same Error Variable does not exist: whatId at line 13 column 14
SecondID PatelSecondID Patel
Please give the object names and field names with your requirement.
 
SecondID PatelSecondID Patel
Hi,

In the code of your custom trigger you are initiatiing your custom object after the if condition and then on line no. 13 you are assigning the value to WhatId which is not the field of your custom object...In short you are trying to write trigger on Custom object and using one of the fields of task object which is not correct.

WhatId is the field of Task and not your custom object.

Waiting for your response if this might solve your issue.

 
This was selected as the best answer