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
vamshi Capvamshi Cap 

Apex script unhandled exception by user/organization:

What is mean by this error: how can I handle. we already doing null checking,

 For example:

Apex script unhandled exception by user/organization: 00*************TE/00************gRb4
 
Visualforce Page: /apex/ppaccountsummary
 
 
 
caused by: System.NullPointerException: Attempt to de-reference a null object
 
Class.PPOrdersController.<init>: line 17, column 1 
 

Tugce SirinTugce Sirin
What do you have at line 17?
JethaJetha
Please paste your code here
 
vamshi Capvamshi Cap
  1. public class PPOrdersController{
  2.     //PPOrdersController pc  = new PPOrdersController();
  3.      public String aID{set;get;}
  4.      public String isSelfCare{set;get;}
  5.      public String accountid {get;set;}
  6.      
  7.      //For pending orders disable view button
  8.      public boolean enableViewButton {get;set;}
  9.      public List<Cart__c> cartlist {get;set;}
  10.      public List<Cart__c> tempcartlist {get;set;}
  11.      
  12.     // Constructor
  13.     public PPOrdersController(){
  14.              String accountid = System.currentPagereference().getParameters().get('accountid');
  15.             enableViewButton = false;
  16.             //For pending orders disable view button logic
  17.             if(!Util.isEmpty(accountid)){
  18.                 system.debug('i am here for the refresh');
  19.                 if(PrepaidAccountManagementService.allowNewOrder(accountid)){
  20.                         enableViewButton = true;
  21.                 }
  22.                 PrepaidOrderManagementService PrepaidOrderManagementServiceObj = new PrepaidOrderManagementService();
  23.                 cartlist = new List<Cart__c>();
  24.                 tempcartlist = new List<Cart__c>();
  25.     
  26.                 cartlist = PrepaidOrderManagementServiceObj.getCartsToAccount(accountid,3);
  27.             }
  28.            
  29.            
  30.          
  31.             /* //Populating the list with first three items.
  32.             if(!Util.isEmpty(tempcartlist)){
  33.                 integer i=0;
  34.                     for(Cart__c obj:tempcartlist){
  35.                         cartlist.add(obj);
  36.                         i++;
  37.                         if(i>2)break;
  38.                     }
  39.             }  */
  40.                     
  41.         
  42.     }
  43.     
  44.     /*******************************************************************
  45.     Purpose     : Redirects to redirectToAccountSearch page HomePanel.
  46.     Parameters  : None
  47.     Returns     : None
  48.     ********************************************************************/
  49.   public PageReference redirectAccountPlanOrdersAction(){
  50.         system.debug(LoggingLevel.DEBUG,'Entering PPOrdersController:redirectAccountPlanOrdersAction');
  51.         PageReference targetPageRef=null;
  52.         try{      
  53.            accountid = System.currentPagereference().getParameters().get('accountid');        
  54.            targetPageRef = Page.OrderQueueList;            
  55.            targetPageRef.getParameters().put('accountid',accountid);
  56.            targetPageRef.setRedirect(true);
  57.            return targetPageRef;
  58.             
  59.         }catch(Exception e){
  60.             system.debug(LoggingLevel.ERROR,'Error while redirecting to the redirectAccountPlanOrdersAction:'+e.getMessage());
  61.         }
  62.         system.debug(LoggingLevel.DEBUG,'Exiting PPOrdersController:redirectAccountPlanOrdersAction'+targetPageRef);
  63.         return targetPageRef; 
  64.     }
  65.     
  66. }
vamshi Capvamshi Cap
for the Util class i am checking if there is any null value is passed or not but still in our this exception is occured.
JethaJetha
Could you please debug your code and check wether this accountId at line number 17 is null or not. Please check and get back to me
vamshi Capvamshi Cap
Let me explain clearly,  but even if Account Id is null next line I am checking for whether Account Id is null or not. the AccountId at line 17 getting from URL

 
JethaJetha
So Could you please also post your UTIL class over here, There might be problem with UTIL class itsekf
 
vamshi Capvamshi Cap
Jetharam, can you confirm for the line: String accountid = System.currentPagereference().getParameters().get('accountid'); chance of throwing null pointer exception even if I not provde null Id.
JethaJetha
And at line number 14, you are reintialize your accountID variable, please remove string declaration before account Id at line 14
JethaJetha
Okay, let me see your UTIL class, Please post it here............
vamshi Capvamshi Cap
/*
*   @description - Utility class for validation of empty values, number, length , date etc.
*/
global with sharing class Util {
    
    /**
    *   @author - Shatanik
    *   @date - 10/29/2012  
    *   @description -This method Copies field values from source object to destination Object.
    *   @param sourceObj- SObject. 
    *   @param  destinationObj- SObject
    */
    
    global static void copyFieldsFromSourceToDestinationObj(SObject sourceObj, SObject destinationObj){
        System.debug('In copyFieldsFromSourceToDestinationObj --------------->>>');
        if(sourceObj != null && destinationObj != null){
            
            Set<String> destinationFieldSet = new Set<String>();
            
            String sourceObjName = sourceObj.getsObjectType().getDescribe().getLocalName();
            String destinationObjName = destinationObj.getsObjectType().getDescribe().getLocalName();
            System.debug('sourceObjName --------------->>>'+sourceObjName);
            System.debug('destinationObjName --------------->>>'+destinationObjName);
            
            Map<String, Schema.DescribeFieldResult> sourceObjFieldDescMap = DescribeCachingUtility.getFieldDescribe(sourceObjName);
            System.debug('sourceObjFieldDescMap --------------->>>'+sourceObjFieldDescMap);
            Map<String, Schema.DescribeFieldResult> destinationObjFieldDescMap = DescribeCachingUtility.getFieldDescribe(destinationObjName);
            System.debug('destinationObjFieldDescMap --------------->>>'+destinationObjFieldDescMap);
            
            for(Schema.DescribeFieldResult destfieldResult : destinationObjFieldDescMap.Values()){
                if(destfieldResult.isUpdateable()){
                    destinationFieldSet.add(destfieldResult.getLocalName());
                }else if(String.valueOf(destfieldResult.getType()).equalsIgnoreCase('REFERENCE') && destfieldResult.isPermissionable()){
                    destinationFieldSet.add(destfieldResult.getLocalName());
                }
            }
            System.debug('destinationFieldSet ---------------------------->>>>'+destinationFieldSet);
            
            for(Schema.DescribeFieldResult sourceField : sourceObjFieldDescMap.Values()){
                String localName = sourceField.getLocalName();
                System.debug('sourceField======================' + sourceField);
                String dataType = sourceField.getType().name();
                
                // Compare the localname of the field with the names of the fields in the above created account order set   
                // If they match then copy over the value of the field from C30 Account to Account Order
                if(destinationFieldSet.contains(localName)){
                    if(sourceObj.get(localName) != null){
                        destinationObj.put(localName, sourceObj.get(localName));
                    }else if(sourceObj.get(localName) == null){
                        if(dataType.equalsIgnoreCase('TEXTAREA') || dataType.equalsIgnoreCase('String') || dataType.equalsIgnoreCase('Phone') || dataType.equalsIgnoreCase('Integer') || dataType.equalsIgnoreCase('Double')){
                            destinationObj.put(localName, null);
                        }
                    }
                }
            }
        }
        
        System.debug('sourceObj ---------------------------->>>>'+sourceObj);
        System.debug('destinationObj ---------------------------->>>>'+destinationObj);
    }
    /**************************************************************************************************************************/
    
    /**
    *   @description - Checks the passed in input field for emptyness and return boolean value.
    *
    *   @param fldName - name of the field
    *   @param msg  - message to be displayed on UI  (can be select/enter)
    *   @param value -  value of input field
    */
    global static boolean isEmpty(String value){
        boolean flag = false;
        if(value == null || value.trim().equals(Cycle30Constants.BLANK)){
            flag = true;        
        }
        return flag;
    }
    
    /**
    * @author Tohar Patel 
    *  @description Check whether list is empty
    *  @param ex Exception which is printed in system log  
    *  @return Boolean True if String is empty or null else return false
    */
     global static boolean isEmpty(List<SObject> objList) {         
         if(objList == null || objList.size()==0) {
            return true;
         }else {
            return false;
         }
    }
    /**
    * @author Neha Gire 
    *  @description Check whether sObject is null
    *  @param ex Exception which is printed in system log  
    *  @return Boolean True if Sobject is null else return false
    */
     global static boolean isEmpty(SObject obj) {       
         if(obj == null) {
            return true;
         }else {
            return false;
         }
    }   
    
 /**
    * @author Tohar Patel 
    *  @description Check whether list is empty
    *  @param ex Exception which is printed in system log  
    *  @return Boolean True if String is empty or null else return false
    */
     global static boolean isEmpty(List<object> objList) {      
         if(objList == null || objList.size()==0) {
            return true;
         }else {
            return false;
         }
    }
    
    
    /**
    * @author Tohar Patel 
    * @date 01/11/2012 
    * @description - The method returns a random hex code using the 'SHA1' algorithm 
    * 
    * @modifiedBy - <Name> : date - <date of change> : purpose - <purpose of change>
    * Above line should be added for each change
    */  
    global static String getRandomHexCode(){
          String randomStr = String.valueOf(Integer.valueOf((Math.random()*System.currentTimeMillis())*System.currentTimeMillis()))+ String.valueOf(System.currentTimeMillis());
          Blob hash = Crypto.generateDigest(Cycle30Constants.SHA1_ENCRYPTION,Blob.valueOf(randomStr));
          String hexDigest = EncodingUtil.convertToHex(hash);
          System.debug(hexDigest);
          return hexDigest;     
    } 
    
   /**
    * @author Monali
    * @date 03/18/2013
    * @description Check whether map is empty
    * @param map<String,Object> map to check whether is empty or not  
    * @return Boolean True if map is empty or null else return false
    */
    global static boolean isEmpty(Map<String,Object> objectMap){      
         if(objectMap == null || (objectMap != null && objectMap.size()==0)) {
            return true;
         }else { 
            return false;
         }
    }
    
   /**
    * @author Monali 
    * @description Check whether Object is null
    * @param object to check whether it is null or not   
    * @return Boolean True if Object is null else return false
    */
    global static boolean isEmpty(Object obj) {       
         if(obj == null) {
            return true;
         }else {
            return false;
         }
    }  
}
vamshi Capvamshi Cap
Certainly this error is not occuring for me in our sanbox but production this is occuring to the users. Is this something with the Users?
JethaJetha
Got the Culprit.....................

 global static boolean isEmpty(String value){
        boolean flag = false;
        if(value == null || value.trim().equals(Cycle30Constants.BLANK)){
            flag = true;        
        }
        return flag;
    }

This method is getting called from your class, in if condition, value.trim().equals(Cycle30Constants.BLANK), through the error, because of vaule is a null string
vamshi Capvamshi Cap
But we have alredy defined the values in Cycle30Constants class the variable as :

public static final String BLANK = '';
vamshi Capvamshi Cap
here just comparing, I think the issue might be withsharing keyword. So that the error I am not getting but user is getting in production since I am login as system admin but user is having some profels. but not sure.
 
JethaJetha
No No, That error should not be null pointer exception, It would be something insufficient priviledge.

What here I am saying is, the variable value is null, and when you try to call any method, like you called trim, which is throughing error, you can trim a null value. Please pass some accountId value in URL and try again, It should work for sure.   I guarantee it.
vamshi Capvamshi Cap
can you please share your email Id  will explain more
 
JethaJetha
yes, it is jetharam123@gmail.com