You need to sign in to do that
Don't have an account?
Matthew Holdgate
Trigger to populate the lookup field on child object
Hi
I have a field where the lookup filter always delivers one record. Is it possible to build a trigger that populates this in the back end and prevents the user having to have to click on this. If so how would it look?
My Parent object is called "terms and conditions" and has fields for ID, Content, Retirement date and Active date. the filter on the lookup at the minute it shows the record that has no retirement date and the active date is after the current date.
The child object has a lookup field on that calles DOUM_TCs.
Any help as I have never heard of apex or triggers before starting this development. Cheers
I have a field where the lookup filter always delivers one record. Is it possible to build a trigger that populates this in the back end and prevents the user having to have to click on this. If so how would it look?
My Parent object is called "terms and conditions" and has fields for ID, Content, Retirement date and Active date. the filter on the lookup at the minute it shows the record that has no retirement date and the active date is after the current date.
The child object has a lookup field on that calles DOUM_TCs.
Any help as I have never heard of apex or triggers before starting this development. Cheers
Please check with below thread from forums community with similar kind issue and suggested workarounds.
- https://developer.salesforce.com/forums/?id=906F0000000918rIAA
Please mark this as solved if it's resolved.Regards,
Nagendra.
I have this so far but get an error: "Invalid foreign key relationship: DOUM_Terms_Conditions__c.DOUM_Terms_Conditions__cobjGL at line 8 column 19"
trigger SetTermsConditions on DOUM_Version__c (before insert, before update) {
Map<Id,Id> cases = new Map<Id,Id>();
List<DOUM_Version__c> listGL = new List<DOUM_Version__c>();
listGL = [Select DOUM_Terms_Conditions__r.Name, DOUM_Terms_Conditions__c from DOUM_Version__c where Id In: trigger.newMap.keySet() AND DOUM_Terms_Conditions__c <> null];
for(DOUM_Terms_Conditions__c objGL: listGL)
{
cases.put(objGL.DOUM_Terms_Conditions__cobjGL.DOUM_Terms_Conditions__r.Name);
}
for (DOUM_Version__c a : Trigger.new)
{
if(a.DOUM_Terms_Conditions__c != null)
{
a.DOUM_Terms_Conditions__c = cases.get(a.DOUM_Terms_Conditions__c);
}
}
}
Any ideas?
With
" cases.put(objGL.id,objGL.DOUM_Terms_Conditions__r.Name); "
objGL.id will give you the id of DOUM_Terms_Conditions__c record.
I can help you more if you can tell me about what values you weant to see in cases map. cases<?,?>
I know get the above error