You need to sign in to do that
Don't have an account?

Apex/Visualforce Exception errors not showing
Below is the code for my Visual Force page and APEX controller. I run a TRY block and intentionaly throw an exception.
I used similar code in another VisualForce/APEX Controller page combination and it works for me however on this page when I click the button and the exception is thrown the error message is not displaying.
VisualForce Page
<apex:page controller="PlacementPreferenceFormController" sidebar="false" showHeader="false" cache="false"> <apex:pageMessages id="errorMessage"/> <apex:outputPanel > <apex:form > <apex:pageBlock title="Placement Preference Form"> <apex:pageBlockSection columns="2"> <apex:InputField value="{!RecruitmentCycle.Allocated_Points__c}"/> <apex:InputField value="{!RecruitmentCycle.Remaining_Points__c}"/> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Add Placement Preference" mode="edit" id="PPAdd"> <apex:pageBlockSection columns="2"> <apex:outputLabel value="Partner Organization " for="pl"><apex:selectList id="pl" value="{!ppn.Partner_Research__c}" size="1" title="Partner Organization"> <apex:selectOptions value="{!PRs}"></apex:selectOptions> </apex:selectList></apex:outputLabel> <apex:InputField value="{!ppn.Points__c}"/> <apex:commandButton value="Add Placement" action="{!newPlacementPreference}" rerender="all"> </apex:commandButton> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Placement Preferences" mode="edit" id="PPList"> <apex:pageBlockTable value="{!PlacementPreferenceList}" var="pp"> <apex:column value="{!pp.Partner_Research_Organization__c}"/> <apex:column value="{!pp.Organization_Type__c}"/> <apex:column value="{!pp.City__c}"/> <apex:column value="{!pp.State__c}"/> <apex:column value="{!pp.Points__c}"/> <apex:column headerValue="Action"> <apex:commandButton value="Del" action="{!deletePlacementPreference}" rerender="all"> <apex:param name="ppParam" value="{!pp.Id}" assignTo="{!ppid}"/> </apex:commandButton> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:outputPanel> </apex:page>
APEX Controller
public class PlacementPreferenceFormController { // Declare Recruitment Cycle and Placement Preference List public Recruitment_Cycle__c rc; public LIST<Placement_Preference__c> ppl; public Placement_Preference__c ppn {get; set;} public String pl {get; set;} public decimal ppnPoints {get;set;} public string ppnPR {get;set;} public string ppid {get;set;} public PlacementPreferenceFormController(){ // Select Recruitment Cycle Record pulling ID parameter rc = [select id, allocated_points__c, remaining_points__c from Recruitment_Cycle__c where id =:ApexPages.currentPage().getParameters().get('id')]; // Select Placement Preference List from parent record ppl = [select id, Partner_Research_Organization__c, City__c, Organization_Type__c, Partner_Research__c, Points__c, Recruitment_Cycle__c, State__c from Placement_Preference__c Where Recruitment_Cycle__c = :ApexPages.currentPage().getParameters().get('id')]; ppn = new Placement_Preference__c(); } // Picklist Select Option Values for Partner Research public List<selectOption> getPRs() { List<selectOption> options = new List<selectOption>(); //new list for holding all of the picklist options options.add(new selectOption('', '- None -')); //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below for (Partner_Research__c PRoption : [select id, Organization_Name__r.name from Partner_Research__c Where (TBR_Partner_Year__c = '2012' AND Research_Stage__c = 'Recruiting' AND Status__c = 'Invite to submit proposal') OR (TBR_Partner_Year__c = '2012' AND Research_Stage__c = 'Position Proposal') OR (TBR_Partner_Year__c = '2012' AND Research_Stage__c = 'Placement') ORDER BY Organization_Name__r.name]) { //query for User records with System Admin profile options.add(new selectOption(PRoption.Id, PRoption.Organization_Name__r.name)); //for all records found - add them to the picklist options } return options; //return the picklist options } public void refreshPlacementPreferences() { ppl = [select id, City__c, Organization_Type__c, Partner_Research__c, Points__c, Recruitment_Cycle__c, State__c from Placement_Preference__c Where Recruitment_Cycle__c = :ApexPages.currentPage().getParameters().get('id')]; } public PageReference deletePlacementPreference() { Placement_Preference__c pptd = [Select id from Placement_Preference__c where Id = :ppid]; delete pptd; string url = 'http://broadcenter.force.com/page/PlacementPreferences?id=' + rc.Id; PageReference p = new PageReference(url); p.setRedirect(true); return p; } public PageReference newPlacementPreference() { try{ throw new cException('Residency Requirement is a required field.'); Placement_Preference__c ppta = new Placement_Preference__c(Recruitment_Cycle__c = rc.id); if (ppn.Points__c > 0) { ppta.Points__c = ppn.Points__c; ppta.Partner_Research__c = ppn.Partner_Research__c; insert ppta; } string url = 'http://broadcenter.force.com/page/PlacementPreferences?id=' + rc.Id; PageReference p = new PageReference(url); p.setRedirect(true); return p; } catch(Exception e){ApexPages.addMessages(e);return null;} } public Recruitment_Cycle__c getRecruitmentCycle(){ return rc; } public LIST<Placement_Preference__c> getPlacementPreferenceList(){ return ppl; } }
Please give the Id to the apex:PageMessage and rendered on the button click.
Though I didn't got in depth of the codes.....however I didn't understand why do you have two <apex:pageMessages /> tag in your visualforce in line 3 and line 5......and how they are different to each other.
As for apex:pageMessage I fell in a similar problem when it was not showing error even when I was trying to make it show with all options.....it behaves weird.........also there are two different tags <apex:pageMessages /> and <apex:pageMessage /> that makes it more confusing.
I went ahead and removed the second instance of the pageMessage tag on line 5 and added an ID as requested in the previous post.
What problems did you encounter with the PageMessages tag and how did you resolve the issue?