Tuesday, 7 February 2012

Displaying Records based on the view selected

It can be observed from the standard salesforce UI behaviour, the page shows a list of records with respect to the view selected. This behavior can be noted in standard objects like Accounts, Contacts, Opportunities etc., The Views like My Accounts, All Accounts, New This Week etc., are available by default in the salesforce edition as shown below,






With the help of "Create New View", we can create our custom views based on the filter criteria selected.

Following code demonstrates this behavior in a Visualforce page based on Contact Object,

VF Page  :






    
        
    
            Select Contacts View: 
            
            
                
            

Edit |  Del | First Previous Next Last

Controller :
public with sharing class ContactMassUpdateBasedOnView 
{
    public String selectedCon{get;set;}
     public Contact contact_obj;
    
    public ContactMassUpdateBasedOnView(ApexPages.StandardSetController controller) 
    {
        contact_obj=(Contact)controller.getRecord();
    }

    public PageReference delTheContact()
    {
        if(selectedCon!=null)
        {
            Contact ct= Database.Query('SELECT Id, Name from Contact WHERE Id=:selectedCon');
            Delete ct;  
            PageReference testPage = Page.CustomContactSearchPage;
            testPage.setRedirect(true);
            return testPage;           
        }
        return null;
    }
}


 Output :




No comments:

Post a Comment