You need to sign in to do that
Don't have an account?
jmburns
Is there no help for the widows son?
I have a visual force page and apex class for editing multiple records at once, I am trying to make a button that creates a new record...I have the save function working, but cannot figure out how to create a new record. Any help would be appreciated!
Apex Class:
public with sharing class BulkEdit { public List<Payment_History__c> payments; public Id thePH; // class constructor public BulkEdit() { thePH = ApexPages.currentPage().getParameters().get('id'); payments = getPayments(); } // get all the children for this Client__c public List<Payment_History__c> getPayments() { payments = [SELECT Name, Payment_Amount__c, Payment_Scheduled_Date__c, Payment_Cleared_Date__c, Payment_Status__c, Fee_Payment__C, Set_Payment__c, Processing_Fee__c FROM Payment_History__c WHERE Client__r.Id = :thePH]; return payments; } public PageReference back() { return new PageReference('/' + thePH); } // the Save button's method. This will update both the parent and children records. public PageReference savePayments() { update payments; payments = getPayments(); if (thePH == null) { return null; } Client__c phToUpdate = [ SELECT Id FROM Client__c WHERE Id = :thePH LIMIT 1]; update phToUpdate; //return new PageReference('/' + thePH); // refresh current page return ApexPages.currentPage(); } }
VF Page:
<apex:page controller="BulkEdit" tabStyle="Client__c"> <apex:form id="theForm"> <apex:pageBlock title="Payment Schedule" mode="edit"> <!-- our Save button tied to our Save method --> <apex:pageBlockButtons > <apex:commandButton action="{!savePayments}" value="Save"/> <apex:commandButton action="{!back}" value="Back to Client Record"/> </apex:pageBlockButtons> <!-- Here we create a table using the Visualforce tag <apex:pageBlockTable> {!payments} calls "getPayments" method in our controller. Note: the word "get" in accessor methods is implicit in Visualforce. We're also assigning a name variable of "currentPayment" for each accessed record. The IDs need to be present to perform the updates but we can keep them invisible to our user through rendered="false" --> <apex:pageBlockTable value="{!payments}" var="currentPayment" id="theRepeat"> <apex:outputText rendered="false">{!currentPayment.Client__r.Id}</apex:outputText> <apex:outputText rendered="false">{!currentPayment.Client__c}</apex:outputText> <!-- We create our columns, along with headers, for our user worksheet Depending on whether or not we want to allow the user to edit a field, we use the inputField or outputField tags. --> <apex:column ><apex:facet name="header">Name</apex:facet> <apex:outputField value="{!currentPayment.name}"/> </apex:column> <apex:column width="80px"><apex:facet name="header">Amount</apex:facet> <apex:inputField value="{!currentPayment.Payment_Amount__c}" style="width:80px"/> </apex:column> <apex:column ><apex:facet name="header">Sched Date</apex:facet> <apex:inputField value="{!currentPayment.Payment_Scheduled_Date__c}"/> </apex:column> <apex:column ><apex:facet name="header">Clear Date</apex:facet> <apex:inputField value="{!currentPayment.Payment_Cleared_Date__c}"/> </apex:column> <apex:column ><apex:facet name="header">Status</apex:facet> <apex:inputField value="{!currentPayment.Payment_Status__c}" style="{!IF((currentPayment.Payment_Status__c = 'Cleared'),'color:green','color:red')}"/> </apex:column> <apex:column ><apex:facet name="header">Processing Fee</apex:facet> <apex:inputField value="{!currentPayment.Processing_Fee__c}"/> </apex:column> <apex:column ><apex:facet name="header">Retainer Fee</apex:facet> <apex:inputField value="{!currentPayment.Fee_Payment__c}"/> </apex:column> <apex:column ><apex:facet name="header">Accumulation</apex:facet> <apex:inputField value="{!currentPayment.Set_Payment__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> <apex:iframe id="xyz" src="/apex/Bulk_Edit_Offer_Payments?id={!$CurrentPage.parameters.Id}"></apex:iframe> </apex:page>
I found this example which seems as if it should work but am having trouble getting it to, can some one please assist with adding this to my class
I think perhaps I am getting closer, getting error:
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Unit_Tests.cls Debt/src/classes line 23 Force.com run test failure
Here is the class with code added:
Here is the section of unit tests that is failing:
Thank you
I removed the test code from the test class and saved, this worked..except:
Now the add row functionality is working but the original functionality is not. (Display all Payment_History__c records associated with Client__c)