0

a student__c has teacher_set__c field, each teacher is assigned in a teacher_set__c so meaning, 1 student = many teachers. now, i have a picklist of students, when i choose in the picklist, the pageblocktable will be updated showing the teachers with the same teacherset. This code compiles but it does not return expected result. what might be wrong? please help. thanks in advance.

VFP

<apex:page controller="PTCSchedulerCX"  sidebar="false" showHeader="false" docType="html-5.0">
    <!--<style>
.datelabel{
float: right;
margin-right: 200px; 
}
</style>-->
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <title>PTC Scheduler</title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0" />


            <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
        </head>

        <body>

            <apex:form >
                <div class="container">
                    <apex:pageBlock >



                    </apex:pageBlock>
                </div> 
            </apex:form>

            <apex:form >
                <div class="container">

                    <apex:pageBlock >
                        <div>         
                            <apex:outputLabel style="margin-left: 55px;">DELGADO, PAULO</apex:outputLabel>
                            <apex:outputLabel style="float: right; margin-right: 100px;" value="{!day}" ></apex:outputLabel>
                        </div>      

                    </apex:pageBlock>
                </div>
            </apex:form>

            <apex:form >
                <div class="container">
                    <apex:pageBlock >            
                        <div>    
                            <apex:outputLabel style="margin-left: 55px;">Select Student:</apex:outputLabel>
                            <apex:selectList size="1" style="margin-left: 5px;">
                                <apex:selectOptions value="{!SNames}"></apex:selectOptions>
                                <apex:actionSupport event="onclick" reRender="teacherBlock" action="{!fetchTeacherInfo}" >
                                    <apex:param id="studentId" name="studentId" value="{!sNames}" assignTo="{!selectedSid}"/>
                                </apex:actionSupport>

                            </apex:selectList>
                        </div>                 
                    </apex:pageBlock>            
                </div> 
            </apex:form>



            <apex:form >            
                <div class="container">                
                    <apex:pageBlock id="teacherBlock">    
                        <div style="margin-top: 10px; padding: 45px;"> 
                            <apex:pageBlockTable value="{!WrapTS}" var="item">
                                <apex:column headerValue="Teacher" value="{!item.t1.First_Name__c} {!item.t1.Name}"/>
                                <apex:column headerValue="Subject" value="{!item.t1.Subject__c}"/>
                                <apex:column headerValue="Room" value="{!item.t1.Room_Assignment__c}"/>
                                <apex:column headerValue="Time">
                                    <apex:selectList size="1">
                                        <apex:selectOption itemValue=""></apex:selectOption>
                                        <apex:selectOption itemValue="9AM-10AM"></apex:selectOption>
                                        <apex:selectOption itemValue="10AM-11AM"></apex:selectOption>
                                        <apex:selectOption itemValue="11AM-12PM"></apex:selectOption>
                                        <apex:selectOption itemValue="12PM-1PM"></apex:selectOption>
                                        <apex:selectOption itemValue="1PM-2PM"></apex:selectOption>
                                        <apex:selectOption itemValue="2PM-3PM"></apex:selectOption>
                                        <apex:selectOption itemValue="3PM-4PM"></apex:selectOption>
                                        <apex:selectOption itemValue="4PM-5PM"></apex:selectOption> 
                                    </apex:selectList>
                                </apex:column>
                                <apex:column >
                                    <!--<apex:inputCheckbox value="{!item.check}"/>-->
                                </apex:column>
                            </apex:pageBlockTable>
                        </div>
                    </apex:pageBlock>
                </div>
            </apex:form>            

            <apex:form >         
                <div class="container" align="right"> 
                    <apex:pageBlock >    
                        <div style="margin-right: 50px;">       
                            <apex:commandButton styleClass="btn btn-primary" value="Proceed to Next Student"/>
                            <apex:commandButton styleClass="btn btn-primary" value="Proceed"/>
                        </div>
                    </apex:pageBlock>       
                </div>
            </apex:form>         
            <script src="https://code.jquery.com/jquery.js"></script>
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.js"></script> 
        </body> 

    </html>     
</apex:page>

Controller

    public with sharing class PTCSchedulerCX{
    public set<ID> teachers = new set<ID>(); 
    public Id selectedSId                        {get;set;}
    public string teacherSet                     {get;set;}
    private map<Id, teacher__c> mapTeacher = new map<Id, teacher__c>();
    private map<Id, student__c> mapStudent = new map<Id, student__c>();
    String day = '';

    public String getDay(){
        Datetime dt = System.now();
        day = dt.format('EEEE, MMMM d, YYYY');
        return day;
    }   


    public List<selectOption> getsNames(){

        List<selectOption> options = new List<selectOption>(); 

        for(Parent__c p : [Select Id, Name, First_Name__c, (Select Id, First_Name__c, Name from Students__r) 
                           from Parent__c WHERE Name = 'Delgado']){
                               for(Student__c stud : p.Students__r){
                                   selectedSId = stud.Id;    
                                   options.add(new selectOption(stud.First_Name__c, stud.First_Name__c + ' ' + stud.Name));
                               }
                           }
        return options;

    }

    public List<WrapperClass> wrapTS{get; set;}

    public PTCSchedulerCX(){
        mapStudent = new Map<Id, student__c>();
        wrapTS = new List<WrapperClass>();

        for(Schedule__c p : [Select Id, Name, Subject__c, Teacher__c, Time__c from Schedule__c]){
            wrapTS.add(new WrapperClass(p));
        }
       for(student__c s:[Select Id, Name, First_Name__c, middle_name__c, teacher_set__c, Parent__c from student__c LIMIT 1 ]){
           if(!mapStudent.containsKey(s.Id)){
                   mapStudent.put(s.Id, s);
                       }

        }

        }

    public class WrapperClass{
        public Teacher__c t1{get; set;}
        public Schedule__c p1{get; set;}
        public student__c s1{get;set;}

        public WrapperClass(Teacher__c myTeacher){     
            t1 = myTeacher;
        }

        public WrapperClass(Schedule__c p){
            p1 = p;
        }
        public WrapperClass(student__c s){
            s1=s;
        }
    }


    public void fetchTeacherInfo(){



        if(mapStudent.containsKey(selectedSId)){
            mapStudent = new map<Id, student__c>([Select Id, name, first_name__c, parent__c, teacher_set__c from student__c WHERE Id = : selectedSId]);


            teacherSet = mapStudent.get(selectedSId).teacher_set__c;
            for (teacher__c myTeacher : [Select Id, name, first_name__c, teacher_set__c, middle_name__c from teacher__c WHERE teacher_set__c = : teacherSet]){
                WrapTS.add(new WrapperClass(myTeacher));

            }

        }     
    }





}
0

On selecting the student value, you are calling fetchTeacherInfo() and using mapStudent to compare. However, there is no place in your code where you have filled in the mapStudent.

You might probably want to add the below line in your code:

for(student__c s:[Select Id, Name, First_Name__c, middle_name__c, teacher_set__c, Parent__c from student__c ]){
   if(!mapStudent.containsKey(s.Id)){
         mapStudent.put(s.Id, s);
   }
   wrapTS.add(new WrapperClass(s));
}
| improve this answer | |
  • hi, @Shailesh it returns an error Method does not exist or incorrect signature: [Map<Id,Student__c>].add(Id, Student__c) – sfdclearner Feb 22 '16 at 8:59
  • Updated the answer..it should be mapStudent.put(s.Id, s) – Shailesh Deshpande Feb 22 '16 at 9:21
  • i have tried it but returns nothing. I will update the code above – sfdclearner Feb 23 '16 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.