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
jeregarjeregar 

How to convert strings to integer in a trigger?

Has anyone needed to convert a string variable to integer? I need to code a verification digit function, and I am getting the digits from a string with the substring function. Next to that, I need to convert each 'text' number to integer for multiplication.
 
Here is a sample of what I need...
 
Code:
public static boolean CUITVerification(String cuit)
{
       if(cuit.length() != 11)
          return false;
       
       String xx1 = cuit.substring(1,1);
       Integer x1 = xx1;
       x1 = x1 * 5;

       if(x1 == 10)
          return true;

}

 to anyone who can help me...thanks
Best Answer chosen by Admin (Salesforce Developers) 
gokubigokubi
This is how it should look, as I understand it:
Integer i;
String s;
s='10';
i=integer.valueof(s);
system.assertEquals(10,i); //this test passes

Of course there's no handling in there for if the string doesn't convert well...

Steve

All Answers

gokubigokubi
This is how it should look, as I understand it:
Integer i;
String s;
s='10';
i=integer.valueof(s);
system.assertEquals(10,i); //this test passes

Of course there's no handling in there for if the string doesn't convert well...

Steve

This was selected as the best answer
jeregarjeregar
Thank you gokubi! It works great.
 
As you said, I had problems with the substring function, but I already solved them.
 
Manish Pal 17Manish Pal 17
Thank you gokubi! It works great.