How to convert String to Integer in Salesforce Apex?

How to convert String to Integer in Salesforce Apex?

Integer.valueOf() can be used to convert String to Integer using Apex in Salesforce.

Check the following code for reference.

Sample Code:

String str = '100';   

if ( str.isNumeric() ) {
        
    Integer intVal = Integer.ValueOf( str );
    System.debug( 'intVal value is ' + intVal );
    
} else {
    
    System.debug( 'String ' + str + ' is not numeric' );
    
}

Output:

Leave a Reply