我有三个对象 1)Truck__c 2)Booking__C 3)Payment___C。Truck 和 Booking 具有 master detail 关系,其中 Truckk 是 master 而 Booking 是 detail。预订和付款具有查找关系,其中预订是父项,付款是子项。
我想根据付款对象中的字段剩余金额中的值更新卡车中存在的字段 isBooked(checkbox)。我在 Payment 对象上添加了触发器,如下所示
trigger TestTrigger on Payment__c (after insert) {
if(Trigger.isAfter && Trigger.isUpdate){
for (Payment__c pay:Trigger.New)
{
payId.add(pay.id);
paidAmount =Integer.valueOf(pay.Paid_Amount__c);
}
Map <id,Booking__c> bookingMap = new Map <id,Booking__c> ();
for (Booking__c obj: [Select Id, Booking_ID__c from Booking__c where Booking_ID__c in:payId])
{
bookingMap.put(obj.Booking_ID__c, obj);
}
for(Booking__c objBooking:matchingIdsMap){
Truck__c truckObj = [Select id,Price__c from Truck__c where Truck__c.id = objBooking.Truck__c.id];
//Integer paidAmount = Payment__c.Paid_Amount__c;
Integer totalAmount = Integer.valueOf(truckObj.Price__c);
Integer remainingAmount = totalAmount-paidAmount;
If(remainingAmount == 0){
truckObj.Booked__c = true
}
update truckObj;
}
}
}
在这里,我首先获取付款 ID,并基于此获取 Booking 对象,它是付款的查找父对象。在此之后,我试图获取作为预订大师的卡车对象。但我不知道如何查询这个作为查询中的 where 子句给出错误
Truck__c truckObj = [Select id,Price__c from Truck__c where Truck__c.id = objBooking.Truck__c.id];
请注意,卡车和付款之间没有直接关系
我如何获取卡车对象提前致谢