You need to sign in to do that
Don't have an account?
Keithlars
Merging values from 2 multiselect picklist in a trigger
I have two multiselect picklist for area of interest, one is being updated from outside of salesforce which I call my area_of_interest_landing__c field, the other is area_of_interest__c.
The area_of_interest_landing__c field may or may not have all the value selected that the area_of_interest__c field has. I need to keep a complete set of values being selected over time in the area_of_interest__c field. My thought was to create a trigger that would update the area_of_interest__c field whenever the area_of_interest_landing__c field is updated. This is my first trigger and I haven't seen any examples of updating multiselect picklist so I'm kind of struggling here so I would like to know if I'm on the right track with the code below. Currently, I get a complie error on invalid type of "String".
trigger area_of_interest on Lead (after insert, after update){
Set<String> interests = new Set<String>();
for (area_of_interest_landing__c aoiLanding : trigger.new)
interests.add(aoiLanding.area_of_interest_landing__c);
for (area_of_interest__c aoi : trigger.new)
interests.add(aoi.area_of_interest__c);
for (area_of_interest__c aoi : trigger.new)
aoi.area_of_interest__c = entries.get(aoi.area_of_interest__c);
}
The area_of_interest_landing__c field may or may not have all the value selected that the area_of_interest__c field has. I need to keep a complete set of values being selected over time in the area_of_interest__c field. My thought was to create a trigger that would update the area_of_interest__c field whenever the area_of_interest_landing__c field is updated. This is my first trigger and I haven't seen any examples of updating multiselect picklist so I'm kind of struggling here so I would like to know if I'm on the right track with the code below. Currently, I get a complie error on invalid type of "String".
trigger area_of_interest on Lead (after insert, after update){
Set<String> interests = new Set<String>();
for (area_of_interest_landing__c aoiLanding : trigger.new)
interests.add(aoiLanding.area_of_interest_landing__c);
for (area_of_interest__c aoi : trigger.new)
interests.add(aoi.area_of_interest__c);
for (area_of_interest__c aoi : trigger.new)
aoi.area_of_interest__c = entries.get(aoi.area_of_interest__c);
}
Message Edited by narsavagep on 11-19-2008 09:53 AM
All Answers
Change your for loops to look like this for(Lead variableName : Trigger.new)...
trigger area_of_interest on Lead (after insert, after update){
Set<String> interests = new Set<String>();
for (Lead aoiLanding:trigger.new)
interests.add(aoiLanding.area_of_interest_landing__c);
for (Lead aoi:trigger.new)
interests.add(aoi.area_of_interest__c);
//Update area_of_interest__c multiselect picklist field with values in Set named "interests"
???
}
You need to create a Map of Id and string then reference the map to update the other field.
Message Edited by narsavagep on 11-19-2008 09:53 AM