+ Start a Discussion
Rima KACIRima KACI 

LWC Passparameters


Hi,
I've created class and method which retrieves List<Account> then it call Visualforce page contains Lightning Web Component.

Is there any way to pass List<Account> from this method to my LWC

Class

public override SearchResult SearchRecords()
    List<Account> accountsCust = SearchClients.searchClientFromCustomerByPhoneMock2(callFolderId);
    if(accountsCust != null && accountsCust.size()>0){  
        result.objectType = 'Url'; 
         Set<String> setIds = new Set<String>();
         setIds.add('https://test.lightning.force.com/apex/SearchClientCustomerByPhoneResultsPage');
        .
        .            
    }
}

Page
<apex:page extensions="SearchClients">
<apex:includeLightning />
<script>
    //Tell your Visualforce page to use your Lightning app
    $Lightning.use("c:SearchClientCustomerByPhoneResultsApp", function() {

        // Write a function that creates the component on the page
        $Lightning.createComponent("c:searchClientCustomerByPhoneResults",
                                   {},
                                   "divid",
                                   function(cmp) {      
                                   })
    });
    </script>
    <body>
        <div id="divid" />
    </body>
</apex:page>


LWC.JS
@track accounts[];
 connectedCallback() {
    this.accounts;
 }
 
 thx for your help

 
Anant KamatAnant Kamat
If you want to pass anything back to Lightning Components, then you need to the annotation @AuraEnabled in your apex controller.
Rima KACIRima KACI
In Class A:
I call webservice to retrieve List of account from externe system 
if list<Account> returned size >0 then I open visualforce page which containes my lightning web component
my LWC execute a method connectedCallback which call an other method in class B this method contains annotation @AuraEnabled
My question is how to pass List<Account> retreived in class A to LWC to display it?
is there any way to pass this list<Account> from class A to page VF then to LWC?
OR pass this List<Account> from class A to class B then it will be called from connectedCallback()?
OR I'am forced to redo the same call webservice from connectedCallback()?

thx for help
Anant KamatAnant Kamat
You need to define an attribute of type = List in the component and then assign the value to this attribute in your controller.js with values from your Apex Controller. This should fix the issue you are facing.