function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kenji775Kenji775 

Saving from a list view

Hey all,

Made a lot of progress, and I'm almost there, just one last hitch. I am basically trying to emulate the inline editing in a list view posted about here.

 

http://salesforcesource.blogspot.com/2009/01/allow-mass-update-of-your-object.html

 

I have the list working, and the save event looks like it fires, but the changed data is not commited to the database. The ajax region updates, and no errors are tossed, but no data is commited. Any thoughts as to why? Below is my code.

 

 

Visualforce page

 

 

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

          <!-- To show page level messages -->
          <apex:pageMessages ></apex:pageMessages>        
            <apex:pageBlockButtons >
                <apex:actionFunction action="{!UpdateRecords}" rerender="pageBlock" status="status"></apex:actionFunction>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!CampaignMembers}" var="cm">
                <apex:column value="{!cm.PID__c}"/>
                <apex:column value="{!cm.Caller__c}"/>
                <apex:column value="{!cm.Contact.phone}"/>
                <apex:column headerValue="Status">
                    <apex:inputField value="{!cm.Status}"/>
                </apex:column>
                <apex:column headerValue="Assign To Study">
                    <apex:outputText escape="false" value="{!cm.Add_To_Study__c}">
                    </apex:outputText>
                </apex:column>    
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:actionStatus startText="Saving..."/>
    </apex:form>    
</apex:page>

 

Controller

 

 

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');
                
                

        CampaignMembers = [Select Token__c, 
                                          SystemModstamp, 
                                          Status, 
                                          Quick_Log_Call__c, 
                                          PID__c, 
                                          Orginization_Name__c, 
                                          LeadId, 
                                          LastModifiedDate, 
                                          LastModifiedById, 
                                          Id, 
                                          IVR_Contact_Attempts__c, 
                                          HasResponded, 
                                          FirstRespondedDate, 
                                          CreatedDate, 
                                          CreatedById, 
                                          ContactId,
                                          Contact.Phone, 
                                          CampaignId, 
                                          Caller__c, 
                                          Add_To_Study__c 
                                          From CampaignMember
                                          where caller__c = :userId and
                                          campaignID = :campaignId];          
    }

    public PageReference UpdateRecords()
    {
        update CampaignMembers;
        system.debug('Saving....');
        return null;
    }    
}

 

 

hisrinuhisrinu

If you use input fieds in between apex column tag then you can just update the list.

 

Something like below

 

<apex:column>
<apex:inputfield value="{!cm.PID__c}"/>
</apex:column>
Pradeep_NavatarPradeep_Navatar

Try out the sample code given below :

 

                                   Public void UpdateRecords()

                                   {

                                     For(CampaignMember cm:CampaignMembers)

                                                 {

                                                   update cm;

                                                 }

                                   }

 

Hope this helps.

SSRS2SSRS2

Can you change following code stuff and try:

<apex:pageBlockButtons >
<apex:actionFunction action="{!UpdateRecords}" rerender="pageBlock" status="status"></apex:actionFunction>
</apex:pageBlockButtons>

Change to:

 

<apex:pageBlockButtons >    
<apex:commandButton > <apex:actionsupport action="{!UpdateRecords}" event="onclick"/> </apex:commandButton >
</apex:pageBlockButtons >

-Suresh

 

 

Kenji775Kenji775

Everyone, thank you for your input. I did try everyones suggestions and didn't really have any change. However I do have a bit more information. Apperantly the records are being changed, because I see the datelastmodified stamp being updated on the record I am attempting to save. So it looks like rather than the record just not saving, it just isn't passing the new information. So when I change the value of the status field, it calls update records, but update records is just updating with the same information it already had, not the information present in the form. Do I somehow need to manually tell the campaignMember list (the one in the heap) to update from the form, before commiting the list to the DB?

Kenji775Kenji775

Further development, other fields do save. I added a text one called notes, and that infact does save. So it's something about the picklist that is causing the value to not save.

Kenji775Kenji775

Okay, now it's working. I have no idea what the change was, maybe it was just a bad cache or soemthing, but it works now. Thanks everyone!

sravanthi_84sravanthi_84

Can you post your working code?

Kenji775Kenji775

Sure

 

Controller

 

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;
    }    
}

 

 

VF 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>

               <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>    
                
                <apex:column headerValue="Status">
                    <apex:inputField value="{!cm.Status}"  onchange="updateRecords();" />
                </apex:column>
                <apex:column headerValue="Assign To Study">
                    <apex:outputText escape="false" value="{!cm.Add_To_Study__c}">
                    </apex:outputText>
                </apex:column>    
                
                <apex:column headerValue="Study">
                    <apex:outputLink value="https://na2.salesforce.com/{!cm.campaignid}" target="_blank">{!cm.Campaign.name}</apex:outputLink>
                </apex:column>                  
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:actionStatus startText="Saving..." id="status"/>
    </apex:form>    
</apex:page>