0

Created a lightning component to display list of records and would like to open the component in new window to show all the values.

But when opening the component in new tab, the data is not displaying and also there is no error it is just balnk page with View all button, I am able to see console logs for the record id and owner id.

enter image description here

Component: OppListComponent

<aura:component controller="displaylistController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,lightning:isUrlAddressable" access="global">
    <aura:attribute name="mycolumn" type="Object[]"/>
    <aura:attribute name="planRecord" type="Object"/>
    <aura:attribute name="recordLoadError" type="String"/>
    <aura:attribute type="Opportunity[]" name="oppList"/>
    
    <aura:attribute name="recordId" type="Id" />   
    <aura:attribute name="record" type="planRecord__c" />
    <aura:attribute name="viewAllFlag" type="Boolean" default="true"/>
    <aura:attribute name="callInit" type="Boolean" default="false"/>
      <aura:handler name="init" value="{!this}" action="{!c.doinit}"/>
    <lightning:navigation aura:id="navService" />


<force:recordData layoutType="FULL"
                      recordId="{!v.recordId}"
                      targetFields="{!v.record}"
                      recordUpdated="{!c.recordUpdate}" />

    <lightning:datatable data="{!v.oppList }" 
                         columns="{!v.mycolumn }" 
                         keyField="id"
                         hideCheckboxColumn="true"
                          />
    <br/>  
    <aura:if isTrue="{!v.viewAllFlag}">
            <div>
                
                <center><lightning:button label="View All" title="Neutral action" onclick="{!c.loadAll }"/></center>
                
            </div>
    </aura:if>
</aura:component>

Component controller:

({        
   
    recordUpdate: function(component, event, helper) {
        
        helper.getOpportunities(component,event,5);
    },
    
    loadAll : function(component, event, helper) {
        var navService = component.find("navService");
         var pageReference = {
                         "type": "standard__component",
                         "attributes": {
                                         "componentName": "c__OppListComponent" // trying to open same component in new window
                                       },
             state: {
        c__param1: component.get("v.record").Id
      }
                       };
     navService.navigate(pageReference);
     helper.getOpportunities(component,event,100);
             
          }
       
   
 })

helper:

 ({
    getOpportunities : function(component,event,intLimit) {
        component.set('v.mycolumn', [
            
             {label: 'Opportunity Name', fieldName: 'linkName', type: 'url',
             typeAttributes: {label: { fieldName: 'Name' }, target: '_blank'}},
             {label: 'Account Name', fieldName: 'accLink', type: 'url',
             typeAttributes: {label: { fieldName: 'AccountName' }, target: '_blank'}},
             {label: 'Stage', fieldName: 'StageName', type: 'text'},
             {label: 'Close Date', fieldName: 'CloseDate', type: 'text'}

         ]);
        console.log('-->>'+component.get("v.record").OwnerId);
        var action = component.get("c.getOpportunityRecords");
        action.setParams({
            "planOwnerId" : component.get("v.record").OwnerId,
            "intLimit" : intLimit
            
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {

             var rows = response.getReturnValue();
             rows.forEach(function(record){ 
                    if(typeof record.Id != 'undefined'){ 
                        
                        // set the record link with record id  
                        record.linkName = '/'+record.Id;
                        record.accLink = '/'+record.Account.Id; 
                        console.log('Record Link --->>'+record.linkName);  
                    }
            });
            for (var i = 0; i < rows.length; i++) {
                var row = rows[i];
                if (row.Account) row.AccountName = row.Account.Name;
                if (row.Account) row.Tier = row.Account.Tier__c;
            }
             component.set("v.oppList", rows);
            }
           // console.log('==='+response.getReturnValue())
            });
         $A.enqueueAction(action);      
    }
    
})

Apex controller:

public class displaylistController {
    @AuraEnabled
    public static List<Opportunity> getOpportunityRecords(String planOwnerId,Integer intLimit)
   { 
       List<Opportunity> opp;
      
            opp = [select id,Name,Account.Name,StageName,Owner.Name,CloseDate
                                 from Opportunity where OwnerId =:planOwnerId  LIMIT: Integer.valueOf(intLimit)];
       
       
      
        return opp;
    }
}

Your Answer

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

Browse other questions tagged or ask your own question.