You need to sign in to do that
Don't have an account?

Custom Save Button - Capture the Parent Id and route to new Visualforce Page for adding Multiple Children
Need to route the user to a visualforce page for creating multiple child records on save of parent record.
Summary
What I want to have happen is when saving the Demographic, the user is immediately taken to the addQuotas page as if they had clicked the button on the detail page. I'm having difficulty making any of this work, trying custom buttons from the Opportunity and hacking the SaveURL, and I'm just not having luck saving the Demographic, grabbing the Id of that Demographic, and then going to the addQuotas page with that Demographic Id in tow.
What do I add to the Save action on the addDemographic visualforce page to then route to the addQuotas page for THAT Demographic?
Basically, I want on Save of Demographic to automatically go here: /apex/addQuotas?id={!Demographic__c.Id}&retURL={!Demographic__c.Id}
Code and Pictures:
addDemographic page
addQuotas page:
addQuotas Extenstion (grabbing details from Demographic parent):
View of the addQuotas page so you get the idea of the page:

Thank you in advance!!
Summary
- Three objects involved: Opportunity, Demographic, and Quota.
- One Opportunity has Many Demographics
- One Demographic has Many Quotas
- I've created a visualforce page where I add many Quotas to the Demographic at once. Currently this is launched from a custom button on the Demographic Detail Page.
- Page Name = addQuotas
- Page has a standard "add row"/"delete row" function to create a Quota record each row from custom controller
- I pass multipe details from the parent Demographic onto each Quota row through an extension
- I've created a visualforce page to override the standard new/edit Demographic layout so I can build a custom save button to route to the addQuotas page.
- Page Name = addDemographic, uses a standard controller, no extensions at the moment
What I want to have happen is when saving the Demographic, the user is immediately taken to the addQuotas page as if they had clicked the button on the detail page. I'm having difficulty making any of this work, trying custom buttons from the Opportunity and hacking the SaveURL, and I'm just not having luck saving the Demographic, grabbing the Id of that Demographic, and then going to the addQuotas page with that Demographic Id in tow.
What do I add to the Save action on the addDemographic visualforce page to then route to the addQuotas page for THAT Demographic?
Basically, I want on Save of Demographic to automatically go here: /apex/addQuotas?id={!Demographic__c.Id}&retURL={!Demographic__c.Id}
Code and Pictures:
addDemographic page
<apex:page standardController="Demographic__c" tabStyle="Demographic__c"> <apex:sectionHeader title="Edit Demographic" subtitle="New Demographic"/> <apex:form > <apex:pageBlock title="Edit Demograhic" mode="edit"> <apex:pageblockButtons > <apex:commandButton action="{!save}" value="Add Quotas"/> </apex:pageblockButtons> <apex:pageblockSection title="Demographic Information" columns="1"> <apex:inputfield value="{!Demographic__c.Opportunity__c}"/> <apex:inputfield value="{!Demographic__c.Qualification__c}"/> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
addQuotas page:
<apex:page standardController="Demographic__c" extensions="EditableQuotaListExtension" showHeader="true" sidebar="false" title="Edit Quota"> <apex:form > <apex:pageMessages id="messages"/> <apex:pageBlock title="Edit Quotas"> <apex:pageBlockButtons > <apex:commandButton value="Cancel" action="{!cancel}" /> <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Demographic Information" collapsible="false"> <apex:outputLink value="/{!Demographic__c.Id}" target="_blank">{!Demographic__c.Name}</apex:outputLink> <apex:pageBlockSectionItem > <apex:outputText value="{!Demographic__c.QualificationName__c}" /> <apex:outputText value="{!Demographic__c.Qualification_Text__c}" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockSection id="childList" columns="1" title="Quotas" collapsible="false"> <apex:variable var="rowNum" value="{!ZERO}" /> <apex:outputLabel value="No Quotas currently exist. Click below to Add." rendered="{!NOT(hasChildren)}"/> <apex:pageBlockTable value="{!children}" var="quota" rendered="{!hasChildren}"> <apex:column headerValue="Condition"> <apex:inputField value="{!quota.Condition__c}"/> </apex:column> <apex:column headerValue="Option"> <apex:inputField value="{!quota.Condition_Option__c}"/> </apex:column> <apex:column headerValue="Description"> <apex:inputField value="{!quota.Description__c}"/> </apex:column> <apex:column headerValue="Quota Amount"> <apex:inputField value="{!quota.Quota_Amount__c}" /> </apex:column> <apex:column headerValue="%/#"> <apex:inputField value="{!quota.Quota_Calculation_Type__c}"/> </apex:column> <apex:column headerValue="Demographic"> <apex:inputField value="{!quota.Demographic__c}"/> </apex:column> <apex:column headerValue="Qualification"> <apex:inputField value="{!quota.Qualification__c}"/> </apex:column> <apex:column headerValue=" "> <!-- This is the second half of the trick to keep track of your row index for deletion. --> <apex:variable var="rowNum" value="{!rowNum + 1}" /> <apex:commandLink value="Delete" action="{!removeFromList}" rerender="childList, messages" immediate="true"> <apex:param name="removeIndex" assignTo="{!removeIndex}" value="{!rowNum}" /> </apex:commandLink> </apex:column> </apex:pageBlockTable> <apex:commandButton value="Add Quota" action="{!addToList}" rerender="childList, messages" immediate="true" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
addQuotas Extenstion (grabbing details from Demographic parent):
public with sharing class EditableQuotaListExtension extends EditableQuotaList { public Demographic__c mydemo {get; private set;} public EditableQuotaListExtension(ApexPages.StandardController stdController) { super(stdController); this.mydemo = [SELECT Id, Name, Qualification__r.Name FROM Demographic__c WHERE Id =: stdController.getRecord().Id]; this.childList = [SELECT Id, Condition__c, Description__c, Quota_Amount__c, Quota_Calculation_Type__c, Condition_Option__c, Qualification__c, Demographic__c FROM Quota__c WHERE Demographic__c =: mysObject.Id]; } /* * This method is necessary for reference on the Visualforce page, * in order to reference non-standard fields. */ public List<Quota__c> getChildren() { return (List<Quota__c>)childList; } public override sObject initChildRecord() { Quota__c child = new Quota__c(); child.Demographic__c = mydemo.Id; child.Qualification__c = mydemo.Qualification__c; child.Quota_Amount__c = 100; child.Quota_Calculation_Type__c = '%'; return child; } }
View of the addQuotas page so you get the idea of the page:
Thank you in advance!!
You VF page would look something like the following:
All Answers
You VF page would look something like the following:
Sorry about that.
Visualforce Error
Formula Expression is required on the action attributes.
I'm assuming something I need to add to the extension for the addQuotas?
I tried just removing that line, which allowed me to save, but then the controller didn't work in terms of adding any rows of record to the visualforce page. If it helps at all, here is the controller for the addquotas page.
thank you thank you thank you again
Thank you so much!!!
I am trying to do the same and i am stuck with the same error
Compile Error: Incompatible argument type List<SObject> for All method on List<Issue_Line__c> at line 35 column 5
I am not able to fix this , Could you please let me know how you did this as i removed the visual force pagew where i has used action Saveand tried to save the controller and it still the class has not worked .
Thanks
Stll could not resolve this . Any help on this error message please. So close
children = new List<Issue_line__c>();
children.addALL(this.childList);
Compile Error: Incompatible argument type List<SObject> for All method on List<Issue_Line__c>
My guess is that you need to replace List<Issue_Line__c> with the parent object rather than the child, but without looking at the whole thing it's hard to guess. Thanks!
Thank you very very much for responding . If possible could you please look at this once. I have done exactly what was done above .
I tried changing that and it did not work. My parent object is case (Demographic__c) and child is issue line (Quote__c)
I have used the exact same code and I belive i have the same use case as you had with VF page for Parent and add mutiple child records
Parent VF (Case) Parent Controller Child VF ( Add mutiple child records Issue )
Child Controller
Child Controller Extension : In this i had the error same as you did Incompatible argument type List<SObject> for All method on List<Issue_Line__c>
Sorry for the long list of codes
And
I try to implement the same code but face another problem. When my children records are saved they are created correctly but are empty.
Any thought before I post my codes?
Thank you in advance for your help.
Sylvie
Not sure why it is that way. If you have used the above code it should not happen that way. It working perfectly for me . There might be a small thing you might have missed . Check it out and if you cant find it then post the code here .
Thanks
One precision, I am working in Lightning, always wonder if it is not the reason why it is not working.
My configuration: 3 Objects: Opportunity (parent), Fact_Finder__c (child), FFDriver__c (grandchild). All with Master-Detail relationship.
On my Opportunity detail page I have a Lightning Component with several buttons which open VF Pages (Fact_Finder__c) with different record types.
My problem is when I save the DriverForm (doSave) the records are created (Fact Finder with all infos and Driver with only the one in initChildRecord) but nothing that I put in other fields.
I have tried to simplify the code (taking out styles and many fields). Sorry it still very long….
VF PAGE (MotorForm) – child level
Extension (FFFormCtrExt)
VF PAGE (DriverForm) – grandchild level Extension (EditableDriverListExtension) Extend (EditableList)
Thank you in advance for your help.
Sylvie
I just relaised that even i have the same issue . Unless i eneter all the values for all the fieldsa in the Mutiple lines it does not save .
I've been trying to do this for the past week, but I'm not getting anywhere...
I have 2 custom objects and I am trying to get the child to be created on insert of parent.
I'm trying to creat an edit visualforce page, so that when I create a new Opportunity Positioning, I will, on the same page layout,be able to also create and save Buying Influence 1,2,3 etc. I know that I will have to override the 'new' button. for the Opportunity Positioning for the new visualforce page.
Any ideas of the best way to do this?
<apex:page standardcontroller="Opportunity_Positioning__c">
<apex:messages />
<apex:sectionheader title="{!$ObjectType.Opportunity_Positioning__c.label} Edit" subtitle="{!IF(ISNULL(Opportunity_Positioning__c.Name), 'New Strategic Client Opportunity Plan',Opportunity_Positioning__c.Name)}"/>
<apex:form >
<apex:pageblock mode="edit" title="{!$ObjectType.Opportunity_Positioning__c.label} Edit">
<apex:pageblockbuttons >
<apex:commandbutton value="Save" action="{!Save}"/>
<apex:commandbutton value="Cancel" action="{!Cancel}"/>
</apex:pageblockbuttons>
<!-- ********** [Record Type : Master ] ********** -->
<apex:outputpanel >
<apex:pageblocksection title="Information" showheader="true" columns="2">
<apex:inputfield value="{!Opportunity_Positioning__c.Name}" required="true"/>
<apex:pageblocksectionitem />
<apex:inputfield value="{!Opportunity_Positioning__c.Opportunity__c}" required="true"/>
<apex:pageblocksectionitem />
</apex:pageblocksection>
<apex:pageblocksection title="Summary of my position today" showheader="true" columns="2">
<apex:inputfield value="{!Opportunity_Positioning__c.Current_Status__c}" required="false"/>
<apex:inputfield value="{!Opportunity_Positioning__c.Key_Actions_Required__c}" required="false"/>
<apex:inputfield value="{!Opportunity_Positioning__c.Strengths__c}" required="false"/>
<apex:inputfield value="{!Opportunity_Positioning__c.Red_Flags__c}" required="false"/>
<apex:pageblocksectionitem />
<apex:inputfield value="{!Opportunity_Positioning__c.Adequacy_of_Current_Position__c}" required="false"/>
</apex:pageblocksection>
<apex:pageblocksection title="Competitive Positioning" showheader="true" columns="2">
<apex:inputfield value="{!Opportunity_Positioning__c.Position_vs_c__c}" required="false"/>
<apex:inputfield value="{!Opportunity_Positioning__c.Primary_Competitor__c}" required="false"/>
</apex:pageblocksection>
</apex:outputpanel>
</apex:pageblock>
</apex:form>
</apex:page>
and
apex:page standardcontroller="Buying_Influence__c">
<apex:messages />
<apex:sectionheader title="{!$ObjectType.Buying_Influence__c.label} Edit" subtitle="{!IF(ISNULL(Buying_Influence__c.Name), 'New Buying Influence',Buying_Influence__c.Name)}"/>
<apex:form >
<apex:pageblock mode="edit" title="{!$ObjectType.Buying_Influence__c.label} Edit">
<apex:pageblockbuttons >
<apex:commandbutton value="Save" action="{!Save}"/>
<apex:commandbutton value="Cancel" action="{!Cancel}"/>
</apex:pageblockbuttons>
<!-- ********** [Record Type : Master ] ********** -->
<apex:outputpanel >
<apex:pageblocksection title="Information" showheader="true" columns="2">
<apex:inputfield value="{!Buying_Influence__c.Name}" required="true"/>
<apex:inputfield value="{!Buying_Influence__c.SCOP__c}" required="true"/>
<apex:inputfield value="{!Buying_Influence__c.Name__c}" required="false"/>
<apex:pageblocksectionitem />
<apex:inputfield value="{!Buying_Influence__c.Buying_influence_role__c}" required="false"/>
<apex:pageblocksectionitem />
<apex:inputfield value="{!Buying_Influence__c.Degree_of_Influence__c}" required="true"/>
<apex:pageblocksectionitem />
<apex:inputfield value="{!Buying_Influence__c.Mode__c}" required="true"/>
<apex:pageblocksectionitem />
</apex:pageblocksection>
<apex:pageblocksection title="How well is based covered for this contact" showheader="true" columns="1">
<apex:inputfield value="{!Buying_Influence__c.Rating_for_base_covered__c}" required="true"/>
<apex:inputfield value="{!Buying_Influence__c.Evidence_to_support_your_rating__c}" required="false"/>
</apex:pageblocksection>
</apex:outputpanel>
</apex:pageblock>
</apex:form>