You need to sign in to do that
Don't have an account?

lwc to pass id to another component
how to pass record id from one component to another in lightning web component ??
please do tell using the example,, suppose i have one component in which i am creating campaign and after clicking on save button it jumps to another component and in that component i want to create a campaign member for the (id) campaign which is created in previous component.
thank you
please do tell using the example,, suppose i have one component in which i am creating campaign and after clicking on save button it jumps to another component and in that component i want to create a campaign member for the (id) campaign which is created in previous component.
thank you
You could make use of events to pass information between different components, below is the link to the example I found: https://salesforce.stackexchange.com/questions/219130/passing-id-between-2-lightning-components
The information in above link is below for quick reference:
Use a lightning event to communicate the survey Id to the parent component, then the parent can pass it along to the other component either using an aura:attribute and binding the new value into the child component's survey Id attribute (recommended for your case), or by calling an aura:method defined on the child component and passing the survey Id as a parameter into that method.
See how to pass information from a child to a parent via a component event here: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_component_example.htm
As a general rule of thumb, component events are used to pass information to the parent, and the parent can use methods to pass/call the child component to do something.
Bonus Edit:
A really great article from Philippe Ozil about best practices for communicating between components: Salesforce Developers Blog: Lightning Inter-Component Communication Patterns
I hope you find this useful and in case if this comes in handy can you please choose this as the best answer so that it can be used by others in the future.
Regards,
Anutej
thank you for your response. The answer you shared is for aura component, but i dont have the knowledge of aura component,, I am trying to learn Lightning WEB components, I want to pass id using web components, can you please share the info for web components.
Thanks
>> https://medium.com/@varma6228/how-to-pass-data-from-one-lwc-component-to-another-lwc-component-lightning-web-component-887f7c928eff
>> https://salesforcediaries.com/2019/07/24/lwc-communication-part-1-passing-data-from-parent-to-child-component/
I hope this helps.
chek this link for How to invoke/call child lightning web component function from parent lightning web component (https://www.salesforcepoint.com/2020/06/how-to-invoke-call-child-lightning-web.html)