You need to sign in to do that
Don't have an account?
sasham
Converting to string from multiselect pick list. Any help on this Pls
It is a Apex code
My pick list value for TimeFrame __c is 12:00 - 08:00 AM.
I need to insert into string starttime__c as 12 Am and endTime__C as 8 AM from that value that i m getting ffor TimeFrame __c
My pick list value for TimeFrame __c is 12:00 - 08:00 AM.
I need to insert into string starttime__c as 12 Am and endTime__C as 8 AM from that value that i m getting ffor TimeFrame __c
<pre>
public static Map<String,String> startTimes = new Map<String,String>
{ '08:00 - 10:00 AM' => '8 AM',
'10:00 - 12:00 AM' => '10 AM',
'01:00 - 02:00 PM' => '1 PM',
'02:00 - 03:00 PM' => '2 PM',
'03:00 - 04:00 PM' => '3 PM'
};
public static Map<String,String> endTimes = new Map<String,String>
{ '08:00 - 10:00 AM' => '10 AM',
'10:00 - 12:00 AM' => '12 AM',
'01:00 - 02:00 PM' => '2 PM',
'02:00 - 03:00 PM' => '3 PM',
'03:00 - 04:00 PM' => '4 PM'
};
String timeFrame = recordA.TimeFrame__c.substringBefore( ';' );
recordB.StartTime__c = startTimes.get( timeFrame );
recordB.EndTime__c = endTimes.get( timeFrame );
</pre>
All Answers
<pre>
public static Map<String,String> startTimes = new Map<String,String>
{ '12:00 AM - 08:00 AM' => '12 AM',
'08:00 AM - 04:00 PM' => '8 AM',
'04:00 PM - 12:00 AM' => '4 PM'
};
public static Map<String,String> endTimes = new Map<String,String>
{ '12:00 AM - 08:00 AM' => '8 AM',
'08:00 AM - 04:00 PM' => '4 PM',
'04:00 PM - 12:00 AM' => '12 AM'
};
myRecord.StartTime__c = startTimes.get( myRecord.TimeFrame__c );
myRecord.EndTime__c = endTimes.get( myRecord.TimeFrame__c );
</pre>
Yes It is multi Select pick list value
I just gave one example for that value .
This value for the Multi select pick list field TimeFrame __c is quering from a object which already has avalue
and
And the i need to insert record into an other object with 2 string fields starttime and endtime
Ex:TimeFrame __c is 12:00 - 08:00 AM.
starttime: 12 AM
endtime : 8 AM
string s = '12:00 - 08:00 PM';
integer num = s.length();
if (num >0){
String start = s.substring(0,2);
String endt = s.substring(8,10);
String r = s.substring(14,16);
//integer num = s.length();
//if (num < 0)
system.debug(start);
system.debug(endt);
system.debug(r);
if (start.substring(0,1)=='0'){
start=start.substring(1,1);
system.debug(start);
}
if (endt.substring(0,1)=='0'){
endt=endt.substring(1,2);
system.debug(endt);
}
start = start + ' '+ r;
endt = endt + ' ' + r;
}
08:00 - 10:00 AM
10:00 - 12:00 AM
01:00 - 02:00 PM
02:00 - 03:00 PM
03:00 - 04:00 PM
TimeFrame__c = '08:00 - 10:00 AM;01:00 - 02:00 PM;02:00 - 03:00 PM';
Can a user select more than one value at a time?
Yes able to select morethan one at a time since it is multiselct . But recoed is inserted with the first one and time frame value is the first one
if they selected TimeFrame__c = '08:00 - 10:00 AM;01:00 - 02:00 PM;02:00 - 03:00 PM' this one.,the value for timefarme in that object is '08:00 - 10:00 AM.. So i always get one value for time frame.
This is how data i can see in that object. ( developed by someone)
<pre>
public static Map<String,String> startTimes = new Map<String,String>
{ '08:00 - 10:00 AM' => '8 AM',
'10:00 - 12:00 AM' => '10 AM',
'01:00 - 02:00 PM' => '1 PM',
'02:00 - 03:00 PM' => '2 PM',
'03:00 - 04:00 PM' => '3 PM'
};
public static Map<String,String> endTimes = new Map<String,String>
{ '08:00 - 10:00 AM' => '10 AM',
'10:00 - 12:00 AM' => '12 AM',
'01:00 - 02:00 PM' => '2 PM',
'02:00 - 03:00 PM' => '3 PM',
'03:00 - 04:00 PM' => '4 PM'
};
String timeFrame = recordA.TimeFrame__c.substringBefore( ';' );
recordB.StartTime__c = startTimes.get( timeFrame );
recordB.EndTime__c = endTimes.get( timeFrame );
</pre>
But i got the requirement , without touching the coding , they wiil be able to add more values to the picklist. and it should work
<pre>
String timeFrame = recordA.timeFrame__c.substringBefore( ';' );
Matcher matcher = Pattern.compile( '(\\d\\d):(\\d\\d) - (\\d\\d):(\\d\\d) (AM|PM)' ).matcher( timeFrame );
if ( matcher.matches() )
{
String startHour = matcher.group( 1 ).removeStart( '0' );
String endHour = matcher.group( 3 ).removeStart( '0' );
String meridian = matcher.group( 5 );
recordB.StartTime__c = startHour + ' ' + meridian;
recordB.EndTime__c = endHour + ' ' + meridian;
}
</pre>