Day 4 Assignment (VFpage, JavaScript)
Jan26

Day 4 Assignment (VFpage, JavaScript)

I have created a 5 Days Salesforce based programming and configuration assignments for practice and improving your skills. This blog have the third day assignment. Since all the blogs are related I would recommend beginners to start from Day 2 assignment and not directly jump to this 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.  1. Create a VF page listing a quick search for all the Professors. A quick search will be a on key press VF page. If the users press “V” in the field all the professors with starting name “V” like Vineet, Vinay .. etc will list down in the page. AJAX Toolkit Developer Guide SOLUTION: VisualForce Page Visual force page code. <apex:page id="page" controller="Basic2SearchProfessorsDynamically" sidebar="false"> <apex:form id="form"> <apex:pageMessages id="errors" /> <apex:pageBlock title="Find Me A Professor!" mode="edit" id="block"> <table width="100%" border="0"> <tr> <td width="200" valign="top"> <apex:pageBlock title="Parameters" mode="edit" id="criteria"> <script type="text/javascript"> function doSearch() { searchServer(document.getElementById("profName").value, document.getElementById("mail").value, document.getElementById("YOE").value ); } </script> <apex:actionFunction name="searchServer" action="{!runSearch}" reRender="results,errors,debug"> <apex:param name="profName" value="" /> <apex:param name="mail" value="" /> <apex:param name="YOE" value="" /> </apex:actionFunction> <table cellpadding="2" cellspacing="2" id="table"> <tr> <td style="font-weight:bold;">Name<br /> <input type="text" id="profName" onkeyup="doSearch();" /> </td> </tr> <tr> <td style="font-weight:bold;">Email<br /> <input type="text" id="mail" onkeyup="doSearch();" /> </td> </tr> <tr> <td style="font-weight:bold;">Year Of Experience<br /> <input type="text" id="YOE" onkeyup="doSearch();" /> </td> </tr> </table> </apex:pageBlock> </td> <td valign="top"> <apex:pageBlock mode="edit" id="results"> <apex:outputPanel id="panel" rendered="true"> <apex:pageBlockTable value="{!profList}" var="prof"> <apex:variable value="{!0}" var="cnt"/> <apex:column headerValue="Action"> <apex:commandButton value="Delete" style="background: red; color: white;" action="{!deleteProf}" rendered="true" reRender="panel"> <apex:param value="{!prof.Id}" name="profToRemove" assignTo="{!rowToRemove}"/> <apex:param name="index" value="{!cnt}"/> </apex:commandButton> <apex:variable var="cnt" value="{!cnt+1}"/> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Professor Name" action="{!toggleSort}" reRender="results"> <apex:param name="sortField" value="Name" assignTo="{!sortField}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!prof.Name}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Professor Email" action="{!toggleSort}" reRender="results"> <apex:param name="sortField" value="Email__c" assignTo="{!sortField}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!prof.Email__c}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Year of Experience" action="{!toggleSort}" reRender="results"> <apex:param name="sortField" value="Year_Of_Experience__c" assignTo="{!sortField}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!prof.Year_Of_Experience__c}" /> </apex:column> </apex:pageBlockTable> </apex:outputPanel> </apex:pageBlock> </td> </tr> </table> <apex:pageBlock title="Debug - SOQL" id="debug"> <apex:outputText value="{!debugSoql}" /> </apex:pageBlock> </apex:pageBlock> </apex:form> </apex:page> 2. The quick search will have a delete button beside each Professor row. This will delete a particular Professor. Once the Professor is deleted all the students from the Professors Course will get de-enrolled(Removed)  SOLUTION: VisualForce Page Controller public with sharing class Basic2SearchProfessorsDynamically { //the soql without the order and limit private String soql {get; set;} //the row to be delete public String rowToRemove{get; set;} //the collection of professors to display public List<Basic2Proffessor__c> profList {get; set;} //Required Professor(Dummy Professor) Basic2Proffessor__c reqProf = [SELECT Id, Name FROM Basic2Proffessor__c WHERE Name = ‘Professor Required’]; //the current sort direction. default...

Read More
Day 3 Assignment
Dec28

Day 3 Assignment

I have created 5 days Salesforce based assignment this is third 3rd day I hope you have already finished 1st and 2nd day. If not it is highly recommended to finish the blog-1, and blog-2 part 1 & part 2  first. The assignment is in format of a typical Salesforce requirement, comparable to a small size project. 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. Requirement: We have a university “St Judes” which wants its salesforce account to get configured by us. Following are the requirement of this client.   1. Since Student and Course are having a many to many relationship, the Junction object will have several fields representing the Student’s performance in those Courses. A Student will have the Status of PASS or FAIL and MARKS OBTAINED for each of its Course as well. Click here to learn more For this solution make a picklist having name Status and values PASS or FAIL and a number field named Marks Obtained in the junction object this will do the trick.   2. All the Professor will get an email 2 days before the Course completion asking the Professors to provide marks to those Students in its Course. Click here to learn more For this what i have done is first create a email field in in Professor and Course object and made the email field mandatory. Than I have created a trigger on Course to auto update the email field in the Course object with Professors email. I hope you have done part-1 and part-2 already and you have already created a trigger on course the best practices tells us that we should not make more than one trigger on a single object. So update this part also in your trigger and this part will auto update the email field in Course object with the email field in Professor.   Trigger: Map<Id, Course__c> profCourseMap = new Map<Id, Course__c>(); List<Course__c> fullCourseList = [SELECT Id, Name, Professor_del__c, Professor_Email__c FROM Course__c WHERE Id IN: Trigger.newMap.keySet()]; for (Course__c course : fullCourseList) { if (Trigger.isInsert) { profCourseMap.put(course.Professor_del__c, course); } if (Trigger.isUpdate && Trigger.oldMap.get(course.Id).Professor_del__c != course.Professor_del__c && course.Professor_del__c != NULL) { profCourseMap.put(course.Professor_del__c, course); } } System.debug(‘profCourseMap————–‘ + profCourseMap); System.debug(‘profCourseMap————–‘ + profCourseMap); List<Course__c> listToBeUpdated = new List<Course__c>(); List<Professor__c> mainProfList = [SELECT Name, Email__c FROM Professor__c WHERE Id IN: profCourseMap.keySet()]; for (Course__c course : profCourseMap.values()) { for (Integer i = 0;...

Read More