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
AskMAskM 

Phone Field in Account

 

I need a rule or code for the Phone field in Accounts that if  someone leaves out the +1 on a US number, I would like Salesforce to just put it in silently.





Currently all telephone numbers for the US  start with +1 ,then area code and local number (i.e. “(454) 565-4252”) .

 

Any Suggestions!

sherodsherod

I'd suggest you'll need to use a before update trigger on the Account object which re-writes the phone number

goabhigogoabhigo

You can use workflow field update to do this. If the phone is US number then update the phone field with adding +1 to the existing value.

I have a question, how do you recognize it as US number?

 

And I didn't understand why you are posting it twice? http://boards.developerforce.com/t5/Formulas-Validation-Rules/Account-Field-Phone/td-p/318695 This is duplicate post. Please dont do this.

Ankit AroraAnkit Arora

Many questions/concerns comes in my mind over this :

 

1) When you have US local selected then when ever a 10-Digit number is filled in phone it gets formatted automatically like this : (999) 999-9999

 

2) When we enter 19999999999 , still it will give us the same (999) 999-9999

 

3) But when we enter +19999999999 , it will save as is +19999999999

 

3) Now what exactly you want? 

i) If I enter a 10-Digit number which is not starting with +1 then append +1 before the number ie when I enter 9999999999 OR 19999999999 it should save like this +19999999999. If yes then here is the code :

 

trigger MyTrigger on Account (before insert)
{
    for(Account acc : Trigger.new)
    {
        String phn = acc.Phone.replace('(' , '') ;
        phn = phn.replace(')' , '') ;
        phn = phn.replace('-' , '') ;
        phn = phn.replace(' ' , '') ;

        if(!acc.Phone.startsWith('+1') && phn.Length() == 10)
        {
            acc.Phone = '+1' + phn ;
        }
    }
}

 ii) When I enter any number which is not starting with +1 should get +1 then here is the code

 

trigger MyTrigger on Account (before insert)
{
    for(Account acc : Trigger.new)
    {
        String phn = acc.Phone.replace('(' , '') ;
        phn = phn.replace(')' , '') ;
        phn = phn.replace('-' , '') ;
        phn = phn.replace(' ' , '') ;

        if(!acc.Phone.startsWith('+1'))
        {
            acc.Phone = '+1' + phn ;
        }
    }
}

 If you have any other requirement then you can change the trigger, or do let me know if you are unable to make it. Just specify what exactly you want.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Ankit AroraAnkit Arora

I forgot to apply the condition 

 

if(acc.Phone != null && acc.Phone != '')

 Before the execution of the code, Please put this else you may got null pointer exception.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page