5

I have two object X and Y. Y is child of X. Object X is having a field called Title (Long Text Area). I want to show this field on Y also. Cross-reference formula field will not work since Title is a Long Text Area field. I don't want to write a trigger on object X since there are many triggers on X and it might hit governor limits. Is there any way to do so? Any thoughts?

2
  • 3
    You can try creating a custom VF page that pulls the Title field's data and add this page to your child object's page layout. – Vijay Prakash May 6 '13 at 10:32
  • 1
    Sounds like it's time to clean up your triggers on object x – Ralph Callaway May 6 '13 at 14:58
2

Option 1) Trigger on the parent object X to monitor for changes to title and cascade to child object Y

Option 2) Inline visualforce page on child Object Y that queries the Long Text Area from parent object X (from @Vijay_Prakash)

Regarding option 1, this is typically a pretty light weight operation, you just need N query rows, N dml rows, 1 query, and 1 dml, where N is the number of child Object Y related to parent Object X. If you're ensuring your trigger only processes changes for a particular parent Object X if the Long Text Area changes (see this answer for more discussion).

2
  • I am doing that which is working fine but suppose later on someone changes Title on X then how to accommodate that change. In that case I would have to write a trigger on X? – doga May 7 '13 at 3:39
  • Just fixed some typos in my answer, which may clarify things (object x and y is a little confusing, i added parent/child to clarify). You don't want a trigger on the child object Y, you want it on the parent object X. Since object Y is the master source for the field in that case you'll want to make the field on the child object X read only. – Ralph Callaway May 7 '13 at 20:16
-1

I suggest to write a trigger, it will work in all condition.

trigger UpdateFieldInChild on Parent(after insert, after update) {

List<Child> conList = new List<Child>();

for(Parent acc: Trigger.new)
{
    String newValueInUpdateChecking = acc.Update_Checking__c;
    for(Child con: acc.Childs)
    {
        Child conObj = new Child();
        conObj.Id = con.Id; 
        conObj.Update_Checking__c = newValueInUpdateChecking;
        conList.add(conObj);
    }

}
Update conList;

}

Hope this will help you. Thanks.

3
  • Welcome to SFSE! This is a very old question, and there have likely been updates to the best practices in the past 5 years. There are a few things I'd like to mention about your answer. First, OP (Original Poster of the question) clearly stated that they did not want to write a trigger, so it'd be a good idea to mention why you think a trigger is necessary (even though OP doesn't want to use one). Second, this trigger won't work as written because trigger context variables don't contain any data on related records (such as child records). You'll need to query for that information. – Derek F Aug 26 '18 at 20:23
  • Finally, this answer is what's known as a "code dump" (the majority of the answer is just code, with no explanation of what it does or how it works). Code dumps tend to generate a lot of back-and-forth in the comments along the lines of "that didn't work" and "try this instead", and are therefore not high-quality answers. – Derek F Aug 26 '18 at 20:23
  • When writing answers, I like to keep in mind that other people, with similar (but different) issues will be looking at my answer for help as well. Providing a solution that can be copy/pasted also means that the person copying the solution is unlikely to have learned anything (part of the goal of this site is to help others grow as programmers/admins). Wrapping things up here, a good answer will tend to cover some common points: 1) What is the problem? 2) Why it is a problem 3) How to fix the problem and 4) Why the fix works. – Derek F Aug 26 '18 at 20:23

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.