I have three custom objects, students, course_detail, and StudentCourseDtlAsscs. The StudentCourseDtlAsscs object is junction object between students and course detail. I want to be able to choose a student from my Student Object and add courses from course detail into StudentCourseDtlAsscs. Is this possible in SF and how?
I have a screenshot of my visualforce page:
VF Page:
<apex:page controller="CourseDetailMultiselect">
<apex:form >
<apex:outputLabel value="Student Name" for="students"></apex:outputLabel>
<apex:selectList id="students" value="{!selectedValue}" size="1" title="Student">
<apex:selectOptions value="{!students}"></apex:selectOptions>
</apex:selectList>
<c:MultiselectPicklist leftLabel="Available Contacts"
leftOptions="{!allCourseDt}"
rightLabel="Selected Contacts"
rightOptions="{!selectedCourseDt}"
size="14"
width="500px"/>
<apex:commandButton action="{!save}" value="Save record"/>
<apex:commandButton action="Cancel" value="Cancel"/>
</apex:form>
</apex:page>
Here is my Class:
public class CourseDetailMultiselect {
//Student Picklist
public string selectedValue {get;set;}
public List<SelectOption> students;
public List<selectOption> getStudents(){
List<selectOption> options = new List<selectOption>();
options.add(new selectOption('','- None-'));
for(Students__c student : [Select Id, Name FROM Students__c]){
options.add(new selectOption(student.id, student.Name));
}
return options;
}
//Course Detail Custom Picklist
public SelectOption[] selectedCourseDt { get; set; }
public SelectOption[] allCourseDt { get; set; }
public String message { get; set; }
public CourseDetailMultiselect() {
selectedCourseDt = new List<SelectOption>();
List<Course_Detail__c> courses = [SELECT Course_Detail__c.FKCourse__r.Name, StartDate__c, Id FROM Course_Detail__c];
allCourseDt = new List<SelectOption>();
for ( Course_Detail__c c : courses ) {
string temp = c.FKCourse__r.Name + ' - ' + c.StartDate__c;
allCourseDt.add(new SelectOption(c.Id, temp));
}
}
public PageReference save() {
//DO NOT KNOW WHAT DO HERE
return null;
}
}