You need to sign in to do that
Don't have an account?
Joe Hayes
Trigger to get value from another object based on picklist value
Hi,
I am having a bit of trouble and cannot find an answer that fits what I need.
I have 2 custom objects totally unrelated. Assessment__c, and AsstCodes__c.
AsstCodes__c has 2 fields Name and Description. Both are text fields.
What I want to achieve is this:
When I save a new Assessment__c record I want a trigger to update the Assessment__c.Description with the AsstCodes__c.Description.
The common factor is that Assessment__c.Code__c (picklist) will be the same value as a record in AsstCodes__c.Name (text value)
So far I have minimal code for this.
I know I need to do the following:
I am just not sure how to put it all together. Hope this all makes sense.
Thanks for your help
Joe
I am having a bit of trouble and cannot find an answer that fits what I need.
I have 2 custom objects totally unrelated. Assessment__c, and AsstCodes__c.
AsstCodes__c has 2 fields Name and Description. Both are text fields.
What I want to achieve is this:
When I save a new Assessment__c record I want a trigger to update the Assessment__c.Description with the AsstCodes__c.Description.
The common factor is that Assessment__c.Code__c (picklist) will be the same value as a record in AsstCodes__c.Name (text value)
So far I have minimal code for this.
I know I need to do the following:
AsstCodeDescription = [SELECT description__c FROM AsstCodes__c WHERE Assessment__c.Name = AsstCode.Name LIMIT 1];
trigger AsstDesc on Assessment__c (after insert, after update) { map<string, Assessment__c> TheMap = new map<string, Assessment__c>(); for (Assessment__c Desc:trigger.new) { if (Desc.Name !='') Desc.Description__c = AsstCodeDescription; update desc; } }
I am just not sure how to put it all together. Hope this all makes sense.
Thanks for your help
Joe
Also, this may work better in a before context so that you don't have to worry about recursion.
All Answers
Also, this may work better in a before context so that you don't have to worry about recursion.
At the moment I'm getting an error on line 10 (Compile Error: Unexpected token 'Desc'. at line 10 column 23)
Not sure where I'm going wrong.
Thanks
Joe
Thank you