+ Start a Discussion
Sami ShakithSami Shakith 

Error message is not showing

Hi,

I am trying to create VF page it displays a report based on month and year. If i give month and year for generated report its showing the result. For other it should show the error messege. 

Here is my VF page code
 
<apex:page controller="test" sidebar="false" >

<apex:form ID="Search" >  
<b>Enter Search parameters</b>
<apex:pageBlock >  
 <apex:pageMessages></apex:pageMessages> 
<apex:pageBlockButtons >
<apex:commandButton value="Submit" action="{!Search}" reRender="showpartner" />
</apex:pageBlockButtons>  <apex:outputLabel title="Enter Search Parameters" value="Enter Year(Exp: 2015 or 2016...):" style="font:bold" /> 
<apex:inputText value="{!Name}"/><br/><br/>
 <apex:outputLabel value="Enter Month(Exp: July or August..):" /> 
<apex:inputText value="{!Month}"/>
<apex:pageBlockTable value="{!tenpartners }" var="partnervalue" id="showpartner" > 

   <apex:column > <b>Search Results</b> <analytics:reportChart reportid="00O280000035HWm" 
  filter="{column:'Opportunity.syear__c', operator:'equals', value:'{!JSENCODE(partnervalue.syear__c)}'},{column:'Opportunity.smonth__c', operator:'equals', value:'{!JSENCODE(partnervalue.smonth__c)}'}"> 
 
</analytics:reportChart></apex:column>   </apex:pageblockTable>    </apex:pageBlock>  </apex:form></apex:page>

Here is my class
 
public class test{
Public List<opportunity> tenpartners{get;set;}
public string Name{get;set;}
public string Month{get;set;}
public Boolean rend { get; set; }
public pagereference search(){
tenpartners = new List<opportunity>();
//tenpartners = database.query('SELECT syear__c FROM Opportunity where syear__c=:Name LIMIT 1');
tenpartners = database.query('SELECT ID,smonth__c,syear__c,Name FROM opportunity where syear__c=:Name and smonth__c=:Month limit 1');
system.debug('tenpartners!!!!'+tenpartners);

if(tenpartners.size() ==0 )
{
 system.debug('tenpartners!!!!'+tenpartners);

    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please enter the correct value.');
ApexPages.addMessage(myMsg);
           
}
return null;}
}

Please i need some one help.
 
Best Answer chosen by Sami Shakith
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help u
<apex:page controller="test" sidebar="false" >

<apex:form ID="Search" >  
<b>Enter Search parameters</b>
<apex:pageBlock >  
 <apex:pageMessages></apex:pageMessages> 
<apex:pageBlockButtons >
<apex:commandButton value="Submit" action="{!Search}"  />
</apex:pageBlockButtons>  <apex:outputLabel title="Enter Search Parameters" value="Enter Year(Exp: 2015 or 2016...):" style="font:bold" /> 
<apex:inputText value="{!Name}"/><br/><br/>
 <apex:outputLabel value="Enter Month(Exp: July or August..):" /> 
<apex:inputText value="{!Month}"/>
<apex:pageBlockTable value="{!tenpartners }" var="partnervalue" id="showpartner" > 

   <apex:column > <b>Search Results</b> <analytics:reportChart reportid="00O280000035HWm" 
  filter="{column:'Opportunity.syear__c', operator:'equals', value:'{!JSENCODE(partnervalue.syear__c)}'},{column:'Opportunity.smonth__c', operator:'equals', value:'{!JSENCODE(partnervalue.smonth__c)}'}"> 
 
</analytics:reportChart></apex:column>   </apex:pageblockTable>    </apex:pageBlock>  </apex:form></apex:page>

Please check below two blog on same
http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/
http://www.infallibletechie.com/2012/10/how-to-display-error-messages-in.html

Please let us know if this will help u

All Answers

Shashikant SharmaShashikant Sharma
There are two things you should do:

1. Make sure if(tenpartners.size() ==0 ) is satisfied when onth is not supplied, it could be poosible there are records whithout month
2. change return null to 
 
return ApexPages.currentPage();

Thanks
Shashikant
Sami ShakithSami Shakith
thanks for your reply sharma. 

When giving return ApexPages.currentPage(); like this it displying none.
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help u
<apex:page controller="test" sidebar="false" >

<apex:form ID="Search" >  
<b>Enter Search parameters</b>
<apex:pageBlock >  
 <apex:pageMessages></apex:pageMessages> 
<apex:pageBlockButtons >
<apex:commandButton value="Submit" action="{!Search}"  />
</apex:pageBlockButtons>  <apex:outputLabel title="Enter Search Parameters" value="Enter Year(Exp: 2015 or 2016...):" style="font:bold" /> 
<apex:inputText value="{!Name}"/><br/><br/>
 <apex:outputLabel value="Enter Month(Exp: July or August..):" /> 
<apex:inputText value="{!Month}"/>
<apex:pageBlockTable value="{!tenpartners }" var="partnervalue" id="showpartner" > 

   <apex:column > <b>Search Results</b> <analytics:reportChart reportid="00O280000035HWm" 
  filter="{column:'Opportunity.syear__c', operator:'equals', value:'{!JSENCODE(partnervalue.syear__c)}'},{column:'Opportunity.smonth__c', operator:'equals', value:'{!JSENCODE(partnervalue.smonth__c)}'}"> 
 
</analytics:reportChart></apex:column>   </apex:pageblockTable>    </apex:pageBlock>  </apex:form></apex:page>

Please check below two blog on same
http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/
http://www.infallibletechie.com/2012/10/how-to-display-error-messages-in.html

Please let us know if this will help u
This was selected as the best answer
Sami ShakithSami Shakith
Thanku so much Amit Chaudhary :)

Its working.