You need to sign in to do that
Don't have an account?
p1erre
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
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.
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.
- Set the field itself as not required
- In the first Account type page layout, make the phone number field required
- 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.