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
Ian QuahIan Quah 

Transitioning (passing variables) between two separate Lightning Resources

Say I have two separate lightning resources: A, and B.

How would I pass variables between the two? If, for example, in page A I get all the individuals for whom I can generate profiles (example: word docs) how do I then pass that list of people eligible for profile generation to B, where I can then iterate through the values to generate them?

Or is there an elegant solution to the problem that I didn't see?
Best Answer chosen by Ian Quah
Nithesh NNithesh N
What @Ashish meant by Child Component is, regarding the structure. You should take the approach based on the structure of the component. 

So, How are A and B connected to each other.

Is B nested within the A component? (Parent-Child Components)
+--------------------------+
|     A                    |
|                          |
| +----------------------+ |
| |  B                   | |
| |                      | |
| |                      | |
| |                      | |
| +----------------------+ |
|                          |
+--------------------------+
Here B is  a Child component, You can either send Values from A to B using Events (Component Events) or by Using Attributes (easiest method) or using methods.
Read the detailed Blog post here (https://developer.salesforce.com/blogs/developer-relations/2017/04/lightning-inter-component-communication-patterns.html). You can find lot of examples in this post.

Are A and B are saperate components? (Sibling Components)
+--------------------------+   +--------------------------+
|     A                    |   |    B                     |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
+--------------------------+   +--------------------------+

Then you need to use Application events. 

So, to know how to use and impliment the methods i mentioned above. Refer this blog post (https://developer.salesforce.com/blogs/developer-relations/2017/04/lightning-inter-component-communication-patterns.html)( It has code samples too).

To know more about Events..Refer the official documentation here (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_intro.htm). 

Let me know if you need anything else. Good Luck.


Best,
Nithesh

All Answers

Ashish KumarAshish Kumar
By Lightning Resources do you mean lightning components?
If yes, you can create an event and pass the values/list of individuals from A and then can handle the event in component B.
Or if B is child component of A then you can pass the values as the attributes to component B.
Let me know if you need any further help.

Regards,
Ashish Kr.
Ian QuahIan Quah
Yes I do mean components! Can you suggest any resources to read up what I need to do it as both "create an event and pass the values to B" and using the "child component"? I tried googling but I guess mysearxh terms weren't useful enough for google to point me in the right direction. if possible I would also like to include a button in B such that the user can go back and generate a different list in A. P.s off the top of your head what are the advantages and disadvantages of each of the methods you mentioned? "Create an event" vs "child component"? Thank you so much for your time!
Nithesh NNithesh N
What @Ashish meant by Child Component is, regarding the structure. You should take the approach based on the structure of the component. 

So, How are A and B connected to each other.

Is B nested within the A component? (Parent-Child Components)
+--------------------------+
|     A                    |
|                          |
| +----------------------+ |
| |  B                   | |
| |                      | |
| |                      | |
| |                      | |
| +----------------------+ |
|                          |
+--------------------------+
Here B is  a Child component, You can either send Values from A to B using Events (Component Events) or by Using Attributes (easiest method) or using methods.
Read the detailed Blog post here (https://developer.salesforce.com/blogs/developer-relations/2017/04/lightning-inter-component-communication-patterns.html). You can find lot of examples in this post.

Are A and B are saperate components? (Sibling Components)
+--------------------------+   +--------------------------+
|     A                    |   |    B                     |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
|                          |   |                          |
+--------------------------+   +--------------------------+

Then you need to use Application events. 

So, to know how to use and impliment the methods i mentioned above. Refer this blog post (https://developer.salesforce.com/blogs/developer-relations/2017/04/lightning-inter-component-communication-patterns.html)( It has code samples too).

To know more about Events..Refer the official documentation here (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_intro.htm). 

Let me know if you need anything else. Good Luck.


Best,
Nithesh
This was selected as the best answer
Ian QuahIan Quah
So I actually ended up using navigatetocomponent :) It allows me to pass in a variable and since I'm only passing two variables in it's not too difficult. Thanksfor the help though! It was an interesting read
Nithesh NNithesh N
I am happy that you found a solution, But isn't navigatetocomponent still in beta ? Are you fine with useing a beta feature? 
(thanks for rewarding me with Best Answer!!)

Best,
Nithesh
David Roberts 4David Roberts 4
I've been attempting to use navigateToComponent and using a wrapper class to collect what I need to pass between components. That all works fine but I find that, when I press the button, it launches an old version of the sibling component.
I may have to try application events...