Sunday, February 17, 2013

Salesforce: Single screen entry for different records

Salesforce user interface is simple and intuitive. It is easy to create new records by clicking new button. But imagine if a sales executive has to create an account first, then enter a contact, opportunity, activity details. It will be a time consuming task. A single screen to enter this information will save some time, increases adoption and productivity.

Here is one example to enter Account, Contact, Opportunity and Activity details from one screen. This is just an example hence I have not written any test class. This page can be improved to display as a wizard.

Controller

public class multirecords {

public Account A {get; set;}
Public Contact C {get; set;}
Public Task T {get; set;}
Public Opportunity O {get; set;}

    public multirecords()
    {
        A = new account();
        C = new contact();
        T = new task();
        O = new opportunity();
    }
    
    public PageReference Save()
    {
        insert A;
        
        C.Accountid = A.id;
        insert C;
        
        T.whatid = A.id;
        T.whoid = C.id;
        insert T;
        
        O.Accountid = A.id;
        insert O;
        
        return new PageReference('/'+A.id);
    }

    public PageReference Cancel()
    {
        return new PageReference('/home/home.jsp');
    }
}


Entry Page



Visualforce