can anyone suggest plz. I have a custom object " Quotation" where there is a Driver details section with below fields,
Now, I have a related object on Quotation object, which is a look up to the " Personal account " field. Below are the various test names of the drivers
Each has an Age maintained in the respective records. Now i need to select the minimum age from all these records and whoever has the min age, that name will reflect in the " Young driver" field with all other detailed fields. Can you plz suggest how to achieve this, i was trying formula field and process builder but couldn't able to make it work. when we keep on adding new records, it should recalculate and choose the latest min one. Thanx
I tried to write the trigger, but got stuck, anyone plz help me on rectifying the below trigger,
trigger trgYoungDriver on Quotation__c (after insert, after update, after delete) {
Set<Id> orgIds = new Set<Id>();
List< Account> updates = new List<Account>();
Quotation__c[] qot = null;
if(Trigger.isInsert||Trigger.isUpdate)
{
qot = Trigger.new;
}
else if(Trigger.isDelete)
{
qot = Trigger.old;
}
for(Quotation__c q : [select id,
min(Contact_Number__r.Age__c),Young_Driver__c,AgeYoungD__c from Quotation__c
where id IN :Trigger.new])
for(Quotation__c p : [select id,
min(Contact_Number__r.Age__c),Young_Driver__c,AgeYoungD__c from Quotation__c
where id IN :Trigger.old])
{
updates.add(q.AgeYoungD__c)=q.Contact_Number__r.Age__c;
}
update updates;
}