+ Start a Discussion
Tyler Morgan 9Tyler Morgan 9 

Component showing records from custom object

On our Opportunity page users have a field to choose an Engineer. These engineers are stored on a custom object.

I would like to display a VF component on the sidebar of the Opp page showing the past Engineer records used on Opps across the parent Account. There typically wouldn't be more than 2-4 over the history of the account. It would also be acceptable for this to display on the Account page.

I have some experience with VF, but don't know where to start with this project going across objects.

Best Answer chosen by Tyler Morgan 9
Abhishek BansalAbhishek Bansal
Hi Tyler,

Yes this can be done easily if you follow the below steps:
  1. Create a lightning component and make sure it is available for flexi pages.
  2. In the init method query the related opportunities of the account where engineer field is not blank.
  3. You can store all these values in a list.
  4. Now display this list in your component in whatever way you want to show it to the users.
  5. Add the component in the Opportunity flexi page.
Let me know if you need any help with the lightning code. You can reach out to me on:
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790

Thanks,
Abhishek Bansal.

All Answers

Brian Weers 18Brian Weers 18
Are you operating in classic or lightning?  I assume lightning since you use the word component.  Is there a reason you don't write this as a component?  As to your visualforce question - if the Engineer field is lookup field to the Engineer object, you'll probably need to have history tracking on for that field and query the history object to get your values.  Querying the history object is a little different.  Query would be something like 'Select id,oldvalue,newvalue,field from opportunityFieldHistory were field = 'Engineer'.  From there you'll have to weed out the noise and changes.  It's also possible to query the opportunityFeed.
Tyler Morgan 9Tyler Morgan 9

Thank you for your response.

We're working in Lightning. I suppose I would do it as a component.

But yeah, I want to know for Account A, which has had ~100 opportunities, which engineers have been chosen over the span of those opps.

Why would I need to use field history tracking if I'm only interested in the current values of the field in these opps?

Abhishek BansalAbhishek Bansal
Hi Tyler,

Yes this can be done easily if you follow the below steps:
  1. Create a lightning component and make sure it is available for flexi pages.
  2. In the init method query the related opportunities of the account where engineer field is not blank.
  3. You can store all these values in a list.
  4. Now display this list in your component in whatever way you want to show it to the users.
  5. Add the component in the Opportunity flexi page.
Let me know if you need any help with the lightning code. You can reach out to me on:
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790

Thanks,
Abhishek Bansal.
This was selected as the best answer