You need to sign in to do that
Don't have an account?
Sourav P
How to autopopulate the field name from a set of records depends upon the minimum age fields maintained in another object
Dear All,, can anyone ssuggest 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 teh 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.
when we keep on adding new records, it should recalculate and choose the latest min one. I tried to write the trigger, but got stuck, can anybody plz try to rectify my trigger, thnx
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 teh 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.
when we keep on adding new records, it should recalculate and choose the latest min one. I tried to write the trigger, but got stuck, can anybody plz try to rectify my trigger, thnx
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; }
Refer the below trigger for your req. Change the contact object to your custom object quotation__c and instead of age__c i have used testnumber__c and in the account object i have used one field called sumoftotalnumber__c instead of the field u want to update in account object.
Regards
Please close the thread if it solved your problem
Thanks
Actually the need is,
I want to update the below fields, on the " Quotation__c" object, ( so this is the main field where the min age updation should come, but can we make all details to be updated, like e.g Young drive is a name string data type, gender, MS are picklists, so depends upon min age records, all fields here should get updated.)
The objects where age records are getting stored is the " Driver__c" object, these are the driver names with all details and various ages and other values.
I have written the above code as per your suggestions, but seems to me it should be opposite , the code is showing me various errors. Thanks
Also name the fields in each objects and from which field you want to take values and to where you want to store them?
Parent object : Quotation__c
Child object : Driver__c
From the parent object Quotation__c, the below fields should get filled up ( depends upon the min age from the driver records attached to the Quotation object, say if 4 driver records attached, then min age from this 4 drivers should reflect on the below fields on Quotation__c),
1.Young Driver (Young_Driver__c)
2. AgeAge (YoungD__c)
3. Gender (GenderYoungD__c)
4. Marital Status (Marital_Status__c)
5. Driving Experience (Driving_ExperienceYoungD__c)
6. Accidents in the last 12 Months (Accidents_in_the_last_12_MonthsYoungD__c)
In the child object, Driver__c, the same above fields do exists as per below,
1. Contact Number (Contact_Number__c) [ move to Young driver name field ]
2. Driver Age (Driver_Age__c)
3. Driver Gender (Driver_Gender__c)
4.Driver Marital StatusDriver_Marital_Status__c
5. Accidents in the last 12 MonthsAccidents_in_the_last_12_Months__c
Thanks
Let me know if there is any issues
The following code works only if one young driver exists.
Regards,
Pavan.