0

I am currently using LCC npm module (Lightning Container) to make Apex calls in our React app.

However, we are also exploring cutting out LCC altogether (the concern is that it has not been updated in 4 years), as our app is currently in a lighting web component iframe wrapped in an aura parent div. Since aura components can speak directly to apex, I am using a callback to get the actual data I need from Apex. However, the data does not update on the static resource. Is there a way to do this?

//.cmp

<aura:component controller="ContactController" implements="force:hasRecordId,flexipage:availableForAllPageTypes" access="global" >
    <aura:attribute name="recordId" type="String" />
    <aura:handler name="init" value="{!this }" action="{!c.doInit }"/>
    <lightning:container src="{!$Resource.demo_salesforce_hello + '/index.html?recordid=' + v.recordId}" onerror="{!c.handleError}"/>
</aura:component>

//.js

doInit : function(component, event, helper) {
    //var recordId = component.get('v.recordId');
    var action = component.get("c.serverEcho");
    action.setParams({recordId : component.get('v.recordId') });
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            console.log("From server: " + JSON.stringify(response.getReturnValue()));
            component.set("v.recordId", JSON.stringify(response.getReturnValue()));               
        }
        else if (state === "INCOMPLETE") {
            // do something
        }
        else if (state === "ERROR") {
            var errors = response.getError();
            if (errors) {
                if (errors[0] && errors[0].message) {
                    console.log("Error message: " + 
                                errors[0].message);
                }
            } else {
                console.log("Unknown error");
            }
        }
    });
    $A.enqueueAction(action);
}

//apex

@AuraEnabled(cacheable=true)
public static Contact[] serverEcho(String recordId) {
    String contactId = [SELECT ContactId FROM Case WHERE Id= :recordId].ContactId;
    System.debug([SELECT Id, Name, LOB__c, PlanName__c FROM Contact WHERE Id= :contactId]);
    return [SELECT Id, Name, LOB__c, PlanName__c FROM Contact WHERE Id= :contactId];
}

1 Answer 1

0

You use the message function:

<lightning:container aura:id="container" src="{!$Resource.demo_salesforce_hello + '/index.html?recordid=' + v.recordId}" onerror="{!c.handleError}"/>

...

component.find("container").message(JSON.stringify(response.getReturnValue()));

This is outlined in the documentation.

1
  • Thank you! I am now calling: LCC.addMessageHandler(function (message) { console.log("MESSAGE", message);}); But I get VFRemote.js:117 Visualforce Remoting: Context incomplete - authorization not provided
    – Nour
    Nov 16, 2021 at 4:22

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.