0

我有以下表格

  1. 床(床号,价格,is_active,状态)

  2. 房间(房间号,价格,is_active,状态,床号)

  3. 公寓(公寓 ID、价格、is_active、状态、公寓 ID)

  4. Booking(booking id, start date, end date, apartment id, room id, bed id)

完成公寓预订后,公寓中的所有房间都应该可用。公寓房间内的所有床位都应该可用。

完成房间预订后,该房间的所有床位都应该可用。

我必须这样做才能批量更新预订记录。在 for 循环中检查可用性是不可行的。如下所示

for(预订 bookingObj : AllBookings){

checkAvailability(预订ID,床,房间,公寓)

}

代码要写在触发器中。

4

1 回答 1

0

我曾经像你一样问人们如何编写代码,但这是一种习惯,必须改变。试着依靠自己,写一些代码;然后问别人。从伪代码开始,查看示例 - 从长远来看,这可能会对您有所帮助。

根据问题,请在下面找到一些代码。我没有给你我希望你学习的整个代码!

trigger CheckBooking on Booking__c (after update){
    for(Booking__c booking : trigger.new){
    //Check if the booking is updated   
    If(Updated){
        //Grab the booking Id into a string var, example below:
        String bookingId = booking.Id;
        //Grab the room Id into a string var
        //Grab the Apartment Id into a string var
        //Grab the bed Id into a string var
    }
  // Do SOQL to check if the room, Apartment, bed are available 
   /*SOQL goes here*/

   //Check to make sure the availability 
    if(available){
        //do your logic
    }
    else{
        //do your logic
    }
  }        
}

注意:在批量大小为 1 时执行此更新,以便为每个记录执行此触发器,即事务大小为 1。

如果您想使交易规模更大,请执行以下操作:
1. 将房间、公寓、床位 ID 添加到列表中,然后使用 SOQL 检查它们是否可用

这两个都应该可以正常工作。试试看。干杯!

于 2012-11-14T19:19:27.687 回答