You need to sign in to do that
Don't have an account?
Kenji775
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; } }
If you use input fieds in between apex column tag then you can just update the list.
Something like below
Try out the sample code given below :
Public void UpdateRecords()
{
For(CampaignMember cm:CampaignMembers)
{
update cm;
}
}
Hope this helps.
Can you change following code stuff and try:
Change to:
-Suresh
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?
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.
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!
Can you post your working code?
Sure
Controller
VF Page