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
swapna muthiyaluswapna muthiyalu 

i receive phone numbers in two combinations , one is 10 digit no like 9875689045 and sometimes like this +19875689045. now i want to trim if the phone no is greater than 10 and get only 10 digit no. i want to trim the +1 and get it like 9875689045.

Meghna Vijay 7Meghna Vijay 7
Hi,

Use TRIM(RIGHT(TEXT(Phone),10)) in formula field.

Hope it helps, if it does mark it as solved.

Thanks
swapna muthiyaluswapna muthiyalu
Thanks Meghna, but i need to acheive this through apex class, so i need to do coding for this.
Shaik Naga janiShaik Naga jani
Hi Swapna,
try below code in your apex class
String strPhoneNumber = '+19876543210';
if(strPhoneNumber.startsWith('+1')) {
    strPhoneNumber = strPhoneNumber.remove('+1');
}
System.debug('strPhoneNumber ======> '+strPhoneNumber);
Kindly mark this as solved if the reply was helpful.
Thanks
Shaik
swapna muthiyaluswapna muthiyalu
thanks Shaik, but my requirement is i have to remove the first no and retrun the remaining 10 digit phone no.
swapna muthiyaluswapna muthiyalu
even if the phone no starts with '1' or '+1' it has to trim that and retun only the 10 digit no
swapna muthiyaluswapna muthiyalu
so the output should be the 10 digits no from end
SarvaniSarvani
Hello Swapna,

Try the below code:
 
String IncomingNumber = '+12529874405';
string  strPhoneNumber;

if(IncomingNUmber.startsWith('+1')){
      strPhoneNumber = IncomingNumber.remove('+1');
}
else if(IncomingNumber.startsWith('1') && IncomingNumber.length()>10){
      
        strPhoneNumber=IncomingNumber.removeStart('1');
   }

else{
    strPhoneNumber =IncomingNumber;
}
System.debug('strPhoneNumber ======> '+strPhoneNumber);
Thanks,
Sarvani