You need to sign in to do that
Don't have an account?
richfer_right
how to auto-assign color values to a field when a new record is created?
I have created a text field in a custom object. I want to update the field value with color values everytime when a record is created
I see you are a developer of few words.
The following code snippet assumes the colours are stored in the apex class. If not, you'll need to retrieve them from wherever. It also assumes the sobject type is Contact and the field is 'Colour__c' - replace as appropriate.
This method should be called from a before insert trigger, as that way it can change the records before they are committed to the database:
All Answers
Can you clarify your use case. Are you looking to assign the same text to each new record? If so, you can look at using a formula to specify a default value for the field.
No, have to assign different color values to each records
Tell me more - are you round-robin assigning from a pool of colours, or is it random?
It is to be assigned randomly to the field
I see you are a developer of few words.
The following code snippet assumes the colours are stored in the apex class. If not, you'll need to retrieve them from wherever. It also assumes the sobject type is Contact and the field is 'Colour__c' - replace as appropriate.
This method should be called from a before insert trigger, as that way it can change the records before they are committed to the database: