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

Using JavaScript to set the Account Name base on value of custom fields

I'd like to automatically format the Account Name field in the standard Accounts object based on the value of a few select custom fields.


This is something I'd normally create a formula for, but there's no way to do that on standard field as far as I can see.


Basically, let's say I'm editing or creating a new account inside -- I have the following custom fields:



First Name

Last Name





I'd like to set it up so the standard account name fields gets updated via JavaScript as the values in those custom fields are modified.


Is this possible, or a pipe dream?

Doug ACFDoug ACF

You would have to make a Visualforce page in order to update the Name field on the edit page via Javascript with every change to a component field. 


But you should also consider a no-code approach where you would form the Name value in a workflow field update after the record is saved.  Since you need something in the Name field when you first save, override the New/Edit button with a URL string that passes in a default value to the name field (e.g., "Set by Workflow Rule"). 

Thanks Doug, took your suggestion and just created an APEX Trigger for it.

I need a similar solution for Contracts.  Is there any way that you could post your trigger code?