You need to sign in to do that
Don't have an account?
Abhilash 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
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
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:
Account:
Trigger:
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
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