I have a custom object named "Property Booking" where if the status changed to approved I have to create a record for my "Quotation" custom object. The tricky part here for me is I don't know how I can input values using the child to parent.
"Property"(master) and "Customer"(master) have a master-detail relationship with my "Property Booking"(detail) object
I tried using the following: pb.Property__r.Type -> not working. Error: Variable does not exist: Type ( but it does exist in the object) pb.Customer__r.Email -> not working.
newQuoList.Property_Type__c = ; ---- what I am trying to do with the line of code above is to insert a "Type" that is based on the "Property" parent field
newQuoList.Customer_Email__c = ; ---- what I am trying to do with the line of code above is to insert an "Email" that is based on the "Customer" parent field.
hoping to have some help or shed some light for this concept. I am quite new here, I am told that I should query in order to get it. But I have no idea on how to start on this.
These are my codes:
public static void isAfterUpdate(List<Property_Booking__c> pbList){
for(Property_Booking__c pb: pbList){
try{
//if the status moves to approved, then a new quotation record should be created, all the fields
//of the quotation record should take in data from rest of the 3 objects except quoted to customer.
//Price should be the quoted price - Case # 8
if(pb.Status__c == 'Approved'){
//list of quotation record to be created
List<Quotation__c> quoList = new List<Quotation__c>();
try{
//insert quotation records
for(Quotation__c newQuoList: quoList){
newQuoList.Booking_Ref__c = pb.Name;
newQuoList.Property_Name__c = pb.propertyName__c;
newQuoList.Property_Type__c = ;
newQuoList.Customer_Name__c = pb.customerName__c;
newQuoList.Acquire_Property_By__c = pb.Acquire_Property_By__c;
newQuoList.Price__c = pb.Quoted_Price__c;
newQuoList.Customer_Email__c = ;
quoList.add(newQuoList);
}
insert quoList;
}catch(DmlException e){
System.debug('An unexpected error has occured: ' +e.getMessage());
}
}
}
My trigger
trigger PropertyBookingTriggers on Property_Booking__c (before insert, after update) {
if(trigger.isUpdate && trigger.isAfter){
PropertyBookingHandler.isAfterUpdate(trigger.new);
}
if(trigger.isInsert && trigger.isBefore){
}
}