Category Archives: Salesforce Corner

Wedid: Using Salesforce in a Residential Care Environment

Challenges

The main business requirement for the aged care facility was streamlining all the information to a single point of data entry as well as providing transparent updates to the residents.  Optimal care of the resident is enhanced when all data is stored in a single system.

Data such as medical records, progressive monitoring and the sharing of social updates as well as picture sharing among family members accessible via mobile.

Ability to grow as the facility increased the number of residents. The ability to provide a secure data store with access restricted based on users and information type.

Solution:

  1. Gather all data and understand the origin and process involved
  2. Design the data model and to ensure a single point of data but ensure that security will not be compromised
  3. Leverage Salesforce Customer Community to provide updates on the residents to family members

Related Objects Lead, Account (Person), Contact, Other Custom Objects
Components Data modelling, Customer Community, Visualforce Page, Apex Trigger
Complexity Medium

Salesforce: Check Null/Empty Value of A Field

In Salesforce, it is very common that we build formula field, validation rule or workflow rules to act on the data of a field and sometimes we would like to validate on an empty value. In Salesforce formula editor, there are two functions: ISBLANK() and ISNULL(). The question here is, which is the correct one that we should use?

ISNULL()

This is an old function that works with most of the field types except Text, Text Area and Long Text. (reference)

ISBLANK()

This is a new function that Salesforce introduce to support the empty field validation on Text fields. It also works with other field types. According to Salesforce documentation, it is recommended to use this function instead. (reference)

Please note that if you are referencing a formula field with the option “Treat blank fields as zeroes”, the formula field will give value zero and won’t be considered as null.

Above is how you can validate an empty field in formula editor. How can we achieve the same in Apex?

Text Fields

There are a few options to validate empty text fields in Apex:

Use String.isBlank() method. This will return true if the text field is empty.
Compare the text field to an empty string, e.g, Account.Name == ”. You shouldn’t use NULL as text field in Salesforce is never considered NULL. Note that String variable can still be considered NULL.

Checkbox Fields

This can be compared by using TRUE or FALSE. This is because an unchecked checkbox field is considered as FALSE instead of NULL.

Other Fields

You should compare the field value to a NULL.

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.

Need your Salesforce Inventory linked to Xero or Saasu?

Want to load data from Xero or Saasu?

We’ve added more functionality to our highly successful product, RIO Readymade Inventory Plus. You can now transfer data from Xero or Saasu to RIO Readymade Inventory Plus.

Can I use other csv data files?

Yes! The program can also handle any csv file in the required format.

How does it work?

  1. Send us an email at support@wdcigroup.net and we’ll send you the job.
  2. The upsert uses Skyvva data loader. Skyvva can be downloaded for free.
  3. Install Skyvva (this app is available on Appexchange).
  4. Install our job
  5. Download the data from Xero/Saasu
  6. Follow the instructions to upload your data to Salesforce.

What if I need some help?

Videos and documentation are available here.

Build on Salesforce features. Can I automate it?

Subscribe to Skyvva and you can email the data to automate the process

Salesforce Apex: Namespace and Field Name in AggregateResult

In Salesforce SOQL, we can use the aggregate function to summarize data in query. When an aggregate function is used, Salesforce will return the result as AggregateResult object and we can retrieve the value by calling AggregateResult.get(‘field name’). For example:

for(AggregateResult ar : [select count(Id), Business_Type__c from Account group by Business_Type__c]){
	system.debug(ar.get('expr0'));		//get the value of count(id)
	system.debug(ar.get('Business_Type__c'));	//get the grouped by field value
}

However, things get a little bit tricky when you have a namespace in the Salesforce instance and you have custom field in the SOQL. The sample query will still work, but you will get an error saying “Invalid aggregate result field” when you are trying to retrive the value of custom field.

To overcome this, you can choose to:

Option 1

Prepend the custom field with a namespace, for instance,

system.debug(ar.get('namespace__Business_Type__c'));	//get the grouped by field value

Option 2

Use alias in the SOQL to represent a custom field in query result.

for(AggregateResult ar : [select count(Id), Business_Type__c businesstype from Account group by Business_Type__c]){
	...
	system.debug(ar.get('businesstype'));	//get the grouped by field value
}

Personally, I would prefer to use Option 2 as I don’t have to hard code the namespace in all the SOQL.

Salesforce: Prevent Duplicate Record By Name

Scenario: An automation to prevent a record with the same name from being created twice.

Problem: Object name is a standard text field and you won’t be able to make it unique.

Solution #1: Salesforce Duplicate Management  Feature. Refer to this blog here for more information.

Solution #2: Validation rule with Vlookup function.
Example: 
Prevent Dup

Please take note that you will need to use $ObjectType in your Vlookup formula. $ObjectType is to tell the formula that it needs to refer to an object in that organisation. Here is how you can select your object from $ObjectType (Only available for custom objects):

SObject
For more details on how to use the Vlookup function, click here.

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.