我曾经像你一样问人们如何编写代码,但这是一种习惯,必须改变。试着依靠自己,写一些代码;然后问别人。从伪代码开始,查看示例 - 从长远来看,这可能会对您有所帮助。
根据问题,请在下面找到一些代码。我没有给你我希望你学习的整个代码!
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 检查它们是否可用
这两个都应该可以正常工作。试试看。干杯!