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
Siboniso ZwaneSiboniso Zwane 

How to remove "NULL"

Good day Developers,

I am struggling to find the solution to this problem.  

/** this function will get leave reason if needed
*  @param email_linesP is array containing all the email lines
*  @return reason string will be returned
*/
    private String getLeaveReason( List< String > email_linesP ){
        
        String reason_string = '';              //this is the reason string
        
        //check if we dont have reason
        if( m_reason_index != -1 ){
            
            //loop through the email lines
            for( Integer i = m_reason_index + 1; i < email_linesP.size(); ++i ){
                
                //check if current line has : charecter( will indicate keyword )
                if( email_linesP[ i ].contains( ':' ) )
                    break;                                  //leave the loop
                
                reason_string += email_linesP[ i ] + '\n';          //append line
                
            }//end of for-block
            
        }
        else
            reason_string = 'No Reason Provided';       //set the reason string to default value
        
        return reason_string;                   //return the reason 
        
    }//end of function definition

The above code is returning the correct information except for when there is no reason for my reason_string, instead it returns a "NULL" value instead of 'No Reason Provided' which is the reason_string. how do I get it to reflect 'No Reason Provided' instead of "NULL"
Saravanan @CreationSaravanan @Creation
Hi

Please try with the below code

/** this function will get leave reason if needed
*  @param email_linesP is array containing all the email lines
*  @return reason string will be returned
*/
    private String getLeaveReason( List< String > email_linesP ){
        
        String reason_string = 'No Reason Provided';              //this is the reason string
        
        //check if we dont have reason
        if( m_reason_index != -1 ){
            
            //loop through the email lines
            for( Integer i = m_reason_index + 1; i < email_linesP.size(); ++i ){
                
                //check if current line has : charecter( will indicate keyword )
                if( email_linesP[ i ].contains( ':' ) )
                    break;                                  //leave the loop
                
                reason_string += email_linesP[ i ] + '\n';          //append line
                
            }//end of for-block
            
        }
        else
            reason_string = 'No Reason Provided';       //set the reason string to default value
        
        return reason_string;                   //return the reason 
        
    }//end of function definition