You need to sign in to do that
Don't have an account?
Jesse Wolff
Custom Object Save and New with Parameters on Custom Object
Hello - I have a custom object which when created, my users need to enter multiple child objects to. Currently there is a custom visualforce form which loads parameters into the URL to populate 2 mandatory fields on the child object, all of which come from the parent custom object.
The URL looks like this:
https://..../apex/myVFpage?Work_Order__c=a3To00000002Voj&Invoice__c=a3O1N000003WBkB
Once the information is entered, the user clicks "Save" and standard controller save action is used which returns them to the page for the newly created child record.
I have created a controller extension to execute a "Save and New", which works great, but does not populate the required fields. I need to grab the URL as listed above, and reload it for the "New" portion of the action. Below is my code:
public class saveAndnew {
public ApexPages.StandardController scMain{get;set;}
public saveAndnew(ApexPages.StandardController controller) {
scMain = controller;
}
public PageReference saveAndNew() {
scMain.save();
PageReference newInvoiceLinefromInv= new PageReference('/apex/newInvoiceLinefromInv');
newInvoiceLinefromInv.setRedirect(true);
return newInvoiceLinefromInv;
}
}
I'm certain there's a way to do this, but I'm spending way too much time on this and coming up empty. Any snippits of wisdom for me?
Thanks,
The URL looks like this:
https://..../apex/myVFpage?Work_Order__c=a3To00000002Voj&Invoice__c=a3O1N000003WBkB
Once the information is entered, the user clicks "Save" and standard controller save action is used which returns them to the page for the newly created child record.
I have created a controller extension to execute a "Save and New", which works great, but does not populate the required fields. I need to grab the URL as listed above, and reload it for the "New" portion of the action. Below is my code:
public class saveAndnew {
public ApexPages.StandardController scMain{get;set;}
public saveAndnew(ApexPages.StandardController controller) {
scMain = controller;
}
public PageReference saveAndNew() {
scMain.save();
PageReference newInvoiceLinefromInv= new PageReference('/apex/newInvoiceLinefromInv');
newInvoiceLinefromInv.setRedirect(true);
return newInvoiceLinefromInv;
}
}
I'm certain there's a way to do this, but I'm spending way too much time on this and coming up empty. Any snippits of wisdom for me?
Thanks,
All Answers
<apex:page standardController="Invoice_Line__c" extensions="DefaultFieldExtension,saveAndnew">
<apex:form >
<apex:pageBlock mode="detail" id="items" title="Billing Entry">
<apex:pageMessages />
// Pageblock stuff....
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton action="{!quicksave}" value="Get Price" />
<apex:commandButton action="{!saveAndnew}" value="Save and New"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>