Aish
Aish

Reputation: 67

Change the format of all Contacts phone numbers in Salesforce

Some of the phone numbers of Contacts are formatted as (123) 456-7891

I need to change the format of all phone numbers to 1234567891.

I don't want to create another formula field that contains the correct format. I want to change the format of all the current phone numbers(and future phone numbers) to the format 1234567891.

Do I need to create a batch Apex class for this? If so, how should I go about formatting the numbers? I couldn't find anything on google.

How should I proceed?

Upvotes: 0

Views: 1275

Answers (1)

eyescream
eyescream

Reputation: 19637

You should be able to do it code-free, with flow/workflow/process builder. Update with "formula"

if

CONTAINS(Phone,'(') || CONTAINS(Phone, ')') || CONTAINS(Phone, '-')

then field update action

Phone = SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Phone, '(', ''), ')', ''), '-', '')

If you really would rather do it with a before insert, before update trigger that's an option too of course.

So that should solve it for future data, how about what's already in the system. One off batch job is an option but that's a lot of work (class, test class, deploy, run, afterwards destructive deployment...).

How much data we're talking about, couple thousands? You could design what you need as a bit of code to run in Developer Console's execute anonymous.

You could look into exporting all bad records with a report, running a fix in excel (or even not, depends how you wrote the 1st part. Did you make it run on every update or only when Phone changes?) and then importing back. If you made it run on every update you could even do a dummy edit (import just the ID column, as if user hit edit and save without changing anything). Depends on size you could use built-in Import Wizard or install Data Loader.

Upvotes: 2

Related Questions