function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
s5s5 

Multi Picklist

Hi,

 

I created one custom object Booking and in this i created one custom field name which is a multi picklist.Cars is one more custom object.If i select the multi picklist in Booking it has to create the record type in cars.

 

Example :This is the multi picklist value

Maruthi-New

Alto-Old

According to above example i need to create the record type in Cars depending on only considering Maruthi or Alto.

For this i need to check before hyphen and then depending on Maruthi or Alto i hv to create record type.

How can this be done using apex code.Please help me in this.i have confusion regrading how to check value before hyphen.

 

If I select both value then it is seperated by semicolon like

Maruthi-New;Alto-Old

I tried seperating semicolon but i dont know how to seperate upto hyphen and assigned to one more field.

For this one i need to ckeck both i.e whether it is Maruthi or Alto and whether it is Old or New.

How can this be done using apex code except hard coding.If i hard code then the length of the programme is long.Please help me in this

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

Do this

 

 

String fieldValue = 'Maruthi-New;Alto-Old'; //Take this from field
List<String> listOption = fieldValue.split(';');

List<String> listStrFinal = new List<String>();
for(String option :  listOption)
         {
                 listStrFinal.add(option.split('-')[0]);
         }

system.debug(' ****** listStrFinal '+ listStrFinal);// this will give you {'Maruthi' , 'Alto'}

 

I hope I understood you issue correctly.

 

All Answers

Shashikant SharmaShashikant Sharma

Do this

 

 

String fieldValue = 'Maruthi-New;Alto-Old'; //Take this from field
List<String> listOption = fieldValue.split(';');

List<String> listStrFinal = new List<String>();
for(String option :  listOption)
         {
                 listStrFinal.add(option.split('-')[0]);
         }

system.debug(' ****** listStrFinal '+ listStrFinal);// this will give you {'Maruthi' , 'Alto'}

 

I hope I understood you issue correctly.

 

This was selected as the best answer
s5s5

Thank you.It is working.