+ Start a Discussion
TheLearnerTheLearner 

Getting error while selecting the record" attempt to dereference null object"

Hi Experts,

Im getting error , while creating the record, there is text box called street , in that if i give some four number it will give you street number , when i was trying to give its throwing error called" attempt to de reference a null object". could you anyone solve it please.

vf page: 


<apex:page standardController="WPD_Reinstatement__c" id="page"> <script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script> <script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script> <script type="text/javascript"> <!--CH07 --> window.onload = function(e){ var notifType = document.getElementById('page:FrmWork:Pb1:Pb2:NotificationType'); var text = notifType.options[notifType.selectedIndex].text showPermitCondition(text); } function showPermitCondition(notificationType){ var panel = document.getElementById('conditionalPanel'); if(notificationType == 'Permit'){ panel.style.display =''; } else{ panel.style.display = 'none'; } } <!--CH07 --> function openpopup() { var URL; var usrn, street,locality,town,county,roadclass; usrn = document.getElementById('page:FrmWork:Pb1:Pb2:USRN1').value; street = document.getElementById('page:FrmWork:Pb1:Pb2:street1').value; locality = document.getElementById('page:FrmWork:Pb1:Pb2:locality1').value; town = document.getElementById('page:FrmWork:Pb1:Pb2:town1').value; county = document.getElementById('page:FrmWork:Pb1:Pb2:county1').value; eastStart = document.getElementById('page:FrmWork:Pb1:Pb3:ES').value; eastEnd = document.getElementById('page:FrmWork:Pb1:Pb3:EE').value; northStart = document.getElementById('page:FrmWork:Pb1:Pb3:NS').value; northEnd = document.getElementById('page:FrmWork:Pb1:Pb3:NE').value; //roadclass = document.getElementById('apexPage:frmSch4:pb:pbs:section29:tabIndex18').value; if(usrn=='' && street=='' && locality==''&& town==''&& county=='') { URL = '{!URLFOR($Page.Wpd_Gazetteer_Search)}'; } else { URL = '{!URLFOR($Page.Wpd_Gazetteer_Search)}' + '?U=' + usrn + '&S=' + street + '&L=' + locality + '&T=' + town + '&C=' + county + '&E=' + eastStart +'&Es=' + eastEnd + '&Ee=' + northStart +'&Em=' + northEnd ; } var GazSearchWin= window.open(URL,'GSearch','height=500,width=800,status=no,scrollbars=yes,resizable=yes'); GazSearchWin.opener = self; //GazSearchWin.focus(); return false; } function timeValidation(){ //Time Fault Received // var tmRec = document.getElementById('j_id0:FrmWork:Pb1:Pb2:j_id41').value; //CH06 var tmRec = document.getElementById('page:FrmWork:Pb1:Pb2:TimeFaultReceived').value; var valueArr = tmRec.split('.'); var vmnt=valueArr[1]; if(vmnt<10 && vmnt.length<2) vmnt=vmnt+'0'; if(valueArr[0]>23){ alert('Time Fault Received: Hour value can not be greater than 23'); return false; } if(vmnt>59){ alert('Time Fault Received: Minute value can not be greater than 59'); return false; } //Time of Arrival on Fault // var tmRec1 = document.getElementById('j_id0:FrmWork:Pb1:Pb2:j_id43').value; CH06 var tmRec1 = document.getElementById('page:FrmWork:Pb1:Pb2:Timeofarrival').value; var valueArr1 = tmRec1.split('.'); var vmnt1=valueArr1[1]; if(vmnt1<10 && vmnt1.length<2) vmnt1=vmnt1+'0'; if(valueArr1[0]>23){ alert('Time of Arrival on Fault: Hour value can not be greater than 23'); return false; } if(vmnt1>59){ alert('Time of Arrival on Fault: Minute value can not be greater than 59'); return false; } return true; } </script> <apex:sectionHeader title="WPD Work" subtitle="Edit WPD Work"/> <!-- CH08 --> <apex:form id="FrmWork"> <input type="hidden" id="USRN" name="USRN" value = "page:FrmWork:Pb1:Pb2:USRN1"/> <input type="hidden" id="Street" name="Street" value = "page:FrmWork:Pb1:Pb2:street1"/> <input type="hidden" id="Locality" name="Locality" value = "page:FrmWork:Pb1:Pb2:locality1"/> <input type="hidden" id="Town" name="Town" value = "page:FrmWork:Pb1:Pb2:town1"/> <input type="hidden" id="County" name="County" value = "page:FrmWork:Pb1:Pb2:county1"/> <input type="hidden" id="eastStart" name="eastStart" value = "page:FrmWork:Pb1:Pb3:ES"/> <input type="hidden" id="eastEnd" name="eastEnd" value = "page:FrmWork:Pb1:Pb3:EE"/> <input type="hidden" id="northStart" name="northStart" value = "page:FrmWork:Pb1:Pb3:NS"/> <input type="hidden" id="northEnd" name="northEnd" value = "page:FrmWork:Pb1:Pb3:NE"/> <input type="hidden" id="roadclass" name="RoadClass" value = "page:FrmWork:Pb1:Pb2:roadclass"/> <apex:pageBlock id="Pb1" title="WPD Work"> <apex:pageMessages id="pgMsg"></apex:pageMessages> <!--CH08.Start --> <apex:panelgrid columns="3" cellpadding="10" > <apex:outputLabel ><b>Search for Street / Town / Location </b> </apex:outputLabel> <apex:inputText style="height:19px" size="60" id="gazSearch"> <c:gazetteerAutoComplete autocomplete_textbox="{!$Component.gazSearch}" localityTxtBoxId="page:FrmWork:Pb1:Pb2:locality1" streetTxtBoxId="page:FrmWork:Pb1:Pb2:street1" townTxtBoxId="page:FrmWork:Pb1:Pb2:town1" usrnTxtBoxId="page:FrmWork:Pb1:Pb2:USRN1" countyTxtBoxId="page:FrmWork:Pb1:Pb2:county1" roadClassTxtBoxId="page:FrmWork:Pb1:Pb2:roadclass" e1TxtBoxId="page:FrmWork:Pb1:Pb3:ES" n1TxtBoxId="page:FrmWork:Pb1:Pb3:NS" e2TxtBoxId="page:FrmWork:Pb1:Pb3:EE" n2TxtBoxId="page:FrmWork:Pb1:Pb3:NE" /> </apex:inputText> <apex:commandButton style="height:25px" onclick="opendetails();return false;" value="Street Details" /> </apex:panelgrid> <!--CH08.End --> <apex:pageBlockSection title="Status"> <apex:inputField value="{!WPD_Reinstatement__c.Work_Status__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Status__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Original_Notice__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Cancelled__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.WPD_Projects__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Abandoned__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.In_Progress_Report__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Abandoned_Reason__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Closure_Report__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.WPD_Work_Type__c}" required="true" /> <!-- CH12 --> <apex:inputHidden id="hdnIsWPDWorkClone" value="{!WPD_Reinstatement__c.WPD_Work_Clone__c}"/> <!-- CH12--> <apex:inputField value="{!WPD_Reinstatement__c.MRS_Certified_ValueFormula__c}" /> <!-- CH05 --> </apex:pageBlockSection> <apex:pageBlockSection title="Description" id="Pb2"> <apex:inputField value="{!WPD_Reinstatement__c.Works_Description__c}" required="true" /> <apex:inputField value="{!WPD_Reinstatement__c.Notice_Number__c}" required="true"/> <apex:inputField id="TimeFaultReceived" value="{!WPD_Reinstatement__c.Time_Fault_Received__c}" required="false"/> <!-- CH02.New & CH06(id added) --> <apex:inputField value="{!WPD_Reinstatement__c.Notice_Type__c}" required="true" /> <apex:inputField id="Timeofarrival" value="{!WPD_Reinstatement__c.Time_of_Arrival_on_Fault__c}" required="false"/> <!-- CH02.New & CH06(Id Added) --> <apex:inputField id="NotificationType" value="{!WPD_Reinstatement__c.Notification_Type__c}" required="true" onchange="showPermitCondition(this.value)"/> <!-- CH07 # SR_ISIS_WPD_066 --> <apex:outputText ></apex:outputText><!--CH11 ##--> <apex:inputField value="{!WPD_Reinstatement__c.Excavation__c}"/> <!--CH11 ##--> <apex:inputField value="{!WPD_Reinstatement__c.Location__c}" required="true"/> <!--CH.03 Start - Rearrange the fields after new field added in layout--> <apex:inputField id="USRN1" value="{!WPD_Reinstatement__c.USRN__c}" /> <!-- CH04 # SR_ISIS_WPD_051 --> <apex:inputField id="street1" value="{!WPD_Reinstatement__c.Street__c}" required="true"/> <apex:inputField value="{!WPD_Reinstatement__c.Granted_Permit_Number__c}" /> <!-- CH04 # SR_ISIS_WPD_051 --> <apex:inputField id="locality1" value="{!WPD_Reinstatement__c.Locality__c}" /> <apex:inputField id="roadclass" value="{!WPD_Reinstatement__c.Road_Class__c}" /> <apex:inputField id="town1" value="{!WPD_Reinstatement__c.Town__c}" required="true"/> <apex:inputField value="{!WPD_Reinstatement__c.Traffic_Sensitive__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Post_Code__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Traffic_lights_on_site__c}" /> <!--CH.01 Start --> <!--<apex:inputField id="roadclass" value="{!WPD_Reinstatement__c.Road_Class_Text__c}" />--> <!--CH.01 End --> <apex:inputField id="county1" value="{!WPD_Reinstatement__c.County__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Spoil_on_site__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Barriers_on_site__c}" /> <!--CH.03 End --> </apex:pageBlockSection> <apex:pageBlockSection title="Grid References" id="Pb3"> <apex:inputField id="ES" value="{!WPD_Reinstatement__c.Eastings_Start__c}" required="true" /> <apex:inputField id="EE" value="{!WPD_Reinstatement__c.Eastings_End__c}" required="true"/> <apex:inputField id="NS" value="{!WPD_Reinstatement__c.Northings_Start__c}" required="true"/> <apex:inputField id="NE" value="{!WPD_Reinstatement__c.Northings_End__c}" required="true"/> </apex:pageBlockSection> <apex:pageBlockSection title="Early Start Information" id="Pb5"> <apex:inputField value="{!WPD_Reinstatement__c.HA_Contact_Name__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Reason__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Agreement_DateTime__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Pin_No__c}" /> </apex:pageBlockSection> <apex:pageBlockSection title="Works Details" id="Pb4"> <apex:inputField value="{!WPD_Reinstatement__c.Estimated_Start__c}" required="true" /> <apex:inputField value="{!WPD_Reinstatement__c.Estimated_End__c}" required="true"/> <apex:inputField value="{!WPD_Reinstatement__c.Works_Start_Date__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Works_End_Date__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Actual_Start__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Date_to_Reinstators__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Actual_Start_Time__c}" /> <!-- CH09 --> <apex:inputField value="{!WPD_Reinstatement__c.Team_Allocated__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Notice_Close__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Planned_Joint_Date__c}" required="true"/> <!-- CH13.Starts --> <apex:inputField value="{!WPD_Reinstatement__c.Part_Reg__c}" /> <!-- CH13.Ends --> <apex:inputField value="{!WPD_Reinstatement__c.Actual_Joint_Date__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Registration__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Jointing_Ref__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Site_Clear__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Comments__c}" /> </apex:pageBlockSection> <!-- CH07 Starts --> <div id="conditionalPanel" style="display:none;"> <apex:pageBlockSection title="WPD Permit Conditions" id="pbPC"> <apex:inputField value="{!WPD_Reinstatement__c.Time_Constraints__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Date_Constraints__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Out_Of_Hours_Work__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Material_And_Plant_Storage__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Road_Occupation_Dimensions__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Traffic_Space_Dimensions__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Road_Closure__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Light_Signals_And_Shuttle_Working__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Traffic_Management_Changes__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Work_Methodology__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Consultation_And_Publicity__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Environmental__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Local__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.No_Conditions_Supplied__c}" /> <apex:inputField value="{!WPD_Reinstatement__c.Condition_Text__c}" /> </apex:pageBlockSection> </div> <!-- CH07 Ends --> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save" onclick="return timeValidation()"/> <!-- CH02.Edit --> <apex:commandButton action="{!cancel}" value="Cancel" /> <!-- <apex:commandButton value="Street Gazetteer" id="tabIndex36" onclick="return openpopup()" rendered="{!IF($Profile.Name=='WPD Sub Reinstator',false,true)}"/> --> <!-- CH08 --> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> <script type="text/javascript"> // CH12 Starts if(document.getElementById('page:FrmWork:Pb1:j_id38:hdnIsWPDWorkClone').value == 'true'){ document.getElementById('page:FrmWork:Pb1:j_id38:j_id48').disabled = true; } // CH12 Ends </script> </apex:page>

class: 

global class gazetteerAutoComplete
{
   /**
   findStreets(String searchText) -  This is a REMOTEACTION method that it called directly from the Page through javascript
                                     It fetches a combination of street,town,locality and county based on the search text.
   **/
   @RemoteAction
   global static String[] findStreets(String searchText)
   {
       return returnResults(callService(searchText));
   }
   //CH01.Start
   /**
   returnResults(Gazetteer_DotNet_Services.GazetteerSearchResults  webServiceResponse)
   This method accepts the result set as an argument and returns the same on the page for selection by the user
   **/
   
   public static List<String> returnResults(Gazetteer_DotNet_Services.GazetteerSearchResults  webServiceResponse)
   {
       List<String> lstStreetNames = new List<String>();
       Gazetteer_DotNet_Services.GazetteerSearchResult[] resultSet;
       resultSet = webServiceResponse.GazetteerSearchResultsRow.GazetteerSearchResult;
       if(resultSet!=null)
           for (Gazetteer_DotNet_Services.GazetteerSearchResult resultRow: resultSet)
               lstStreetNames.add(resultRow.StreetDescriptor);
       return lstStreetNames;
   }
   /**
   callService(String searchText) -  This method calls the webservice with the search text as an argument. The webservice is 
   hosted by a CAST IRON server which in turns calls a Stored Procedure to fetch the results from the GAZETTEER DATABASE
   **/
   public static Gazetteer_DotNet_Services.GazetteerSearchResults callService(String searchText)
   {
       try
       {
           //Validates the ORG ID as well
           //return new gazetteerDataWSDL.GazetteerSearchPort().GazetteerSearch(searchText,UserInfo.getOrganizationId().substring(0,15));
           //Hard coded the organization id as CSB refresed, and once paul come from holidy need to update in CastIron
           //return new gazetteerDataWSDL.GazetteerSearchPort().GazetteerSearch(searchText,UserInfo.getOrganizationId().substring(0,15));  
           
           String samp = System.Label.Organization_ID; 
           return new Gazetteer_DotNet_Services.GazetterSoap().GazetteerSearch(searchText, samp);   
       
       }
       catch(Exception ex)
       {
           return new Gazetteer_DotNet_Services.GazetteerSearchResults();
       }
       //CH01.End
   }
}
 
Suraj GharatSuraj Gharat
The error message for this kind of exceptions also bears code line number that caused the error. Please share the complete message.
TheLearnerTheLearner
hi this is the error;


The page https://c.cs7.visual.force.com says: (url is: https://c.cs7.visual.force.com/apex/WPD_Work_Override?retURL=%2Fa6U%2Fo&save_new=1&sfdc.override=1, when i oopen to create record this is the url)

Attempt to de reference a null object.

this is the error, there is no controller for that page, but some where they written this apex class name which i shared above could you tell me