To create a password field in visualforce page, you can use inputsecret. InputSecret is an HTML input element of type password.
Let’s take an example:
In below visualforce page there are two input fields Name & Account Number of Account object. Here Account number is in inputsecret. The inputsecret filed of Account Number will act like a password field.
Regular expressions (REGEX) is a string that is used to match another string, using a specific syntax. Apex provides patterns and matchers that enable you to search text using regular expressions.
Pattern Class: A pattern is a compiled representation of a regular expression. Patterns are used by matchers to perform match operations on a character string.
Matcher Class: It allows to do further actions such as checking to see if the string matched the pattern or allows to manipulate the original string in various ways and produce a new desired one.
Let’s take one simple example:
public Boolean ValidateEmail(String emailId)
{
Boolean result = false;
String emailRegex = '^[a-zA-Z0-9._|\\\\%#~`=?&/$^*!}{+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$';
Pattern EmailPattern = Pattern.compile(emailRegex);
Matcher EmailMatcher = EmailPattern.matcher(emailId);
if(EmailMatcher.matches())
{
result = true;
}
return result;
}
In above example ValidateEmail is a method with emailId parameter. In ValidateEmail method there is a string variable, which contains email validation regex. Then I create matching pattern by using the pattern class with emailRegex variable. Then I do match it against the emailId. After that I do check emailId variable is in valid email format.
In this article I will demonstrate how to create treeview in visualforce page.
Here in Visualforce Page displays a collapsible treeview, with Accounts and Contacts related to the account.
For this development we need JQuery plugins. Download the Jquery Plugin from here and Upload this Zip file into Static Resources with the name “JqueryTreeView”.
Create Apex class with following code:
public with sharing class TestTreeView
{
//Wrapper class to contain the parent nodes and their child nodes
public class WCTreeView
{
public List<contact> Child {get; set;}
Public Account Parent {get;set;}
public WCTreeView(Account objAC, List<contact> objCList)
{
Child = objCList;
Parent = objAC;
}
}
Public List<wctreeview> TreeView;
Public List<wctreeview> GetNodes()
{
TreeView = new List<wctreeview>();
List<account> objACList = [Select Id, Name from Account];
for (Integer i = 0; i < objACList.size(); i++)
{
List<contact> objCList = [Select Id, FirstName, LastName from Contact where AccountId = :objACList[i].Id];
TreeView.add(new WCTreeView(objACList[i], objCList));
}
return TreeView;
}
}
Using apex:relatedlist we can display a list of Salesforce records that are related to a parent record with a lookup or master-detail relationship.
Let’s take an example:
To render the visualforce page properly, you must associate the Visualforce page with a valid account record in the URL. e.g. if 0019000000nMEIG is the account ID, the resulting URL should be: https://Salesforce_instance/apex/TestRelatedListPage?id=0019000000nMEIG Visualforce Page:
In this article I’ll demonstrate how to check a String whether it is null or empty or blank using Apex.
we can use the following methods to check a whether String is null or empty or blank: IsBlank – It Returns true if the specified String is white space, empty (”) or null, otherwise it returns false. IsNotBlank – It Returns true if the specified String is not white space, not empty (”) and not null, otherwise it returns false. IsEmpty – It Returns true if the specified String is empty (”) or null, otherwise it returns false. IsNotEmpty – Returns true if the specified String is not empty (”) and not null, otherwise it returns false. Sample Code:
public with sharing class CheckString
{
public String CheckIt {get;set;}
public CheckString()
{
CheckIt = 'Biswajeet';
}
//Check IsBlank
public Boolean CheckisBlank()
{
if(String.isBlank(CheckIt))
{
//String is not white space or not empty ('') or not null
return false;
}
else
{
//String is white space or empty ('') or null
return true;
}
}
//Check IsNotBlank
public Boolean CheckIsNotBlank()
{
if(String.isNotBlank(CheckIt))
{
//String is not whitespace and not empty ('') and not null
return true;
}
else
{
//String is whitespace or empty ('') or null
return false;
}
}
//Check IsEmpty
public Boolean CheckIsEmpty()
{
if(String.isEmpty(CheckIt))
{
//String is not empty ('') or not null
return false;
}
else
{
//String is empty ('') or null
return true;
}
}
//Check IsNotEmpty
public Boolean CheckisNotEmpty()
{
if(String.isNotEmpty(CheckIt))
{
//String is not empty ('') and not null
return true;
}
else
{
//String is empty ('') or blank or null
return false;
}
}
}
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject