Skip to main content
deleted 2 characters in body; edited tags
Source Link
Adrian Larson
  • 151.4k
  • 38
  • 247
  • 431

I am iterating through an array of a List of Maps and want to run an if function whenever an item from the list meets a condition.

The problem I am currently facing is Salesforce producing the following error:

System.NullPointerException: Attempt to de-reference a null object

System.NullPointerException: Attempt to de-reference a null object

Here's the code with some more explanations:

    for ( Integer i=1; i<allRows.size(); i++ ){
          //this system.debug is to iterate over all lists, extract the values
          //under the 'Names' header and display them in debug (IT WORKS)
          system.debug(allRows[i].get('Names'));
          String namesRow = allRows[i].get('Names');
          //The below debug also produces the correct values          
          system.debug('namesRow is ' +namesRow);
          //When the below function is active I am getting the NullPointerException Error
          if (namesRow.contains('Andrew')){
            system.debug('this name is in the database!');
    
          }
    
        }
      }

I am iterating through an array of a List of Maps and want to run an if function whenever an item from the list meets a condition.

The problem I am currently facing is Salesforce producing the following error:

System.NullPointerException: Attempt to de-reference a null object

Here's the code with some more explanations:

    for ( Integer i=1; i<allRows.size(); i++ ){
          //this system.debug is to iterate over all lists, extract the values
          //under the 'Names' header and display them in debug (IT WORKS)
          system.debug(allRows[i].get('Names'));
          String namesRow = allRows[i].get('Names');
          //The below debug also produces the correct values          
          system.debug('namesRow is ' +namesRow);
          //When the below function is active I am getting the NullPointerException Error
          if (namesRow.contains('Andrew')){
            system.debug('this name is in the database!');
    
          }
    
        }
      }

I am iterating through an array of a List of Maps and want to run an if function whenever an item from the list meets a condition.

The problem I am currently facing is Salesforce producing the following error:

System.NullPointerException: Attempt to de-reference a null object

Here's the code with some more explanations:

    for ( Integer i=1; i<allRows.size(); i++ ){
          //this system.debug is to iterate over all lists, extract the values
          //under the 'Names' header and display them in debug (IT WORKS)
          system.debug(allRows[i].get('Names'));
          String namesRow = allRows[i].get('Names');
          //The below debug also produces the correct values          
          system.debug('namesRow is ' +namesRow);
          //When the below function is active I am getting the NullPointerException Error
          if (namesRow.contains('Andrew')){
            system.debug('this name is in the database!');
    
          }
    
        }
      }
deleted 6 characters in body
Source Link

I am iterating through an array of a List of Maps and want to run an if function whenever an item from the list meets a condition.

The problem I am currently facing is Salesforce producing the following error:

System.NullPointerException: Attempt to de-reference a null object

Here's the code with some more explanations:

    for ( Integer i=1; i<allRows.size(); i++ ){
          //this system.debug is to iterate over all lists, extract the values
          //under the 'Names' header and display them in debug (IT WORKS)
          system.debug(allRows[i].get('Names'));
          String namesRow = allRows[i].get('Names');
          //The below debug also produces the correct values          
          system.debug('namesRow is ' +namesRow);
          //When the below function is active I am getting the NullPointerException Error
          if (investmentsRownamesRow.contains('Andrew')){
            system.debug('this name is in the database!');
    
          }
    
        }
      }

I am iterating through an array of a List of Maps and want to run an if function whenever an item from the list meets a condition.

The problem I am currently facing is Salesforce producing the following error:

System.NullPointerException: Attempt to de-reference a null object

Here's the code with some more explanations:

    for ( Integer i=1; i<allRows.size(); i++ ){
          //this system.debug is to iterate over all lists, extract the values
          //under the 'Names' header and display them in debug (IT WORKS)
          system.debug(allRows[i].get('Names'));
          String namesRow = allRows[i].get('Names');
          //The below debug also produces the correct values          
          system.debug('namesRow is ' +namesRow);
          //When the below function is active I am getting the NullPointerException Error
          if (investmentsRow.contains('Andrew')){
            system.debug('this name is in the database!');
    
          }
    
        }
      }

I am iterating through an array of a List of Maps and want to run an if function whenever an item from the list meets a condition.

The problem I am currently facing is Salesforce producing the following error:

System.NullPointerException: Attempt to de-reference a null object

Here's the code with some more explanations:

    for ( Integer i=1; i<allRows.size(); i++ ){
          //this system.debug is to iterate over all lists, extract the values
          //under the 'Names' header and display them in debug (IT WORKS)
          system.debug(allRows[i].get('Names'));
          String namesRow = allRows[i].get('Names');
          //The below debug also produces the correct values          
          system.debug('namesRow is ' +namesRow);
          //When the below function is active I am getting the NullPointerException Error
          if (namesRow.contains('Andrew')){
            system.debug('this name is in the database!');
    
          }
    
        }
      }
Source Link

System.NullPointerException when using .contains in a for loop

I am iterating through an array of a List of Maps and want to run an if function whenever an item from the list meets a condition.

The problem I am currently facing is Salesforce producing the following error:

System.NullPointerException: Attempt to de-reference a null object

Here's the code with some more explanations:

    for ( Integer i=1; i<allRows.size(); i++ ){
          //this system.debug is to iterate over all lists, extract the values
          //under the 'Names' header and display them in debug (IT WORKS)
          system.debug(allRows[i].get('Names'));
          String namesRow = allRows[i].get('Names');
          //The below debug also produces the correct values          
          system.debug('namesRow is ' +namesRow);
          //When the below function is active I am getting the NullPointerException Error
          if (investmentsRow.contains('Andrew')){
            system.debug('this name is in the database!');
    
          }
    
        }
      }