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
Alfredo OrnelasAlfredo Ornelas 

Trigger is showing an error after update

This is my FIRST trigger.
I want to create an "Event" after "Time Off Request" is Approved.
After approving, the following error message is showing...

User-added image

Here is my trigger:

trigger TRTimeOffAfterUpdate on Time_Off_Request__c (after update) {

for (Time_Off_Request__c toEvent : Trigger.new) {
    if(toEvent.Status__c=='Approved'){
   // Event event = new Event
   Event ev= new Event 
   (
        OwnerId = toEvent.CreatedById,
        StartDateTime = toEvent.First_Day_Off__c,
        EndDateTime = toEvent.End_Time_Off__c,
        Subject = toEvent.Type__c,
        Description =  toEvent.Comments__c,
        ShowAs = 'Out of Office'
    );
    insert ev ;             
}
}
}

Any idea what is wrong?
Thanks
Khan AnasKhan Anas (Salesforce Developers) 
Hi Alfredo,

Greetings to you!

This error occurs when the picklist field mentioned in the error message meets the following conditions:
 
  • 'Restrict picklist to the values defined in the value set' is enabled on the mentioned picklist field.
  • The mentioned picklist field is a dependent picklist.
  • The Page Layout does not include the controlling and dependent picklist fields.
  • A default value is set for the mentioned picklist field:
    • If the Object includes Record Types - This error occurs if the record type sets the default value.
    • If the Object does not include Record Types - This error occurs if the picklist field sets the value.

Please refer to below knowledge article for more information:
https://help.salesforce.com/articleView?id=000320321&type=1&mode=1 (https://help.salesforce.com/articleView?id=000320321&type=1&mode=1)

Please refer to the below links which might help you further with the above issue.

https://salesforce.stackexchange.com/questions/150504/picklist-value-not-recognized-in-the-test

https://salesforce.stackexchange.com/questions/229088/restricted-picklist-issue-even-providing-correct-value

https://success.salesforce.com/answers?id=9063A000000lCxhQAE

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
ASIF ALIASIF ALI
Make sure values are coming in the block , provide values for the required fields and Nullcheck for the fields which you are going to use as reference,