Day 2 Assignment Part-2

I have created a 5 Days Salesforce based programming and configuration assignments for practice and improving your skills. This blog have the second day assignment part-2. The assignment is in format of a typical salesforce requirement, comparable to a small size project. To design and develop this project it is recommended that you register a fresh salesforce developer org. Please go through the requirements which are well defined and should be easily understood if you have a basic understanding of salesforce sales and service cloud. Your data model design or solution approach to the requirements might be different from the answers provided here. Every solution is correct if you are fulfilling all the requirements. It is highly recommended before working on this blog you must have completed the part-1 blog.

Requirement: We have a university “St Judes” which wants its Salesforce account to get configured by us. Following are the requirement of this client.

 

2.1. A Course will have list of all the Students in it enrolled.

Click here to learn more

You don’t know it yet that you have already completed it. You just need to make them viewable from page layout and you know it now how to do it.

 

2.2.  Professor fields “DOB” “Years of Experience”, “Expertise”        Multipicklist(Java,English,Mechanical,..etc)

Click here to learn more

It is again a data model configuration question to create fields.

 

2.3. The University will display all the Professors experties.

Hint: In University detail page your new section must look like—>

day2(8)

 

Click here to learn more

We have to create a Inline Visualforce page to solve this problem.

And here is the controller class for this problem:

Class:

public with sharing class ListOfProfessorInUniversity {

public boolean flag{get; set;}

public string ids{get; set;}

public ListOfProfessorInUniversity(ApexPages.StandardController controller){

ids = controller.getId();

} public List<Professor__c> getAllProfessor() {

List<Course__c> allCourses = [SELECT Name, Professor_del__c, Select_University__c

FROM Course__c

WHERE Professor_del__c != NULL AND Select_University__c =: ids];

Set<Id> CourseIdList = new Set<Id>();

for (Course__c courses : allCourses) {

CourseIdList.add(courses.Professor_del__c);

}

system.debug(‘>>>>>>>>>>’ +CourseIdList);

List<Class__c> allClass = [SELECT Name, Class_Teacher__c FROM Class__c

WHERE Class_Teacher__c !=: CourseIdList OR Id IN : CourseIdList];

Set<Id> classIdList = new set<Id>();

for (Class__c classes : allClass){

classIdList.add(classes.Class_Teacher__c);

}

system.debug(‘>>>>>>>>>>’ +classIdList);

List<Professor__c> professors = [SELECT Name, email__c, Experience__c, Expertise__c FROM Professor__c

WHERE Id IN : CourseIdList OR Id IN : classIdList];

system.debug(‘*****************’ +professors);

Set<Professor__c> IdSet = new Set<Professor__c>(); idSet.addAll(professors);

system.debug(‘>>>>>>>>>>>’ + idSet);

if (NULL != IdSet){

flag = true;

}

else{

flag = false;

}

return professors;

}

}

 

and here is the Visualforce page for this controller:

 

<apex:page standardController=”St_Judes_University__c” extensions=”ListOfProfessorInUniversity”>

<apex:sectionHeader title=”All Professors Related to University”/>

<apex:outputpanel rendered=”{!flag}” > These are the students which are teached by teacher. </apex:outputpanel>

<apex:pageBlock >

<apex:pageBlockTable value=”{!AllProfessor}” var=”professor”>

<apex:column value=”{!professor.Name}”/>

<apex:column value=”{!professor.email__c}”/>

<apex:column value=”{!professor.Experience__c}”/>

<apex:column value=”{!professor.Expertise__c}”/>

</apex:pageBlockTable>

</apex:pageBlock>

</apex:page>

 

Now your work is done and now you just need to add the Visualforce page in the page layout section.

 

2.4. When ever a new student is added he is supposed to be registered at-least in a Course and a Class.

Click here to learn more

For this you must create the field on Student of Course mandatory and in Course the Class field make it mandatory too. That’s it your work is done.

 

2.5. When a new Course is added to have a valid future Start date. (NOTE: Customize such that even the end date is of future and greater than or equal to the start date.)

Click here to learn more

For this you must create two Validation rules. You have made a Validation rule previously so it is not going to be a problem for you.

Now the validation rule is like this:

StartDate::: IF( ISBLANK( Start_Date__c ),true, IF ( Start_Date__c < TODAY(),true,false))

EndDate::: IF( ISBLANK( End_Date__c ),true, IF ( End_Date__c < TODAY(),true,false))

 

2.6. A Course cannot be registered by a Student if it does not have a Professor.

Click here to learn more

For this again you have to create validation rule:

ISBLANK( Course_select__r.Professor_del__c )

 

2.7. The University home page will have an alert message if it has any single course without a professor.

Hint: After adding the Visualforce page your University detail page must look like –>

day2(8)

Click here to learn more

We are back on creating a inline Visualforce page. To create the Visualforce page first lets start with the controller class.

Class:

public with sharing class ListOfStudentsinClass{

public string coursesString{get;set;}

public List<Course__c> CourseName{get; set;}

public boolean flag{get;set;}

List<Course__c> CourseList = new List<Course__c>();

public ListOfStudentsinClass(ApexPages.StandardController ST){

string coursesString=ST.getId();

CourseList = [

SELECT Name, Professor_del__c, Select_University__c

FROM Course__c

WHERE Select_University__c =: coursesString

AND Professor_del__c =: NULL];

system.debug(‘>>>>>>’ +CourseList);

if ( NULL != Course__c.Professor_del__c){

flag=true;

}

else{

flag=false;

}

}

public List<Course__c> getCourses() {

return CourseList;

}

}

 

Now that we have our controller class we can create the Visualforce Page and it can be created like this.

(NOTE: I have already told you this is totally my perception you can modify anything by your style but do it to like at-least you fulfill the criteria and about the page you can modify it and make it more beautiful by using HTML and CSS tags. )

 

<apex:page standardController=”St_Judes_University__c” tabStyle=”University__c” extensions=”ListOfStudentsinClass”>

<apex:sectionHeader title=”Error”/>

<apex:outputpanel rendered=”{!flag}” > These Courses dont have professors in them. </apex:outputpanel>

<apex:pageBlock >

<apex:pageBlockTable value=”{!Courses}” var=”course”>

<apex:column value=”{!course.Name}”/>

</apex:pageBlockTable>

</apex:pageBlock>

</apex:page>

Now you have to add it in your university page layout and now you know it already how to do it.

Author: AJ

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *

× How can I help you?