You need to sign in to do that
Don't have an account?
Andrew Telford
Dynamically choose field to Update
I am attempting to create a trigger that will update certain fields if the value in a multipicklist is present.
Rather than have 20 If statements to check if the value is in it, I want to be able to something like
IF taskListValue is in picklistValue
THEN fieldToUpdate = fieldListValue.indexof( taskListValue.indexof( picklistValue )
It would then say something like ...
thisRecord.fieldToUpdate = TRUE
updateObject.add(thisRecord);
What I currently have is
Rather than have 20 If statements to check if the value is in it, I want to be able to something like
IF taskListValue is in picklistValue
THEN fieldToUpdate = fieldListValue.indexof( taskListValue.indexof( picklistValue )
It would then say something like ...
thisRecord.fieldToUpdate = TRUE
updateObject.add(thisRecord);
What I currently have is
//-- Some Varaibles to start with STRING strRelated = thisTask.Campaign_Related__c; STRING[] strRelated_split = strRelated.split(';'); LIST<STRING> lstOfTasks = NEW LIST<STRING>(); //-- Stores the values that can be in the multipicklist thisTask.Campaign_Related__c LIST<STRING> lstOfFields = NEW LIST<STRING>(); //-- Stores the field names that we want to update if the values is passed. These are in the same sequence so getting the index of one will refer to the index of the other. //-- Add some values to our lists lstOfTasks.add('EDU - Business Insurance Session'); lstOfFields.add('Business_Insurance_Session_Completed__c'); lstOfTasks.add('EDU - CBA/CFP Branch Training Session'); lstOfFields.add('CBA_CFP_Branch_Training_Session_Complete__c'); lstOfTasks.add('EDU - Client Seminars'); lstOfFields.add('Client_Seminars_Completed__c'); FOR(intCount = 0; intCount < strRelated_split.size() ; intCount++) { IF( strReleated_split[intCount] is in lstOfTasks) { intX = lstOfTasks.indexOf( strReleated_split[intCount] ); theField = lstOfFields[intX] thisAMP.thisField = TRUE; } }Any help would be appreciated.
All Answers
Please have a look on below code and let me know if you are looking for the same Please mark this as answer it fullfills your requiremnent.
Thanks,
Rakesh Kumar Saini
Unfortunately I am getting the following error
This is the current code
The final code looks like this for those that might come after ...