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

Help using Standard Controller for Custom Object to create multiple custom object records from list button?
Hi all,
I am attempting to create a Visualforce page where users can add multiple child records at once. I want to add a list button to the related list on the parent object. Both are custom objects.
The parent object in this scenario Sessions__c and the child object is Class_Enrollments__c. Not sure if this is applicable, but Sessions__c is the child of Groups_and_Classes__c.
I am new to development, so I reworked some code based on code I found online. Basically, I want users to be able to click a "Add Class Enrollments" button on the Class Enrollments list. I want this to take them to a Visualforce page where they can add as many rows as needed, populating the Youth Name, Attendance, and Participation Note fields.
The code worked when I used the custom controller. However, when I tried to add the list button, I realized that it was not available in Content because I used a custom controller. I tried to amend the code for the Standard Controller, but I keep getting errors. Here is my original code:
<apex:page controller="AddingEnrollmentsController">
<apex:form >
<apex:variable var="rowNum" value="{!0}" />
<apex:pageBlock >
<apex:variable var="rowNum" value="{!0}" />
<apex:pageBlockTable value="{!Class_EnrollmentsList}" var="CE">
<apex:facet name="footer">
<apex:commandLink value="Add" action="{!insertRow}"/>
</apex:facet>
<apex:column headerValue="Youth Name">
<apex:inputField value="{!CE.Youth_Name__c}"/>
</apex:column>
<apex:column headerValue="Attendance">
<apex:inputField value="{!CE.Attendedance__c}"/>
</apex:column>
<apex:column headerValue="Participation Notel">
<apex:inputField value="{!CE.Participation_Note__c}"/> <apex:column headerValue="Delete" >
<apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
<apex:param value="{!rowNum}" name="index" />
</apex:commandLink>
<apex:variable var="rowNum" value="{!rowNum+1}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!insertClass_Enrollments}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class AddingEnrollmentsController {
Id SessionId;
public List<Class_Enrollments__c> Class_EnrollmentsList {get;set;}
public Integer rowNum{get;set;}
public AddingEnrollmentsController(){
SessionId = ApexPages.currentPage().getParameters().get('SessionId');
Class_EnrollmentsList = new List<Class_Enrollments__c>();
Class_EnrollmentsList.add(new Class_Enrollments__c());
}
public void insertClass_Enrollments(){
insert Class_EnrollmentsList;
}
public void insertRow(){
Class_EnrollmentsList.add(new Class_Enrollments__c());
}
public void delRow(){
rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
Class_EnrollmentsList.remove(rowNum);
}
}
When previewing this, it looks great, except the delete doesn't work.
When I try to update it to the Standard Controller, however, I get this error:
Error: Unknown property 'Class_Enrollments__cStandardController.classenrollmentsList'
I have tried formatting that list element every way I can imagine (Class_EnrollmentsList, Class_Enrollments__cList, Class_Enrollments__c_List, etc.), and it still won't work.
Here is the updated code:
<apex:page standardController="Class_Enrollments__c" recordSetVar="classenrollments">
<apex:form >
<apex:variable var="rowNum" value="{!0}" />
<apex:pageBlock >
<apex:variable var="rowNum" value="{!0}" />
<apex:pageBlockTable value="{!classenrollmentsList}" var="CE">
<apex:facet name="footer">
<apex:commandLink value="Add" action="{!insertRow}"/>
</apex:facet>
<apex:column headerValue="Youth Name">
<apex:inputField value="{!CE.Youth_Name__c}"/>
</apex:column>
<apex:column headerValue="Attendance">
<apex:inputField value="{!CE.Attendedance__c}"/>
</apex:column>
<apex:column headerValue="Participation Notel">
<apex:inputField value="{!CE.Participation_Note__c}"/>
<apex:column headerValue="Delete" >
<apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
<apex:param value="{!rowNum}" name="index" />
</apex:commandLink>
<apex:variable var="rowNum" value="{!rowNum+1}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!insertclassenrollments}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Help?? I'm so new to this that I'm not sure what I am doing wrong. Any help is appreciated!
I am attempting to create a Visualforce page where users can add multiple child records at once. I want to add a list button to the related list on the parent object. Both are custom objects.
The parent object in this scenario Sessions__c and the child object is Class_Enrollments__c. Not sure if this is applicable, but Sessions__c is the child of Groups_and_Classes__c.
I am new to development, so I reworked some code based on code I found online. Basically, I want users to be able to click a "Add Class Enrollments" button on the Class Enrollments list. I want this to take them to a Visualforce page where they can add as many rows as needed, populating the Youth Name, Attendance, and Participation Note fields.
The code worked when I used the custom controller. However, when I tried to add the list button, I realized that it was not available in Content because I used a custom controller. I tried to amend the code for the Standard Controller, but I keep getting errors. Here is my original code:
<apex:page controller="AddingEnrollmentsController">
<apex:form >
<apex:variable var="rowNum" value="{!0}" />
<apex:pageBlock >
<apex:variable var="rowNum" value="{!0}" />
<apex:pageBlockTable value="{!Class_EnrollmentsList}" var="CE">
<apex:facet name="footer">
<apex:commandLink value="Add" action="{!insertRow}"/>
</apex:facet>
<apex:column headerValue="Youth Name">
<apex:inputField value="{!CE.Youth_Name__c}"/>
</apex:column>
<apex:column headerValue="Attendance">
<apex:inputField value="{!CE.Attendedance__c}"/>
</apex:column>
<apex:column headerValue="Participation Notel">
<apex:inputField value="{!CE.Participation_Note__c}"/> <apex:column headerValue="Delete" >
<apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
<apex:param value="{!rowNum}" name="index" />
</apex:commandLink>
<apex:variable var="rowNum" value="{!rowNum+1}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!insertClass_Enrollments}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class AddingEnrollmentsController {
Id SessionId;
public List<Class_Enrollments__c> Class_EnrollmentsList {get;set;}
public Integer rowNum{get;set;}
public AddingEnrollmentsController(){
SessionId = ApexPages.currentPage().getParameters().get('SessionId');
Class_EnrollmentsList = new List<Class_Enrollments__c>();
Class_EnrollmentsList.add(new Class_Enrollments__c());
}
public void insertClass_Enrollments(){
insert Class_EnrollmentsList;
}
public void insertRow(){
Class_EnrollmentsList.add(new Class_Enrollments__c());
}
public void delRow(){
rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
Class_EnrollmentsList.remove(rowNum);
}
}
When previewing this, it looks great, except the delete doesn't work.
When I try to update it to the Standard Controller, however, I get this error:
Error: Unknown property 'Class_Enrollments__cStandardController.classenrollmentsList'
I have tried formatting that list element every way I can imagine (Class_EnrollmentsList, Class_Enrollments__cList, Class_Enrollments__c_List, etc.), and it still won't work.
Here is the updated code:
<apex:page standardController="Class_Enrollments__c" recordSetVar="classenrollments">
<apex:form >
<apex:variable var="rowNum" value="{!0}" />
<apex:pageBlock >
<apex:variable var="rowNum" value="{!0}" />
<apex:pageBlockTable value="{!classenrollmentsList}" var="CE">
<apex:facet name="footer">
<apex:commandLink value="Add" action="{!insertRow}"/>
</apex:facet>
<apex:column headerValue="Youth Name">
<apex:inputField value="{!CE.Youth_Name__c}"/>
</apex:column>
<apex:column headerValue="Attendance">
<apex:inputField value="{!CE.Attendedance__c}"/>
</apex:column>
<apex:column headerValue="Participation Notel">
<apex:inputField value="{!CE.Participation_Note__c}"/>
<apex:column headerValue="Delete" >
<apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
<apex:param value="{!rowNum}" name="index" />
</apex:commandLink>
<apex:variable var="rowNum" value="{!rowNum+1}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!insertclassenrollments}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Help?? I'm so new to this that I'm not sure what I am doing wrong. Any help is appreciated!