Thursday, October 25, 2012

Enhanced list views on a Visualforce page

Enhanced lists are used when you want to display a specific list view for a standard or custom object, rather than having all list views available for the user to select.
Step 1 – Create the list view
Go to the standard or custom object and click on the Create New View next to the Go button. Create the view and click on Save. When the page has reloaded, you will notice in the url a 15 digit id has been created for your view. Copy or make a note of the id.
 
 
 
 
 
 
 
 
 
 
Step 2 – Add code to your visualforce page
Add the following bit of code to your visualforce page, replacing the listid with your id:
<apex:enhancedlist type=”Lead” height=”730″ customizable=”false” rowsPerPage=”25″ Listid=”00B30000007wesH” />
Change customizable to equal true if you want your users to be able to edit the filters on the view. Once saved, you should find your visualforce page displays an enhanced list similar in appearance to the image below.

Change Password using apex code

setPasswordID userID
String password
VoidSets the password for the specified user. When the user logs in with this password, they are not prompted to create a new password. Use resetPassword if you want the user to go through the reset process and create their own password.
Warning
Be careful with this method, and do not expose this functionality to end-users.

e.g. System.setPassword('006A123ahjklkk','password123');
 

Hide Salesforce Logo

You can hide the logo from top using the javascript below.


<script language="JavaScript">try{var pa=document.getElementById("phHeaderLogoImage"); pa.style.display = "none";}catch(err){alert('There was an error on this webpage='+err.description);}</script>


You can either use it in visualforce page or add it in homepage components.

Check if inputTextField contains numbers only

Many times you want to check if the inputText contains numbers of decimals only e.g. getting amount in input.


public boolean isValidNumber(String inputNumber){
     Pattern p = Pattern.compile('\\d+(\\.\\d+)?');
     Matcher m =p.matcher(inputNumber);
     return m.Matches();
}

The above method return true if it is a valid number else return false.