• James Burnett
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am new to apex coding, and I working on a pro-bono project for a non-profit. I am having a problem writing a working test for an apex class and VF page combination that I truly believe is working as intended (tested in Sandbox - not verified by apex test class). I was hoping someone could help me clean up this test class so that I can get this function deployed.  

Here's what I have so far - 

VF Page:

<apex:page controller="AddMultipleAttendanceController" >
    
    <apex:form >
    
    <apex:pageBlock >
    
        <apex:pageBlockTable value="{!listAttendances}" var="Att">
        
            <apex:column headerValue="Client">
                <apex:inputField value="{!Att.Client__c}"/>
            </apex:column>
        
            <apex:column headerValue="Program Name">
                <apex:inputField value="{!Att.Program__c}"/>
            </apex:column>

            <apex:column headerValue="Session Week">
                <apex:inputField value="{!Att.Session__c}"/>
            </apex:column>
      
        </apex:pageBlockTable>

    <apex:pageBlockButtons >
    
        <apex:commandButton value="Add Attendances Row" action="{!addAttendance}"/>

        <apex:commandButton value="Save Attendances" action="{!saveAttendance}"/>

    </apex:pageBlockButtons>

    </apex:pageBlock>
    
</apex:form>
</apex:page>


Here is the Apex Class:

public class AddMultipleAttendanceController
{   
    Attendance__c enrollment = new Attendance__c();
     
    public List<Attendance__c> listAttendances { get; set; } 
         
    public AddMultipleAttendanceController()
    {
    listAttendances= new list<Attendance__c>();
    listAttendances.add(enrollment);
    }
    
    Public void addAttendance()
    {
    Attendance__c Att = new Attendance__c();
    listAttendances.add(Att);
    }
    public PageReference saveAttendance() {
    for(Integer i=0; i<listAttendances.size(); i++)
    {
    insert listAttendances;
    }
    return Page.Allitemssaved;
    }   
}

I cannot manage, however, to get a test class to work. I was planning on just using a single object item to test it, but maybe that wasn't working. Can anyone help me with this?

Here is all that I have managed to code for the test class (like I said, novice):

@isTest
public class AddMultipleAttendanceControllerTests {

    Private Static testmethod void AddMulitipleAttendanceControllerTests() {
        Attendance__c objAttendance = new Attendance__c();
        objAttendance.Client__c = 'a0v5B000000AHni';
        objAttendance.Program__c = 'a105B00000002j9';
        objAttendance.Session__c = 'a135B0000000MwN';
        insert objAttendance;

I would really appreciate any help with this. I'm sure there are people out there that could do this in just a few moments, but I lack the skill. Any documentation that you could add explaining the steps that I am missing would be extremely helpful. Thanks.

 
I am new to apex coding, and I working on a pro-bono project for a non-profit. I am having a problem writing a working test for an apex class and VF page combination that I truly believe is working as intended (tested in Sandbox - not verified by apex test class). I was hoping someone could help me clean up this test class so that I can get this function deployed.  

Here's what I have so far - 

VF Page:

<apex:page controller="AddMultipleAttendanceController" >
    
    <apex:form >
    
    <apex:pageBlock >
    
        <apex:pageBlockTable value="{!listAttendances}" var="Att">
        
            <apex:column headerValue="Client">
                <apex:inputField value="{!Att.Client__c}"/>
            </apex:column>
        
            <apex:column headerValue="Program Name">
                <apex:inputField value="{!Att.Program__c}"/>
            </apex:column>

            <apex:column headerValue="Session Week">
                <apex:inputField value="{!Att.Session__c}"/>
            </apex:column>
      
        </apex:pageBlockTable>

    <apex:pageBlockButtons >
    
        <apex:commandButton value="Add Attendances Row" action="{!addAttendance}"/>

        <apex:commandButton value="Save Attendances" action="{!saveAttendance}"/>

    </apex:pageBlockButtons>

    </apex:pageBlock>
    
</apex:form>
</apex:page>


Here is the Apex Class:

public class AddMultipleAttendanceController
{   
    Attendance__c enrollment = new Attendance__c();
     
    public List<Attendance__c> listAttendances { get; set; } 
         
    public AddMultipleAttendanceController()
    {
    listAttendances= new list<Attendance__c>();
    listAttendances.add(enrollment);
    }
    
    Public void addAttendance()
    {
    Attendance__c Att = new Attendance__c();
    listAttendances.add(Att);
    }
    public PageReference saveAttendance() {
    for(Integer i=0; i<listAttendances.size(); i++)
    {
    insert listAttendances;
    }
    return Page.Allitemssaved;
    }   
}

I cannot manage, however, to get a test class to work. I was planning on just using a single object item to test it, but maybe that wasn't working. Can anyone help me with this?

Here is all that I have managed to code for the test class (like I said, novice):

@isTest
public class AddMultipleAttendanceControllerTests {

    Private Static testmethod void AddMulitipleAttendanceControllerTests() {
        Attendance__c objAttendance = new Attendance__c();
        objAttendance.Client__c = 'a0v5B000000AHni';
        objAttendance.Program__c = 'a105B00000002j9';
        objAttendance.Session__c = 'a135B0000000MwN';
        insert objAttendance;

I would really appreciate any help with this. I'm sure there are people out there that could do this in just a few moments, but I lack the skill. Any documentation that you could add explaining the steps that I am missing would be extremely helpful. Thanks.