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
p1errep1erre 

Apex code

Hi there i'm new into appex code and i have following issue: i would like to add a dummy phone number to an account when I create it: the phone number should be unique for each account and should be assigned on the salesforce server side: Usecase is as follows: 1) I create a new account with account type "prospect" 2) I do not enter the phone number (phone number is a customized field in my account) 3) I save the new account 4) Salesforce assigns a unique phone number to this account and it shows it on the Salesforce Client GUI is there a way of doing step4) with Apex code ? thanks for any proposal /pierre
MVJMVJ

Yes you can use APEX to do this.

However,  Why would you not setup your field to be an auto number field?  Do you want the user to be able to change the dummy phone?  Why do you need a dummy phone number in the first place.  Sounds kind of foolish.

 

Any way here is a quick summary of what to do:

1) create a trigger on the account object that is a before insert.
2) When the trigger is fired you can change the phone value
3) You will need a custom object to store the last phone number that was created
4) You can increment that value by 1 each time a new account is created.

Again it is a simple Trigger but I would challenge why you need this.  It just does not make sense to me.

 

p1errep1erre
Thank you for your reply.

here's the reason my I need a dummy number
in my application there are two types of accounts, the first account type needs a "real" existing phone number that must be set when creating the account, the second account type does not have an assigned phone number yet but still needs a dummy one to be set automaticaly when creating the account in Salesforce. This phone number shall be changed later on.
The dummy number must be different from all existing phone numbers and must be unique in order to avoid two accounts having the same number.


MVJMVJ
Look at workflow.  Specifically field updates.  You could do this without APEX Code.
jpizzalajpizzala
Could you perhaps avoid the dummy phone number requirement altogether by doing the following?:
  1. Set the field itself as not required
  2. In the first Account type page layout, make the phone number field required
  3. In the second Account type page layout, make the phone number field NOT required - since it will be added later on but is not truly necessary from a data integrity standpoint.
True, this does not solve the unique phone number problem for the first Account type, but I assume that since these will be real numbers they shouldn't overlap (in theory).

Hope this helps.
p1errep1erre
well the thing is that my account object requires a phone number, even a dummy one, because in my application the phone number is a relation key to other objects within Salesforce: so, not defining one would lead to inconsistence withing the application