Convert String to integer

Integer x = 6; String y = '4'; // y is the String Type integer value. x = integer.valueof(y); // y is convert in integer and put value in x which is integer type. system.assertEquals(4,x); System.debug(x);



Example :

String num1 ='50'; String num2 = '30'; String num3 = num1 +num2 ; // you get 5030 because we are not convert string to integer system.debug(num3) ; Integer num4 = integer.valueof(num1) + integer.valueof(num2) ; // you get 80 because we convert them in integer system.debug(num4) ;

Comments

Popular posts from this blog

Email Send through apex class

Insert a Record to an object in salesforce