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
Abhilash DaslalAbhilash Daslal 

Problem with my trigger

Hi Guys,
I have the following trigger which is not working as expected.

The User has a picklist field Colour__c which has values red,pink,purple,green and yellow.
The Account has a text field called Owner_Colour__c.

The Trigger assigns the Owner's colour while inserting the Account record.Please help

trigger AssignUserColourToAccount on Account (before insert , before update) {
    List<Account> accList = new List<Account>();
    String ownerColour = [Select id,Colour__c from User WHERE id=:UserInfo.getUserId()][0].Colour__c;
        for (Account acc : trigger.new){
            acc.Owner_Colour__c = ownerColour;
            accList.add(acc);
        }
         
}

Thanks,
Abhilash
Khan AnasKhan Anas (Salesforce Developers) 
Hi Abhilash,

Greetings to you!

I have tried the same code in my org and it is working fine (see screenshots). It might possible that you have other trigger/process builder/workflow which is/are conflicting with this trigger. 

Also, please check that your trigger is active.

User:
User-added image

Account:
User-added image


Trigger:
User-added image


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.

Thanks and Regards,
Khan Anas
Abhilash DaslalAbhilash Daslal
Hi Anas, 
Thank you for your reply. It was the problem with the field data type and I had not given value to the field Colour__c for the user. Now the issue is solved 

thanks, 
Abhilash