Oh my god. It's full of code!

Simple List Editor VisualForce Page

Hey everyone. So I just finished a real simple visual force application. Basically it’s a list view editor. Just gets a large list of data that can be edited inline, that saves as you work. It can also be easily modified to refine the data providing query based on URL data. By itself, it isn’t super useful, but it’s a good building block for other projects. This particular instance tool was for our home callers. They needed an easy way to see everyone they were supposed to call, and needed a way to track the outcomes of those calls. A report wouldn’t do the trick since you can’t modify data, and clicking from record to record was too slow. Campaign members get assigned a caller, so I just have the query refine the results based on caller (and campaign if desired) and display the results for editing. So without further ado, here ya go.

Visualforce Page

<apex:page controller="callListController" action="{!getData}" sidebar="false" >
    <apex:sectionHeader title="My Call List"></apex:sectionHeader>
    <apex:form >
        <apex:pageBlock title="">

          <!-- To show page level messages -->
          <apex:pageMessages ></apex:pageMessages>        
            <apex:actionFunction action="{!UpdateRecords}" name="updateRecords" rerender="pageBlock" status="status"></apex:actionFunction>
            <apex:pageBlockTable value="{!CampaignMembers}" var="cm">
                <apex:column headerValue="PID">
                    <apex:outputLink value="https://na2.salesforce.com/{!cm.contactid}" target="_blank">{!cm.PID__c}</apex:outputLink>

               <apex:column value="{!cm.Contact.Account.name}"/>
               <apex:column value="{!cm.Contact.name}"/>
               <apex:column value="{!cm.Contact.phone}"/>
                <apex:column headerValue="Notes">
                    <apex:inputField value="{!cm.Notes__c}"  onchange="updateRecords();" />
                <apex:column headerValue="Status">
                    <apex:inputField value="{!cm.Status}"  onchange="updateRecords();" />
                <apex:column headerValue="Assign To Study">
                    <apex:outputText escape="false" value="{!cm.Add_To_Study__c}">
                <apex:column headerValue="Study">
                    <apex:outputLink value="https://na2.salesforce.com/{!cm.campaignid}" target="_blank">{!cm.Campaign.name}</apex:outputLink>
        <apex:actionStatus startText="Saving..." id="status"/>


public class callListController 
    private List<CampaignMember> CampaignMembers;

    public List<CampaignMember> getCampaignMembers() 
       return CampaignMembers;
    public void getData()
            Map<string,string> params = ApexPages.currentPage().getParameters();
            Id campaignId = params.get('campaignId');
            Id userId = params.get('userid');
            String query = 'Select Status, Add_To_Study__c, PID__c, Notes__c, Contact.Phone, Contact.Account.Name, Contact.Name, Campaign.name, Caller__c From CampaignMember where campaign.Status in (\'Recruiting\',\'Caller Recruit\') and campaign.isActive = true';
            if(userId != null)
                query += ' and caller__c = \'' + userId + '\'';
            if(campaignId != null)
                query += ' and campaignID = \'' + campaignId + '\'';
            query += ' Order By Contact.Account.name LIMIT 1000';
            CampaignMembers = Database.query(query);    

    public PageReference UpdateRecords()
        update CampaignMembers;
        return null;

As usual, any questions, hit me up in the comments. Hope this helps!

2 responses

  1. swati

    hi i am new to salesforce, i logged in to force.com via trial account created apps through wizards and added fields and data to the tabs but i cannot find how to get visualForce Editor and see xml content also how to link my app to Eclipse where i can code using apex.

    thank u

    May 10, 2011 at 9:44 am

  2. Hi – I need to implement exactly this functionality in my company but not sure how to actually do it. Would you mind describing in a few bullet points what I need to do to actually implement your solution in my SF instance? i.e.

    Step 1: Set up a Campaign with the following name: XYZ
    Step 2: …
    Step 3: Create a new VF page and copy the above code into it

    May 21, 2013 at 7:05 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s