Skip to main content
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
2 answers
  1. Nov 9, 2018, 7:06 AM
    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:

    Hi Abhilash,Greetings to you!I have tried the same code in my org and it is working fine (see screenshots).

    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
0/9000