You need to sign in to do that
Don't have an account?
Sahaj
Attempt to de-reference a null object,Error is in expression
Hi
Please help me with Attempt to de-reference a null object,how can i resolve this issue
Error is in expression '{!doGeneration}' in page updateincidentremelaptime: Class.GenerateRemainingElapsedTime.doGeneration: line 63, column 1
Below is the sample code(controller) and VF page
Please help me with this. :)
Please help me with Attempt to de-reference a null object,how can i resolve this issue
Error is in expression '{!doGeneration}' in page updateincidentremelaptime: Class.GenerateRemainingElapsedTime.doGeneration: line 63, column 1
Below is the sample code(controller) and VF page
Public Class GenerateRemainingElapsedTime{ public List<BMCServiceDesk__Incident_Service_Target__c> listIncidentServiceTarget{get;set;} public Boolean IsGenerated{get;set;} Public GenerateRemainingElapsedTime(){ IsGenerated=false; listIncidentServiceTarget= [SELECT Id, BMCServiceDesk__FKIncident__r.Owner_new__c, BMCServiceDesk__FKIncident__r.Summary__c, Name, BMCServiceDesk__ElapsedTime__c, BMCServiceDesk__FKIncident__r.PendingStartTime__c, BMCServiceDesk__FKIncident__r.PendingDuration__c, BMCServiceDesk__TimeRemaining__c, BMCServiceDesk__StateValue__c, BMCServiceDesk__StartDate__c, BMCServiceDesk__Support_Hour_Applied__c, BMCServiceDesk__PausedDuration__c, BMCServiceDesk__TargetEndDate__c, BMCServiceDesk__FKIncident__r.Status_picklist__c ,BMCServiceDesk__FKIncident__r.Name, BMCServiceDesk__FKIncident__c FROM BMCServiceDesk__Incident_Service_Target__c WHERE BMCServiceDesk__TargetType__c ='ResolutionTime' AND BMCServiceDesk__IsCanceled__c = false AND BMCServiceDesk__StateValue__c <> 'Canceled' AND BMCServiceDesk__FKIncident__r.Status_picklist__c IN ('Assigned','In Progress', 'Pending') AND createddate > 2015-10-29T00:00:00.000Z]; System.Debug('####Controller-listIncidentServiceTarget: '+listIncidentServiceTarget); } //Format Date As String Public String formatMS(Long timeInMilliSeconds){ Long seconds = timeInMilliSeconds / 1000; Long minutes = seconds / 60; Long hours = minutes / 60; Long days = hours / 24; String timeF = days + ' day(s) ' + AppendZero(Math.mod(hours,24)) + ':' + AppendZero(Math.mod(minutes,60)) + ':' + AppendZero(Math.mod(seconds,60))+' HH:MM:SS'; return timeF ; } Public String AppendZero(Long num){ String timeF; if(num<10){ timeF='0'+num; }else{ timeF=''+num; } return timeF ; } //Method Call Public PageReference doGeneration(){ //Get Incident Service Target listIncidentServiceTarget= [SELECT Id, Name, BMCServiceDesk__FKIncident__r.Owner_new__c, BMCServiceDesk__FKIncident__r.Summary__c, BMCServiceDesk__ElapsedTime__c, BMCServiceDesk__FKIncident__r.PendingStartTime__c, BMCServiceDesk__FKIncident__r.PendingDuration__c, BMCServiceDesk__TimeRemaining__c, BMCServiceDesk__StateValue__c, BMCServiceDesk__StartDate__c, BMCServiceDesk__Support_Hour_Applied__c, BMCServiceDesk__PausedDuration__c, BMCServiceDesk__TargetEndDate__c, BMCServiceDesk__FKIncident__r.Status_picklist__c ,BMCServiceDesk__FKIncident__r.Name, BMCServiceDesk__FKIncident__c FROM BMCServiceDesk__Incident_Service_Target__c WHERE BMCServiceDesk__TargetType__c ='ResolutionTime' AND BMCServiceDesk__IsCanceled__c = false AND BMCServiceDesk__StateValue__c <> 'Canceled' AND BMCServiceDesk__FKIncident__r.Status_picklist__c IN ('Assigned','In Progress', 'Pending') AND createddate > 2015-12-05T00:00:00.000Z]; IsGenerated=true; System.Debug('####Controller-listIncidentServiceTarget: '+listIncidentServiceTarget); for(BMCServiceDesk__Incident_Service_Target__c ist : listIncidentServiceTarget){ System.Debug('####Controller-ist: '+ist ); if(ist.BMCServiceDesk__StartDate__c!=null && ist.BMCServiceDesk__TargetEndDate__c !=null){ DateTime startDate= ist.BMCServiceDesk__StartDate__c ; DateTime endDate= ist.BMCServiceDesk__TargetEndDate__c ; //Total Time Long totalTime=BusinessHours.diff(ist.BMCServiceDesk__Support_Hour_Applied__c, startDate, endDate); //Elapsed Time Long elapsedTime=BusinessHours.diff(ist.BMCServiceDesk__Support_Hour_Applied__c, startDate, DateTime.Now()); //Remaining Time Long remainingTime; String fRemainingTime; if(ist.BMCServiceDesk__FKIncident__r.Status_picklist__c=='Pending'){ //Dynamic Calculation //Decimal pendingTime=BusinessHours.diff(ist.BMCServiceDesk__Support_Hour_Applied__c, ist.BMCServiceDesk__FKIncident__r.PendingStartTime__c, DateTime.Now()); Long pendingTime=(ist.BMCServiceDesk__FKIncident__r.PendingDuration__c).longValue()+BusinessHours.diff(ist.BMCServiceDesk__Support_Hour_Applied__c, ist.BMCServiceDesk__FKIncident__r.PendingStartTime__c, DateTime.Now()); elapsedTime=elapsedTime-pendingTime; remainingTime=BusinessHours.diff(ist.BMCServiceDesk__Support_Hour_Applied__c,ist.BMCServiceDesk__FKIncident__r.PendingStartTime__c, endDate); fRemainingTime=formatMS(remainingTime); }else{ //Static Calculation elapsedTime=elapsedTime-(ist.BMCServiceDesk__FKIncident__r.PendingDuration__c).longValue(); if(DateTime.Now()>endDate){ //remainingTime=elapsedTime-totalTime; remainingTime=BusinessHours.diff(ist.BMCServiceDesk__Support_Hour_Applied__c, endDate, DateTime.Now()); fRemainingTime='- '+formatMS(remainingTime); }else{ //remainingTime=totalTime-elapsedTime; remainingTime=BusinessHours.diff(ist.BMCServiceDesk__Support_Hour_Applied__c, DateTime.Now(), endDate); fRemainingTime=formatMS(remainingTime); } } String fElapsedTime=formatMS(elapsedTime); System.debug('####----------------Incident Number: '+ist.BMCServiceDesk__FKIncident__r.Name+' Status: '+ist.BMCServiceDesk__FKIncident__r.Status_picklist__c); System.debug('####Total Time: '+totalTime); System.debug('####Elapsed Time: '+fElapsedTime); System.debug('####Remaining Time: '+fRemainingTime); ist.BMCServiceDesk__ElapsedTime__c=fElapsedTime; ist.BMCServiceDesk__TimeRemaining__c=fRemainingTime; } } return null; } public PageReference CreatePDF(){ PageReference pageRef = new PageReference('/apex/RemElapPDF'); pageRef.setRedirect(false); return pageRef; } }
<apex:page tabStyle="BMCServiceDesk__Incident_Service_Target__c" controller="GenerateRemainingElapsedTime"> <style type="text/css"> .btnCSS { padding:3px; margin:2px 2px 0 2px; font: bold 13px Arial, Helvetica, sans-serif; width:90px; -moz-border-radius : 2px; -webkit-border-radius: 2px; cursor:pointer; text-decoration: none !important; background: #8C004C; background-color:#8C004C; border: 1px solid #8C004C; color:#FFF!important; } .btnCSS:hover { text-decoration: none !important; background: #8C004C; background-color:#8C004C; border: 1px solid #8C004C; color: #FFF!important; } </style> <apex:sectionHeader title="Generate Remaining/Elapsed Time" help="https://help.salesforce.com/htviewhelpdoc?err=1&id=admin_transfer.htm&siteLang=en_US" /> This screen allows you to generate Remaining/Elapsed Time of Incident Service Target of <b>Assigned</b>, <b>In Progress</b> and <b>Pending</b> incidents. <apex:form id="frm"> <apex:pageMessages /> <apex:actionFunction status="asRefresh" action="{!doGeneration}" name="doGeneration" reRender="oPanel,oPanel1"/> <apex:pageBlock id="pB" mode="maindetail"> <apex:pageBlockButtons location="top" > <button title="Generate" type="button" class="btnCSS" onclick="doGeneration();">Generate</button> <apex:outputPanel id="oPanel1"> <apex:commandLink rendered="{!IsGenerated}" title="Download in XLS" value="Download in XLS" styleClass="btnCSS" action="{!CreatePDF}"/> </apex:outputPanel> <apex:actionstatus id="asRefresh"> <apex:facet name="start"> <img style="margin-bottom:-3px;margin-top:5px;float:right" src="/img/loading.gif" title="Please Wait..." /> </apex:facet> </apex:actionstatus> </apex:pageBlockButtons> <apex:outputPanel id="oPanel"> <apex:variable value="{!0}" var="rowNum" /> <apex:pageBlockSection title="Remaining/Elapsed Time to be generated for below Incident Service Target" collapsible="false" columns="1"> <apex:pageBlockTable value="{!listIncidentServiceTarget}" var="t"> <apex:column headerValue="#"> <apex:outputText value="{!rowNum + 1}"/> <apex:variable var="rowNum" value="{!rowNum + 1}"/> </apex:column> <apex:column headerValue="Incident"> <apex:outputLink target="_blank" value="/apex/BMCServiceDesk__incidentConsole?record_id={!t.BMCServiceDesk__FKIncident__r.Id}" >{!t.BMCServiceDesk__FKIncident__r.Name}</apex:outputLink> </apex:column> <apex:column headerValue="Incident Service Target"> <apex:outputLink target="_blank" value="/{!t.Id}" >{!t.Name}</apex:outputLink> </apex:column> <apex:column headerValue="Queue" value="{!t.BMCServiceDesk__FKIncident__r.Owner_new__c}"/> <apex:column headerValue="Status" value="{!t.BMCServiceDesk__FKIncident__r.Status_picklist__c}"/> <apex:column headerValue="Summary" value="{!t.BMCServiceDesk__FKIncident__r.Summary__c}"/> <apex:column headerValue="Elapsed Time" rendered="{!IsGenerated}" value="{!t.BMCServiceDesk__ElapsedTime__c}"/> <apex:column headerValue="Remaining Time" rendered="{!IsGenerated}" value="{!t.BMCServiceDesk__TimeRemaining__c}"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>
Please help me with this. :)
Check the FLS of PendingDuration__c,Have you given access to this field.I think the field is hidden .
Check once and let me kknow still you have issue .
Thanks
Manoj
Thanks alot for your response and giving time for my issue.
I have given the access of the field but still facing the error. Can you please check if there is any possible solution for this.
Sahaj