Skip to main content
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
12 个回答
  1. 2017年8月15日 13:05
    OK.  I still think using maps to look up the start and end times is the way to go.  You'll have to add your 6th value to the maps, as you didn't post it.

    <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>

     
0/9000