You need to sign in to do that
Don't have an account?
Ap30
ApexMessage is not displayed
Hi All,
In my below code else part is not working though status field is blank. Please guide where i'm going wrong.
===============
<apex:page standardController="Detail__c" extensions="WarningPage" action="{!displayWarning}">
<apex:form >
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
</apex:pageBlock>
</apex:form>
</apex:page>
==============================================
public with sharing class WarningPage {
public WarningPage(ApexPages.StandardController controller) {
}
public void displayWarning(){
list<Detail__c> stud = [select id,name,Status__c from Detail__c ];
for(Detail__c s : stud)
{
if(s.Status__c == 'More details needed')
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'More details needed'));
}
else if(s.Status__c == '')
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Verified'));
}
}
}
}
In my below code else part is not working though status field is blank. Please guide where i'm going wrong.
===============
<apex:page standardController="Detail__c" extensions="WarningPage" action="{!displayWarning}">
<apex:form >
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
</apex:pageBlock>
</apex:form>
</apex:page>
==============================================
public with sharing class WarningPage {
public WarningPage(ApexPages.StandardController controller) {
}
public void displayWarning(){
list<Detail__c> stud = [select id,name,Status__c from Detail__c ];
for(Detail__c s : stud)
{
if(s.Status__c == 'More details needed')
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'More details needed'));
}
else if(s.Status__c == '')
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Verified'));
}
}
}
}
Actually, I correct your code Only not your logic.
Yoy are getting this error "I'm getting both messages in single page irrespective of status field value." because your detailList has 2 object simple
So as a page Load ==>at that instant whatever would be in the List would show
so correct your code according to it.
By the way, what is the requirement?
All Answers
In the Apex class, before the For Loop, you should check if the list is empty or not.
For example, consider the following code:
Please mark it as Best Answer so that it can help others in the future.
Regards,
Priya Ranjan
Hi AP,
I have run your code in my Org and I found that minor mistake in you code
Please replace this Line else if(s.Status__c == '') with below code
1.
Or
2.
You can also simply write
in both case, it is working fine.
Please mark it as the Best Answer so that other people would take reference from it.
Thank You
Ap, Please mark As the Best Answer
Thank You
Actually, I correct your code Only not your logic.
Yoy are getting this error "I'm getting both messages in single page irrespective of status field value." because your detailList has 2 object simple
So as a page Load ==>at that instant whatever would be in the List would show
so correct your code according to it.
By the way, what is the requirement?