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

Creating Multiple Child Records Input Screen - Pass Multiple Values from Parent in PageReference
I have two objects - Demographics and Quotas. Both objects also have a lookup to a third object called Qualification. I have used Visualforce and Apex to create a multi-entry screen for adding multiple Quotas to a Demographic at once. I have successfullly passed the Demographics Id directly into the Demographics lookup by using both the controller and the custom button URL. I haven't figured out yet what to write in the controller to pass a second parameter from the URL into the input field. I tried a few things, but just removed them since they weren't working. Below is what I'm working with.
Objects
Demographic: Demographic__c
Quota: Quota__c
Qualification: Qualification_Library__c
Fields
The Qualification field on both Demographics and Quotas is Qualification__c
Visualforce Page
Button
(URL)
Any help in getting that qualification id to populate in the Qualification__c field for each row would be much appreciated
Here's what it looks like in action, just need that one field autofilled!

Objects
Demographic: Demographic__c
Quota: Quota__c
Qualification: Qualification_Library__c
Fields
The Qualification field on both Demographics and Quotas is Qualification__c
Visualforce Page
<apex:page controller="addDemoController" tabstyle="Quota__c"> <apex:form > <apex:pageBlock title="Define Demographic Quotas"> <apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable"> <apex:column headerValue="IDent" rendered="false"> <apex:outputText value="{!wrapper.ident}"/> </apex:column> <apex:column headerValue="Condition"> <apex:inputField value="{!wrapper.quota.Condition__c}"/> </apex:column> <apex:column headerValue="Option"> <apex:inputField value="{!wrapper.quota.Condition_Option__c}"/> </apex:column> <apex:column headerValue="Demographic"> <apex:inputField value="{!wrapper.quota.Demographic__c}"/> </apex:column> <apex:column headerValue="Qualification"> <apex:inputField value="{!wrapper.quota.Qualification__c}"/> </apex:column> <apex:column headerValue="Action"> <apex:commandButton value="Delete" action="{!delWrapper}" rerender="wtable"> <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/> </apex:commandButton> </apex:column> </apex:pageBlockTable> <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable"> <apex:param name="addCount" value="1" assignTo="{!addCount}"/> </apex:commandButton> <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlock> </apex:form> </apex:page>Apex Class
public class addDemoController { public List<quotaWrapper> wrappers {get; set;} public static Integer toDelIdent {get; set;} public static Integer addCount {get; set;} private Integer nextIdent=0; public addDemoController() { wrappers=new List<quotaWrapper>(); for (Integer idx=0; idx<1; idx++) { wrappers.add(new quotaWrapper(nextIdent++)); } } public void delWrapper() { Integer toDelPos=-1; for (Integer idx=0; idx<wrappers.size(); idx++) { if (wrappers[idx].ident==toDelIdent) { toDelPos=idx; } } if (-1!=toDelPos) { wrappers.remove(toDelPos); } } public void addRows() { for (Integer idx=0; idx<addCount; idx++) { wrappers.add(new quotaWrapper(nextIdent++)); } } public PageReference save() { Id eventId; eventId = ApexPages.currentPage().getParameters().get('eventId'); List<Quota__c> quotas=new List<Quota__c>(); for (quotaWrapper wrap : wrappers) { quotas.add(wrap.quota); } insert quotas; return new PageReference('/' + ApexPages.currentPage().getParameters().get('eventId')); } public class quotaWrapper { public Quota__c quota {get; private set;} public Integer ident {get; private set;} public quotaWrapper(Integer inIdent) { ident=inIdent; quota=new Quota__c(Demographic__c =ApexPages.currentPage().getParameters().get('eventId')); } } }
Button
(URL)
/apex/AddQuotaSelect?eventId={!Demographic__c.Id}
Any help in getting that qualification id to populate in the Qualification__c field for each row would be much appreciated
Here's what it looks like in action, just need that one field autofilled!
Here's the final code if anyone is interested or has suggestions on a cleaner, shorter, more efficient way to write it
All Answers
public class addDemoController
{
public List<quotaWrapper> wrappers {get; set;}
public static Integer toDelIdent {get; set;}
public static Integer addCount {get; set;}
private Integer nextIdent=0;
public addDemoController()
{
wrappers=new List<quotaWrapper>();
Id eventId = ApexPages.currentPage().getParameters().get('eventId')
Id qualLibraryId = null;
for(Demographic__c demo:[Select id ,Qualification_Library__c from Demographic__c where id = eventId]){
qualLibraryId = demo.Qualification_Library__c;
}
for (Integer idx=0; idx<1; idx++)
{
wrappers.add(new quotaWrapper(nextIdent++));
}
}
public void delWrapper()
{
Integer toDelPos=-1;
for (Integer idx=0; idx<wrappers.size(); idx++)
{
if (wrappers[idx].ident==toDelIdent)
{
toDelPos=idx;
}
}
if (-1!=toDelPos)
{
wrappers.remove(toDelPos);
}
}
public void addRows()
{
for (Integer idx=0; idx<addCount; idx++)
{
wrappers.add(new quotaWrapper(nextIdent++));
}
}
public PageReference save()
{
Id eventId;
eventId = ApexPages.currentPage().getParameters().get('eventId');
List<Quota__c> quotas=new List<Quota__c>();
for (quotaWrapper wrap : wrappers)
{
quotas.add(wrap.quota);
}
insert quotas;
return new PageReference('/' +eventId);
}
public class quotaWrapper
{
public Quota__c quota {get; private set;}
public Integer ident {get; private set;}
public quotaWrapper(Integer inIdent)
{
ident=inIdent;
quota=new Quota__c(Demographic__c = eventId,Qualification_Library__c = qualLibraryId);
}
}
}
Unfortunately this has not worked yet. There were a few errors (colon needed here, semi colon there, and the field is Qualification__c for the objects). Once I got those sorted, I got this error: Error: addDemoController Compile Error: Variable does not exist: eventId at line 73 column 44
Here's an image of the screen
And the updated code
Thoughts?
Here's the final code if anyone is interested or has suggestions on a cleaner, shorter, more efficient way to write it