Tag Archives: Visualforce

Salesforce: Visualforce CommandButton to Bypass Validation/Required Fields

In Visualforce apex:CommandButton component, there is an attribute called “immediate” that allows us to invoke the controller action bypassing the validation rules associated with the fields (especially those that mark with required=”true”) in a visualforce page. I have been using this attribute alongside with the cancel button which does not required any input from users. Until recently, I noticed that the attribute no longer working as expected in one of my visualforce page development. For example:

<apex:page standardController="Account" extensions="AccountExt" standardStylesheets="true" applyBodyTag="false" docType="html-5.0" title="My Wizard">
	<apex:form id="theform" >
		<apex:pageBlockButtons >
			<apex:commandButton value="Cancel" action="{!cancel}" immediate="true"/>
			<apex:commandButton value="Search" action="{!doSearch}" />
		</apex:pageBlockButtons >
		
		<apex:pageBlockSection title="Test">
			<apex:inputfield value="{!account.Type__c}" required="true"/>
		</apex:pageBlockSection>
	</apex:form>
</apex:page>

After some research, I realised this is actually related to the behavior in HTML 5 (doctType=”html-5.0″) where it will automatically validate all the required fields that I have in a form. So, how can we overcome this?

Option 1 (Form level)

You can set an HTML 5 attribute called html-novalidate=”novalidate” at the form level. However, this will disable the validation for all buttons. You should only use this if you have your own validation logic implementation in the controller/extension class.

<apex:form id="theform" html-novalidate="novalidate" >

Option 2 (Button level)

You can have the similar attribute next to the command button to disable the validation on the button specifically.

<apex:commandButton value="Cancel" action="{!cancel}" immediate="true" html-formnovalidate="formnovalidate" />

This is a better option to go for as we do not need to worry about implementing the additional logic to validate the user input.

Wedid: Custom CPQ

Challenges:

This company earns their revenues through providing services and lab products.

Currently, all the product details e.g selling prices, promo prices are stored in different external systems. These details are not available in Salesforce.

The sales team will need to manually check for product details – product prices from different systems before adding them into the Salesforce quote. This is causing a massive backlog in the quoting process and the company is looking for a solution to expedite the process.

For example:

  1. User is going to propose Product A.
  2. The user logs in to system A to check for the selling price for Product A.
  3. Then, the user logs in to system B to check for the promo price (if any) for Product A.
  4. Once confirmed, the user includes Product A as line item in the quote.

Solution:

  1. Create a custom page in Salesforce that allows user to search for the products.
  2. Using integration and web service calls, allow user to search for the prices of the selected products from both systems through the same custom page in Salesforce.
  3. From the price search results, user can proceed by creating a quote and and quote line items.
Related Objects Product, Pricebook, Pricebook Entry, Opportunity, Opportunity Product, Quote, Quote Line Item
Components/App VisualForce, Trigger

Web Service Calls base code generated via WSDL2Apex then further modified to suit the need.

Complexity Difficult

Challenge encountered as the initial WSDL file was not compliant with WSDL2Apex requirement and necessitated adjustment before it can be parsed by WSDL2Apex.

 

Wedid: Custom Invoice Administration

Challenges:

This company earns their revenues through bookings services that they have planned and executed for their clients.

Their invoicing practice is to invoice all completed line items of the bookings in end of each month. For an example,  they would like to prepare the bookings and line items completed this month for invoicing.

Booking A
1) Account: Company XYZ
2) Booking Completed: 01/16/2015
3) Booking Line Items:
– Placement Booking
– Transportation Booking

Booking B
1) Account: Company ABC
2) Booking Completed: 22/16/2015
3) Booking Line Items:
– Placement Booking
– Transportation Booking

Booking C
1) Account: Company XYZ
2) Booking Completed: 01/16/2015
3) Booking Line Items:
– Placement Booking
– Transportation Booking

Booking C
1) Account: Company ABC
2) Booking Completed: 22/16/2015
3) Booking Line Items:
– Placement Booking

Solution:

  1. The line items of each bookings are set as products in Salesforce. These products must be from a single pricebook.
  2. Build a Visualforce page that allows the record search and filtering. i.e. Dates.
  3. With the results found from the search and filtering, user can choose which bookings and their line items to be processed.
  4. Once proceed, a trigger will create opportunities for each bookings and booking line items will be created as opportunity line items against the created opportunities.
  5. User can then use an app to sync the opportunities and their opportunity line items over to their accounting  system for invoicing process.
Related Objects Product, Pricebook, Pricebook Entry, Booking, Booking line item, Opportunity, Opportunity Product
Components/App VisualForce, Trigger, Breadwinner App
Complexity Difficult

Salesforce Visualforce Page workaround for apex:pageBlockSection not collapsible within apex:repeat

Visualforce provides us with many tools and components to quickly setup a page with high degree of similarity in style with Salesforce UI look and feel.

One of such is the pageBlockSection, which as the name hint is often used to create a section within the Visualforce Page that we intend to display, ex:

<apex:pageBlockSection title="Test Section">
...
</apex:pageBlockSection>

Much like the way Salesforce own UI pageBlockSection behave, this section can be toggled between a collapsed state where it only display the title of the section, ex:

2015-06-23 12_08_02-salesforce.com - Developer Edition

or unfolded into it’s deployed state where it display the content of the section as well as the title..

2015-06-23 12_07_42-salesforce.com - Developer Edition

These are standard capability of the pageBlockSection itself, but as of the time of this writing a problem exist when we attempt to use pageBlockSection while enclosing it within a repeat component, ex:

<apex:repeat>
	<apex:pageBlockSection title="Test Section">
	...
	</apex:pageBlockSection>
</apex:repeat>

The above code will break the collapsible feature of pageBlockSection, locking it in unfolded state.
A workaround to this problem is to include a dummy pageBlockSection prior to the repeat component, this dummy pageBlockSection can be hidden and it will remain functional, so to fix our example above:

<apex:pageBlockSection title="Title" collapsible="true" rendered="false"/>
<apex:repeat>
	<apex:pageBlockSection title="Test Section">
	...
	</apex:pageBlockSection>
</apex:repeat>

Salesforce Visualforce Page View State

Have you ever encountered the “Maximum view state size limit” error on the Visualforce page that you developed even though you only capture very little information (e.g, like 3 input fields)?

Maximum view state size limit (135KB) exceeded. Actual view state size for this page was xxx.xxKB

The way that the view state works is that it is not only holding the value of the field that you capture on the page, but it also holds the value of any accessible objects/variables that you have declared in the controller/extension. For example, if you have an object list (e.g, List<Account>) and the list is holding a lot of records, you might encounter the view state size limit error even though you are not displaying result in the page.

Salesforce has a good explanation on Visualforce View State that gives you a good start if you are troubleshooting the issue. As a good developer, you should also follow the best practice guide to develop a performance optimized Visualforce page.

Wedid: Automated Record Link

Challenges

Certain products that are up for sale require product activation code. In Salesforce, a custom object is created to store all the product activation code records. Whenever an opportunity is closed won, the opportunity products should be assigned with activation codes and details. This can then be generated out in PDF form and sent to customers. There are a series of filters and criteria involved when it comes to assigning the right activation codes to the right opportunity products and this process is currently being handled manually. User will have to eyeball both the opportunity products and activation codes to link them appropriately. It is pretty time consuming when you have to manually assign these activation codes to the opportunity products when the list is long (e.g. 10 products and above).

Solution:

We have implemented Visualforce page and Apex classes and to do the following:

1. Page to list out all the opportunity products that require product activation codes (exclude the product that do not require activation codes).

2. Apex class to search for available product activation codes from a different object based on specific criteria.

3. Apex class to link both the opportunity product and the product activation code together and populate relevant product activation code data to product and vice versa.

Related Objects Custom Objects
Components Apex Classes, Visualforce Page
Complexity Medium

Wedid: Salesforce Community Customisation

Challenges

Customer would like to host a community forum in Salesforce which allows customers to discuss and contribute ideas by using Salesforce Chatter function. They also would like to consolidate the information that they have in the website to the community forum.

Solution:

The Salesforce Visualforce page is used to build a custom webpage for the community forum. The Visualforce page also embed with the Chatter functionality so that customers can collaborate with each other.

Related Objects Account
Contact
Custom Object
Chatter
Chatter Topic
Components Visualforce Page
Chatter
Apex Class
Salesforce Community
Complexity High

Wedid: Custom workflow in Salesforce

Challenges

Customer is a professional property buyers group in Australia. They help their clients to analyse, purchase and manage the properties. As the whole process is tedious and hard to manage (e.g, information gathering, activity tracking, customer meetings and etc), they would like to implement a clean and lean workflow wizard in Salesforce that can help to reduce the manual work.

Solution:

A custom object is created to act as the workflow stage. In each stage, there will be a list of fields that need to be tracked. A series of Visualforce pages are used to read the workflow stages from the custom object and render the required fields dynamically on the fly. The Visualforce pages are also act as the wizard to guide the users through the necessary steps involved in the business flow.

We also use Salesforce Cloud Scheduler and Activity object. This allows users to schedule their meeting with customers and track any other activities.

Related Objects Account
Opportunity
Property (Custom Object)
Settlements (Custom Object)
Loan (Custom Object)
Components Visualforce Page
Apex Class
Workflow Rules
Cloud Scheduler
Complexity High

Salesforce: License Key Automation

Challenges

User have to manually assign license keys to the related software in Opportunity Line Item whenever the opportunities are closed as won.

The process involve users going in to the license keys object and look for the available license key. They have to manually populate the software info into the assigned license key records as well.

Solutions:

Create a trigger that allows users to assign license key to the related software automatically by a button click. The solution covers:

  1. Listing out the software in Opportunity Line Item that will go through the license key assignment process. From the list, users have options to proceed or cancel.
  2. If proceed, the license key assignment process will start.
  3. In the assignment process, the trigger will search for the “Available” license key based on the type and version of the software. Once the list of available license keys have been found, one license key will be selected and assigned to the software. The software details will be populated into the assigned license key and the status of the licensed key will be set as “Not Available”.
Related Objects Opportunity and Custom Object
Components Apex Trigger, Visualforce
Complexity Complex

Customizing Quote Template

You may be using the Salesforce default Quote feature and you want to further customize the quote template so that it matches your requirement?

To do so, we can utilize the Visualforce page feature in Salesforce (Professional Edition supported) to create the quote template instead. With Visualforce page option, the quote template and its content can be further customize (i.e. by using HTML and CSS).

For example, following is a simple quote sample with customized background that is generated through the Visualforce page:

Additionally, emailing the generated Visualforce Quote to the respective contact or particular recipient is possible too. To find out more about this approach, check out our example posted here.