我可以在salesforce中拥有包含多种数据类型的列表

Pra*_*ady 1 salesforce visualforce apex-code

我有一个字符串List time1的值(00:00 AM,00:30 AM,01:00 AM,01:30 AM ...........所以一直到晚上11:30)

我还有一个自定义对象预约_c的列表appList.

此列表仅包含设定约会的记录

即如果预约设定为上午8点至上午8点30分和上午10点至上午11点,则只能保留这2条记录

我需要创建一个网格或表来显示从凌晨00:00到晚上11:30的当天约会.

我需要读通在该时间点的每一行,并检查是否有相应匹配的APPLIST那个时候,如果发现的话,我需要显示从APPLIST细节否则它应该显示对时间自由.我还需要将它存储在列表中,以便我可以在VF页面中使用它.我该怎么定义这个清单?我可以将列表存储在一列中,并在其他列中包含约会对象列表

有没有更好的方法来接近这个?

Mat*_*cey 5

在这种情况下,我将使用一个类并具有该类的对象列表:

class CTimeSlot
{
    public Time           tStart         {get; set;}
    public Appointment__c sAppointment   {get; set;}

    public CTimeSlot(Time startTime)
    {
        tStart = startTime;
        Appointment__c = null;
    }
}

// ** snip ** 

list<CTimeSlot> liTimeSlots = new list<CTimeSlot>();

// ** snip ** loop through times, and for each add an entry to the list

    CTimeSlot newSlot = new CTimeSlot(loopTime);
    liTimeSlots.add(newSlot);
    mapTimeToSlot.put(loopTime + '', newSlot);
}

// ** snip ** when running through your query results of Appointment__c objects:
for(Appointment__c sAppointment : [select Id, Time__c from Appointment__c where ...])
{
    if(mapTimeToSlot.get(sAppointment.Time__c) != null)
    {
        mapTimeToSlot.get(sAppointment.Time__c).sAppointment = sAppointment;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用CTimeSlot的实例填充此列表,并且在您预约的时间将其设置为实例上的sAppointment - 通过使用插槽的映射也可以更容易,映射时间(作为字符串)到CTimeSlot.

在页面中,您可以重复列表:

<table>
<apex:repeat var="slot" value="{!liTimeSlots}">
    <tr>
        <td><apex:outputText value="{!slot.tStart}"/></td>
        <td>
            <apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.SomeField)}"/>
        </td>
    </tr>
</apex:repeat>
Run Code Online (Sandbox Code Playgroud)

希望这会给你一些想法,让你走上正确的道路!