Posts

Showing posts with the label visualforce

Disabled Save Button on Forms while Saving in Salesforce

Image
How to Disable the Save Button on your Form while the Form is Saving to Prevent Multiple Submissions in a Custom Salesforce Visualforce Page Salesforce default functionality on forms will disable the save button after the form is submitted to prevent multiple submissions. The disabled Save button will look like: Disabled save button after form submit When creating your own VisualForce page you can write custom code to mimic this functionality in your forms using just Javascript and modifying the button's CSS styles. Create Javascript functions to disable and enable the save button You will need to create 2 Javascript functions that will enable and disable the button by modifying the css and properties of the save button. I am using jQuery but you can also do this with vanilla Javascript. I am currently using a unique style class attached to the button to look it up for convenience since this page does not get modified very often if eve...

Create a Salesforce User in Apex with all Required Fields Populated

Create a Salesforce User with Code in Apex with all of the Required Fields Populated for a Test Class When attempting to create a user with code in Apex you will encounter an error if you do not populate every single required field. You may be attempting to do this for a Test class or for any number of reasons. The error you encounter may look similar to the following: Missing fields Exception System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName, Email, Alias, TimeZoneSidKey, LocaleSidKey, EmailEncodingKey, ProfileId, LanguageLocaleKey]: [LastName, Email, Alias, TimeZoneSidKey, LocaleSidKey, EmailEncodingKey, ProfileId, LanguageLocaleKey] Create a User Many of those fields require specific values populated from a picklist. Below is some boilerplate code you can use to create a use programmatically with all of those fields populated correctly. You can use your own values for...

Salesforce Dynamically Populated List of Checkboxes in Visualforce and Apex

Image
Dynamically Populated List of Checkboxes in Visualforce and Apex Below you will find details on how to create a dynamic checkbox group on a custom Salesforce page using Apex and Visualforce. These examples will leverage Visualforce specific tags and Apex specific functionality to accomplish things that you would normally need an external library such as jQuery to acheive. Dynamic Array of Checkboxes Dynamically build an array of checkboxes and keep track of which boxes are checked.  Checkboxes will be populated from a SOQL query from a custom object in Salesforce.  Selected options will be tracked and persisted if you re-render the checkboxes. Visualforce Command button to refresh list of checkboxes <apex:commandButton action="{!refresh}" reRender="customCheckboxPanel" status="loadingDetails"> This is just an example.  A more practical use of this would be a onchange or onclick event such as if you had checkbo...