0

Hi developer community,

I have the following trigger creating a child object when parent is saved. However, not all the field on the child object gets populated because they are only available on the child record.

trigger CreateBuyingInfluence on Opportunity_Positioning__c (after insert)

{
   List<Buying_Influence__c> Childs = new List<Buying_Influence__c>();
   for(Opportunity_Positioning__c a : trigger.new)
   {
      Buying_Influence__c Child = new Buying_Influence__c ();
      Child.SCOP__c = a.id;
      Child.Name = 'testName'; 

      Childs.add(Child);      
   }

   insert Childs;
}

So, I'm now trying to create a trigger that redirects me to the child page once parent is created/record saved.

When the Parent object=Opportunity Positioning is created then upon saving the record a trigger will prompt me to create Child Object=Buying Influences. Any ideas on how I can achieve this?

Thank you so much. Rog

2

A trigger is only meant to function at database level. It can't influence the UI and forward a user to a new page.

You have the following alternatives:

  1. create a formula field on the parent object containing a 'reminder' to create the child
  2. create all child fields in the parent object and copy them over from there in your trigger
  3. create 1 visualforce page overriding the parent new/edit page and make sure both objects are created from that page.
  4. create a visual workflow that takes the user through the process of creating the 2 objects

I'd suggest to go for #3 if you have the knowledge of APEX/Visualforce.

  • Hi Guy, thank you for your response. I have considered alternatives 2 and 3. – R.Lara Oct 13 '16 at 10:21
  • I've even started to work on a APEX/Visualforce page, however, as my knowledge was very limited I couldn't make it work. How would the option 1 work? Could I use it as a pop up? – R.Lara Oct 13 '16 at 10:24
  • Not as a popup, but you could use a roll-up summary to check whether or not the parent has a child or not. Based on that, show anything (colored text, whatever) in the formula field that you'll put on top of the page. – Guy Clairbois Oct 13 '16 at 10:28
  • Since you're not that experienced in APEX/Visualforce, I've added an option #4 that should be a bit easier to do. – Guy Clairbois Oct 13 '16 at 10:28
  • I've tried creating a Flow as well, but from a UI perspective, my managers didn't like how the data was displaying in only one column. – R.Lara Oct 13 '16 at 10:32

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.