function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
enossirenossir 

Lightning component to VF page error "Attempt to de-reference a null object "

So i'm dealing with a classic to lightning converision and have a object that has a related object in which there is a list buttton that when clicked in lightning doesn't work.
 
/apex/New_Blue?id={!Account.Id}



So since i can't do a quick action to VF page (crazy amounts of redesign)

I'm doing a quick actions ---> component ---> VF page
 
<aura:component controller="New_Blue_ctl" implements="force:appHostable,force:lightningQuickActionWithoutHeader,flexipage:availableForAllPageTypes,force:hasRecordId" access="global" >
	  <aura:handler name="init" value="{!this}" action="{!c.newBlue}"/>
</aura:component>

I use no header....because i don't want a header, i just want the Javascript to execute pass the record and start the VF page that's it nothing more.
 
({
	newBlue : function(component, event, helper) {
		    var urlEvent = $A.get("e.force:navigateToURL");
        	var recordId = component.get("v.recordId");
   			
   			
                urlEvent.setParams({
          "url": "/apex/New_Blue?id=" + recordId, 
            "isredirect": "true"
        });
        urlEvent.fire();
	}
})

Now here's the issue is when i click on the quick action 


Attempt to de-reference a null object 
Raj VakatiRaj Vakati
How are you testing this app ?? If you are testing this app with .app contains force:navigateToURL will not wokr . 

 
enossirenossir
I made it into a quick action on the account page and i click the quick action button.
enossirenossir
also i removed force:appHostable don't know why i had that in there.
Raj VakatiRaj Vakati
Can you see what is the value its printing on the console logs 
 
({
	newBlue : function(component, event, helper) {
		    var urlEvent = $A.get("e.force:navigateToURL");
        	var recordId = component.get("v.recordId");
   			console.log('recordId '+recordId);
   			
                urlEvent.setParams({
          "url": "/apex/New_Blue?id=" + recordId, 
            "isredirect": "true"
        });
        urlEvent.fire();
	}
})

 
enossirenossir
@Raj Vakati

It gives me the record id as it should.
Raj VakatiRaj Vakati
Can you check debug logs to see why its failing ?? for me the code what ever you shared is looks good 
enossirenossir
I think it might be the URL for some reason.

Maybe i need to use "<domianName>--test.lightning.force.com/apex/New_Blue?id=" instead of "/apex/New_Blue?id=" Or possibly use the classic url?

It gives me "attempt to de-referene a null object." in the dev console it says line 63 of the apex class related to the VF page has failed, specifically  

sot = parentId.getSObjectType();

where sot is  private SObjectType sot {get; set;}
public New_Blue) {
        // figure out from which object (Acct or Opp) we are creating the new Service record:
        parentId = ApexPages.currentPage().getParameters().get('pId');
        sot = parentId.getSObjectType();
        if(sot == Opportunity.sObjectType) {
            isOpp = true;
            // Get opp data for defaulting the new Service fields:
        // T-1642 Added CloseDate & Install Date to SOQL:
         //Separation Begin
            opp = [select Id, Name, AccountId, Account.Name, Marketing_Campaign__c, Marketing_Campaign__r.Name, CloseDate, Install_Date__c
                   from Opportunity where ID = :parentId AND  RecordTypeID NOT IN :CommonObjectRecordTypeUtil.opportunityRecordTypeList];
         //Separation End
            forObject = 'Opportunity';
            forName = opp.Name;
            oppId = opp.Id;
            oppName = opp.Name;
        // T-1642 Begin
            oppCRDD = opp.Install_Date__c;
            oppCloseDate = opp.CloseDate;
        // T-1642 End
            acctId = opp.AccountId;
            acctName = opp.Account.Name;
            campName = '';
            if(opp.Marketing_Campaign__c != null) {
                campId = opp.Marketing_Campaign__c;
                campName = opp.Marketing_Campaign__r.Name;
            }

 
enossirenossir
Also private ID parentId {get; set;}    But it should be able to see the parent Id since i'm passing it to the VF page......could it be parentId = ApexPages.currentPage().getParameters().get('pId'); causing the issue.