Monday, January 16, 2017

Pre-poulate the "Name" field when creating a new record and update after saving

Sometimes there is a need to not use Auto-number as a record name. Instead, you want to pre-populate a Name field when creating a new record with a default value and update the Name based on some rules.
Unfortunately, it's impossible to create your own New custom button. The only option to achieve the requirement is to override the New button with custom VF page. Further please find solution description.

#Edit a new button - override with Visualforce page


Visualforce page was created which redirects to a hack URL with parameter "Name=Partner+Plan".

<apex:page standardController="Partner_Plan__c">
  <script>
      window.top.location.href = '/a0w/e?nooverride=1&retURL=%2Fa0w%2Fo&Name=Partner+Plan';  
 </script>
</apex:page>


#To prevent multiple redirect it's necessary to add parameter "nooverride=1".

After clicking on the button "New" you will be redirected to the page with these paramerers and field "Name" will be filled.
Partner Plan Name required update after saving. It should be consists "Partner Plan" + "Partner Name" + "Year".

#This was done using Workflow Rule.
  • Rule Criteria: true;
  • Evaluation Criteria: Evaluate the rule when a record is created, and every time it's edited
  • Immediate Workflow Action: field update;
  • Formula value: "Partner Plan - " + Practice_Group_Lead__r.FirstName + " " + Practice_Group_Lead__r.LastName + " " - " + TEXT(Plan_Year__c)
After saving: