function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rodrigo_RochaRodrigo_Rocha 

How to get the component (field) id within a standard lightning page?

I created a custom junction object (PS_Relationship__c) with  2 lookup fields  (Advisor__c and Private_Staff__c) to the User object.

If I run a query, I'm able to get th advisors name related to a specific private staff like: 

SELECT Advisor__r.Name FROM PS_Relationship__c WHERE Private_Staff__c != null

What I want is to create a component to list all the advisors the private staff is related to. So if I'm looking into a record within this custom object, for the private staff listed on the record, I want to be able to return all the other advisors related to the same Private Staff (Private_Staff__c) in the same page.

How do I get the field (component) ID for the private staff?
drs-medrs-me

So I guess you want to create a custom lightning component to display the advisors, right ?

If so,use force:hasRecordId to automatically get the current user record id:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_interfaces_force_hasrecordid.htm

Then your apex should look like
 

SELECT Advisor__r.Name FROM PS_Relationship__c WHERE Private_Staff__c != :recordId

Where as the recordId is a variable in the apex controller for this lightning component
Rodrigo_RochaRodrigo_Rocha
How do I reference a field within my component? For a custom lightning record page, I know how to get the component (field) id, but for the auto generated page layout, I'm not sure how to get it.

The problem is: I need to pass to the recordId variable, the populated value for a custom field, and not the record id for a record within my custom object.

Does it make sense?

Thanks.
 
drs-medrs-me
Hi Rodrigo,
yes it does make sense.
If you use the force:hasRecordId attribute on your lightning component, the record id of the current record on that page layout is v.recordId
Rodrigo_RochaRodrigo_Rocha
Any ideais? :)
drs-medrs-me
in your javascript you can get it with controller.get('v.recordId')
check it out here: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_interfaces_force_hasrecordid.htm