0

I'm adding a lightning out component to a pre-existing visualforce page. I can pass the values from the sObject bound in the Visualforce page to my Lightning Component by passing these as separate parameters (one for each required field) to associated attributes in my lightning component however I'd like to pass just one attribute and reference this for picking up the fields in my component.

On testing this out this afternoon I've been unable to get this to work.

My Lightning Out VF page is as follows

<apex:page standardController=“Impact__c” showChat="false" tabStyle="case" >
    <apex:includeLightning />
    <div id=“Incident”/> 
    <script>
        $Lightning.use("c:SM_ProblemIncidentChange", function() {
          $Lightning.createComponent("c:SM_ProblemIncident",
            {incidentRecord: "{!Impact__c.Incident__r}"},
          “Incident”,
          function(cmp) {
          });
        });        
     </script>
</apex:page>

If I pass Incident__r or Incident__c I just get the id of the associated incident record in my component as opposed to a full sObject reference, or I'm not accessing these correctly in the component. if I do the following I can pass individual fields.

<apex:page standardController=“Impact__c” showChat="false" tabStyle="case" >
    <apex:includeLightning />
    <div id=“Incident”/> 
    <script>
        $Lightning.use("c:SM_ProblemIncidentChange", function() {
          $Lightning.createComponent("c:SM_ProblemIncident",
            {incidentId: "{!Impact__c.Incident__r}”,
         caseNumber: "{!Impact__c.Incident__r.CaseNumber}”},
          “Incident”,
          function(cmp) {
          });
        });        
     </script>
</apex:page>

Should I be able to pass the full sObject? Is seems the most logical approach instead of individual fields.

Lightning Data Service is not supported on Lightning Out.

Thanks in advance for any tips on this.

3
  • Is your Visualforce page using a standard controller? – dsharrison Nov 7 '17 at 19:36
  • You could pass in a full sobject, but it needs to be formatted the way Lightning expects, with an sobjectType parameter, and you'd have to explicitly pull in all the fields you want. It's arguably easier to just query it directly in the component as in the answer. – sfdcfox Nov 8 '17 at 2:32
  • Hi To pass in the full sObject is jSON the only approach for this? Thanks. – RedQueries Nov 8 '17 at 15:27
0

While it is true that LDS is not available for Lightning Out I think your best bet in this situation would be to retrieve the object's data within the component.

You get the Id from the page, but the component calls the database to retrieve the record with the specified Id.

Of course, you should be able to pass the full sObject if you format it as a JSON in the component's loader, but I think this approach is a little annoying to maintain if you need to change/add/remove the object's fields (because then you'll have to edit not only your component but also the JSON manually).

2
  • Hi dsharrison, sfdcfox, Renata, Thanks for your replies. A standard controller exists indeed in the Visualforce page. I was thinking as a standard controller is already used it would be good to not have to re-query for the fields again. I had created an attribute of type <aura:attribute name="incidentRecord" type="Case" /> in my component. For formatting the sObject to a correct type supported for passing to an sObject attribute JSON has been mentioned above. Is JSON the only/correct process for this? Thanks again! – RedQueries Nov 8 '17 at 9:35
  • @FRed The only way to pass the object from the page to the component is through JavaScript. So you either need to retrieve the object on the page's controller, then serialize it as JSON and pass it to the component, or you pass the Id to the component and retrieve the object from there. As far as I know, this is the only way of doing this (and I did this myself in a customer's org, so I can assure you that it works just fine). – Renato Oliveira Nov 8 '17 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.