0

I would like to run Lightning component in Visualforce but it keeps failing. Here is a error I keep getting.

This page has an error. You might just need to refresh it. Action failed: c:LightningSharing$controller$doInit [Cannot read property 'state' of null] Failing descriptor: {c:LightningSharing$controller$doInit}

<aura:component controller="LightningSharing" implements="lightning:isUrlAddressable">

    <aura:attribute name="shares" type="object[]" />
    <aura:attribute name="sObjectName" type="String" />
    <aura:attribute name="recordName" type="String" />
    <aura:attribute name="recordId" type="String" />

    <aura:attribute name="searchObject" type="String" default="group"/>
    <aura:attribute name="searchString" type="String" />
    <aura:attribute name="selectedSharee" type="String" />

    <aura:attribute name="results" type="object[]" />
    <aura:attribute name="searchTimeout" type="object" />
    <aura:attribute name="perm" type="string" default="Read/Write"/>

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:handler name="change" value="{!v.pageReference}" action="{!c.doInit}" />

    <aura:registerEvent name="handleCallbackError" type="c:handleCallbackError"/>
    <c:LightningErrorHandler />
    <aura:handler event="c:handleCallbackError" action="{!c.stopProp}" phase="bubble"  />

    <lightning:navigation aura:id="navService" />

    <!--icons at https://www.lightningdesignsystem.com/icons/ -->
    <lightning:card title="{!v.sObjectName + ' : ' + v.recordName}" variant="base">
        <aura:set attribute="actions">
            <lightning:button onclick="{!c.navToRecord}"  label="{!$Label.c.Back}" title="{!'Return to ' + v.recordName}" />
        </aura:set>
        <aura:set attribute="footer">
            <!--footer markup-->
        </aura:set>
        <div class="slds-p-horizontal_medium">
            <lightning:tabset>
                <lightning:tab>
                    <aura:set attribute="label">{!$Label.c.ViewCurrentPermissions}</aura:set>
                    <div class="sls-p-around--medium">
                        <table class="slds-table slds-table_bordered slds-no-row-hover slds-table_cell-buffer">
                            <thead>
                                <tr>
                                    <th class="slds-text-heading_label" scope="col">
                                        <div class="slds-truncate">{!$Label.c.UserOrGroup}</div>
                                    </th>
                                    <th class="slds-text-heading_label" scope="col">
                                        <div class="slds-truncate">{!$Label.c.Type}</div>
                                    </th>
                                    <th class="slds-text-heading_label" scope="col">
                                        <div class="slds-truncate">{!$Label.c.Name}</div>
                                    </th>
                                    <th class="slds-text-heading_label" scope="col">
                                        <div class="slds-truncate">{!$Label.c.AccessLevel}</div>
                                    </th>
                                    <th class="slds-text-heading_label" scope="col">
                                        <div class="slds-truncate">{!$Label.c.Reason}</div>
                                    </th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                <aura:iteration items="{!v.shares}" var="share">
                                    <tr class="slds-hint-parent">

                                        <td data-label="{!$Label.c.UserOrGroup}">{!share.UserOrGroupType}</td>
                                        <td data-label="{!$Label.c.Type}">{!share.SubType}</td>
                                        <td data-label="{!$Label.c.Name}">
                                            <a onclick="{!c.navToUser}" id="{!share.UserOrGroupID}">
                                                {!share.UserOrGroupName}
                                            </a>
                                        </td>
                                        <td data-label="Access Level">
                                            {!share.AccessLevel}

                                        </td>
                                        <td data-label="{!$Label.c.Reason}">{!share.RowCause}</td>
                                        <td>
                                            <aura:if isTrue="{!share.RowCause=='Manual'}">
                                                <a onclick="{!c.setRead}" id="{!share.UserOrGroupID}" class="slds-button slds-button_neutral">
                                                    {!$Label.c.Read}
                                                </a>
                                                <a onclick="{!c.setReadWrite}" id="{!share.UserOrGroupID}" class="slds-button slds-button_neutral">
                                                    {!$Label.c.ReadWrite}
                                                </a>
                                                <a onclick="{!c.delete}" id="{!share.UserOrGroupID}" class="slds-button slds-button_neutral">
                                                    {!$Label.c.Delete}
                                                </a>
                                            </aura:if>
                                        </td>
                                    </tr>
                                </aura:iteration>
                            </tbody>
                        </table>
                    </div>
                </lightning:tab>
                <lightning:tab>
                    <aura:set attribute="label">{!$Label.c.AddNewPermission}</aura:set>

                    <lightning:layout class="slds-box slds-theme_shade">
                        <lightning:layoutItem padding="around-small" flexibility="grow">
                            <lightning:select aura:id="searchPicklist" name="select1" label="{!$Label.c.Search}" value="{!v.searchObject}">
                                <option value="group">{!$Label.c.PublicGroups}</option>
                                <option value="userrole">{!$Label.c.Roles}</option>
                                <option value="user">{!$Label.c.Users}</option>
                            </lightning:select>
                        </lightning:layoutItem>

                        <lightning:layoutItem padding="around-small" flexibility="grow">
                            <lightning:input aura:id="search" name="for" value="{!v.searchString}" label="For" type="search" onchange="{!c.search}" placeholder="{!$Label.c.Type3}"
                            />
                            <aura:if isTrue="{!v.results.length >= 199 }">
                                {!$Label.c.TooManyResultsMessage}
                            </aura:if>
                        </lightning:layoutItem>
                    </lightning:layout>


                    <aura:if isTrue="{!v.results.length > 0}">

                        <table class="slds-table slds-table_bordered slds-no-row-hover slds-table_cell-buffer slds-m-top_large">
                            <thead>
                                <tr>
                                    <th class="slds-text-heading_label" scope="col">
                                        <div class="slds-truncate">{!$Label.c.Name}</div>
                                    </th>
                                    <th class="slds-text-heading_label" scope="col">
                                        <div class="slds-truncate">{!$Label.c.SetAccessLevel}</div>
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <aura:iteration items="{!v.results}" var="result">
                                    <tr class="slds-hint-parent">

                                        <td data-label="{!$Label.c.Name}">{!result.Name}
                                            <aura:if isTrue="{!result.Type}">
                                                ({!result.Type})
                                            </aura:if>
                                        </td>
                                        <td data-label="{!$Label.c.AccessLevel}">
                                            <a onclick="{!c.setRead}" id="{!result.Id}" class="slds-button slds-button_neutral">
                                                {!$Label.c.Read}
                                            </a>
                                            <a onclick="{!c.setReadWrite}" id="{!result.Id}" class="slds-button slds-button_neutral">
                                                {!$Label.c.ReadWrite}
                                            </a>
                                        </td>
                                    </tr>
                                </aura:iteration>
                            </tbody>
                        </table>
                    </aura:if>

                </lightning:tab>


            </lightning:tabset>
        </div>
    </lightning:card>



</aura:component>

My app:

<aura:application access="GLOBAL" extends="ltng:outApp"> 
    <aura:dependency resource="c:LightningSharing"/>
</aura:application>

My VF Page:

<apex:page standardStylesheets="false" showHeader="false" sidebar="false">

    <apex:includeLightning />
    <div id="lightning" />

    <script>
        $Lightning.use("c:360LightningSharing", function() {
          $Lightning.createComponent(
            "c:LightningSharing",
            {},
            "lightning",
            function(cmp) {
        component.set("v.recordId" , 'a021U000002ahgzQAA');

            });
        });
    </script>

</apex:page>

If it helps, I`m trying to run this lightning component in VF - https://github.com/mshanemc/LightningSharing

1 Answer 1

0

You probably want to check if pageRef is actually returning something, in the doInit method (when the lightnig component initializes) ensure that the proper values are being popualted.

As is, it doesnt look like they are. Are you sure this component is supported in Visualforce?

you should probably check with the person who created this repository under the issues section

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .