How to Display replated data when controlling field is selected

  • 2
  • Question
  • Updated 4 years ago
  • Answered
I have a field called Lead Name that looks up to the Lead object.  I then have other fields like Lead Phone, Lead Street, Lead City, Lead State and Lead Zip.  All those filed values are dependent on what is selected in the Lead Name.  As soon as I select a lead name I would like to have all the related data fields updated automatically.  Right now the fields are not populated until the model is saved.     I tried  setting up an action and re-querying the model when the Lead Name changed but that caused some issues for the page.   Any thoughts???
Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb

Posted 4 years ago

  • 2
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
What you tried is what we'd reccomend.  Create a separate lead model that doesn't load data on page load and has a condition on lead Id.  Then when your other model (that has the lead field) is updated run an action that activates the condition with the lead ID value and queries that separate lead model.  The field editor tied to the separate lead model will not show at first,  but when you select a lead - it will repaint and show the lead data. 
Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb

Rob,

I created the new model, and set an action on the old model to query the new model.  This seems to work but I am not getting the new data to display on the form.  If I go into the Developer Console I can see that the new model has the data that I want to display but the page still shows the old data - see below.   

So I had an old lead with an address that is shown on the form (left side).  I selected a new lead called 'Aimee Shane'.  On the right side you can see the address information for 'Aimee' but the form did not repaint.   Your thoughts?



Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Do you change the Lead Name in the field shown in your picture?  If so, the phone, and address information are being sourced from the first model (you can only have a field editor bound to one component).  You need to move the Lead Information into another field editor, bound to your second model.  Its the one that is being updated...  
Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb

Rob,

Once again, thanks for the assistance.

Jeff

Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb
Rob,

I have a follow up question.  I created a new model just for the lead address information called RepaintLeadData.  I have the main model that is called SampleRequest.  I have an action defined on the SampleRequest model that fires when the Lead name is changed.  This activates a condition on the RepaintLeadData model and queries the model (RepaintLeadData).  That updates the address information for the newly selected lead in the RepaintLeadData model.  

Now I want to update the fields on the SampleRequest model.  I set up an action on the RepaintLeadData model, for every time the model is queried to update fields on a row, select the SampleRequest model and update the address fields with the values from the RepaintLeadData model.   That sounds simple enough but I am not getting any values passed back to the SampleRequest model.  I tried using differnt merge syntax in the value field on the action ({{$Model.RepaintLeadData.data.0.Phone}}, {{Phone}} 123-456-7890) but nothing seems to work.  Any ideas or suggestions?
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
This one is a little misleading.  Though you can select a field from a related object in the Update Row action properties - you cannot actually update a field from a related object.  You need to use a different model if you want to update the data on the related object. 

So in your case,  I'd make the lead address section a different field editor,  and connect it to the RepaintLeadData model.  Here you will get the real time update,  and the user willb e able to edit the lead address information.