You need to sign in to do that
Don't have an account?
Andrew Hoban 14
Visualforce Quick Save not working
Hi all,
I have a visualforce page that works great, however i need to implement a quick save button for users to quickly save the fields without having to refresh the page. I have used the standard quick save command button "<apex:commandButton value="Quick Save" action="{!QuickSave}"/>" however when the button is clicked the records are not saved. I have created a custom controller so im not sure if I need to reference the button inside it.
Many thanks
Controller:
VF Page:
I have a visualforce page that works great, however i need to implement a quick save button for users to quickly save the fields without having to refresh the page. I have used the standard quick save command button "<apex:commandButton value="Quick Save" action="{!QuickSave}"/>" however when the button is clicked the records are not saved. I have created a custom controller so im not sure if I need to reference the button inside it.
Many thanks
Controller:
public class IncidentLogPopup { public List<Incident_Log__c> memberList {get;set;} public List<Incident_Log__c> memberAddList {get;set;} public String memberName {get;set;} public string searchstring {get;set;} public PageReference cancel() { return null; } public IncidentLogPopup() { } public IncidentLogPopup(ApexPages.StandardController controller) { String sql = 'SELECT Match_Day_Ops__c, Date_Time__c, Date_Closed__c, Type__c, Priority__c, Incident__c, Reported_to__c, Reported_By__c, Opened_Closed_Status__c FROM Incident_Log__c'; memberList = Database.Query(sql); memberAddList = new List<Incident_Log__c>(); memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now())); } public void AddRow() { memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now())); } Public Pagereference Save(){ insert memberAddlist; PageReference page = new Pagereference('/a0G/o'); page.setRedirect(true); return page; } }
VF Page:
<apex:page sidebar="false" StandardController="Match_Day_Ops__c" extensions="IncidentLogPopup"> <style type = "text/css"> .colHeadr {text-align:center;} </style> <apex:form > <apex:pageBlock title="Incident Log {!$ObjectType.Match_Day_Ops__c.Fields.Name.Label}" id="membAdd" > <apex:pageBlockButtons location="Both"> <apex:commandButton value="Save" Action="{!save}" /> <apex:commandButton value="Quick Save" action="{!QuickSave}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageblockSection > <apex:pageBlockTable style="width:100%" value="{!memberAddList}" var="memb"> <apex:column headerValue="Match Day Ops" headerClass="colHeadr"> <apex:inputField value="{!memb.Match_Day_Ops__c}" style="width:325px" /> </apex:column> <apex:column headerValue="Type" headerClass="colHeadr"> <apex:inputField value="{!memb.Type__c}"/> </apex:column> <apex:column headerValue="Priority" headerClass="colHeadr"> <apex:inputField value="{!memb.Priority__c}"/> </apex:column> <apex:column headerValue="Date/Time Opened" headerClass="colHeadr"> <apex:inputField value="{!memb.Date_Time__c}"/> </apex:column> <apex:column headerValue="Incident Open" headerClass="colHeadr"> <apex:inputField value="{!memb.Incident__c}" style="width: 200px; height: 80px"/> </apex:column> <apex:column headerValue="Date/Time Closed" headerClass="colHeadr"> <apex:inputField value="{!memb.Date_Closed__c}"/> </apex:column> <apex:column headerValue="Incident Closed" headerClass="colHeadr"> <apex:inputField value="{!memb.Incident_Closed__c}" style="width: 200px; height: 80px"/> </apex:column> <apex:column headerValue="Reported To" headerClass="colHeadr"> <apex:inputField value="{!memb.Reported_To__c}"/> </apex:column> <apex:column headerValue="Reported By" headerClass="colHeadr"> <apex:inputField value="{!memb.Reported_By__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageblockSection> <apex:pageblockSection columns="1" > <apex:pageblockSectionItem > <apex:commandLink value="Add Row" action="{!addRow}" reRender="membAdd" /> </apex:pageblockSectionItem> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
upsert is combination of update and insert, which menas if id exists update if does not then insert.
It will update the record once it has the Id.
All Answers
"System.DmlException: Insert failed. First exception on row 0 with id a1Nf0000000lUuoEAE; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Error is in expression '{!QuickSave}' in component <apex:commandButton> in page incidentlogtest: Class.IncidentLogPopup.quickSave: line 43, column 1
Class.IncidentLogPopup.quickSave: line 43, column 1"
I think this is because the fields are trying to be overwritten and is causing the error. Is there a way around this problem at all?
upsert is combination of update and insert, which menas if id exists update if does not then insert.
It will update the record once it has the Id.