You need to sign in to do that
Don't have an account?
multi select picklist
i have multi select picklist feild in account. the no of opportunities should be created that are equals to values selected in multi select picklist feild
i wrote below code . by using this iam able to create one opportunty at a time
trigger:
=========================
trigger OppIns on Account (after insert) {
list<Opportunity> oppts =new list<Opportunity>();
for(account acc:trigger.new)
{
oppts =new list<Opportunity>();
oppts.add(new Opportunity(name=acc.products__c,accountid=acc.id,StageName='Prospecting',Closedate=date.today()));
}
insert oppts;
}
for example i select two values in picklist two opportunity should be created
In this case inside the for loop you have to first get the value of the multi-select picklist value to string
String multi = Acccount.SomeField__c;
Then split the string based on ';' using split function. So you got the list of values which were selected in the
multi-select picklist and then iterate through the same and create opportunity records for each value selected
All Answers
In this case inside the for loop you have to first get the value of the multi-select picklist value to string
String multi = Acccount.SomeField__c;
Then split the string based on ';' using split function. So you got the list of values which were selected in the
multi-select picklist and then iterate through the same and create opportunity records for each value selected
thanks for your reply
how to iterate splited values, can u post me the code snippet
List<Opportunity> oppts = new List<Opportunity>();
String selected = 'A;B;C;D'; // THe value selected from multi-select picklist will look something like this in background
List<String> selectedValues = Selected.split(';'); // Split to get the individual values
for(String selectedValuesInstance : selectedValues)
{
oppts.add(new Opportunity(name=acc.products__c,accountid=acc.id,StageName='Prospecting',Closedate=date.today(),
PicklistField__c = selectedValuesInstance));
}