I need your advice. I have custom LWC for tab and record page. For tab this component show accounts list with related oportunities. For record page it should show only this account and also it should be hidden search and pagination. I made functionality for tab but don't know how to use the same lwc for record page. Can you help me?
1 Answer
In your component's class, make sure you have the following line of code:
@api recordId;
After that, you can call a wire or imperative Apex call to get just the account's records. This attribute will be null when you're not viewing a record, and it will be not-null when you are viewing a record. You can use connectedCallback
to determine which method you'd like to call.
connectedCallback() {
if(this.recordId) {
this.loadTabData();
} else {
this.loadRecordData();
}
}
You can read more about how to Make a Component Aware of Its Record Context and how to Call Apex Methods Imperatively.
-
I made as you advice me. Thank you. Everything works great!– YauheniCommented Jun 28, 2022 at 19:07