1

I have 2 custom objects with master-detail relationship:

custom_object__1(parent)
custom_object__2(child)

I have an after update trigger on the Custom_Object__1(parent) and also I have the if condition where the fields are set as criteria based on which the trigger.new is fired now I need to need to include the record type of the child object also on the filter type any approach on how to do this?

  • Are you trying to filter parent records based on record type of child records?. There can be multiple child records with different record types under one parent record right? – Victor Jun 8 '15 at 18:33
  • 1
    You will have to query the child objects including their RecordTypeId field for the set of objects in the trigger. And as @Victor mentions you need to consider how multiple record types for the child objects should affect the logic unless you have already constrained that in some way. – Keith C Jun 8 '15 at 18:35
  • In this case we have only 1 child all the time – Salesforce Learner Jun 8 '15 at 18:43
1

Code of this sort will allow you to use the developer name of the record type in your logic:

trigger MyTrigger on custom_object__1 (after update) {

    // Map is custom_object__1 to developer name of custom_object__2 record type
    Map<Id, String> m = new Map<Id, String>();
    for (custom_object__2 c2 : [
            select custom_object__1, RecordType.DeveloperName
            from custom_object__2
            where custom_object__1 in :Trigger.newMap.keySet()
            ]) {
        m.put(c2.custom_object__1, c2.RecordType.DeveloperName);
    }

    for (custom_object__1 c1 : Trigger.new) {
        String developerName = m.get(c1.Id);
        if (developerName == 'xyz') {
            ...
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.