+ Start a Discussion
Money Care 7Money Care 7 

How to Pass error message in vf page

Hi Friends
i have two fields one is text field (field__c) another is formula field (formula__c).if formula field value is "c2" and text field value is blank its showing error message .i have tried this but ist not working
 
if( curriculum .Product_Code__c =='C2' && curriculum .No_of_ups__c==null  )
        {
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please fill the field value !!!...........'));
   return null;
        }

 
SFDC GuestSFDC Guest
Hi Money Care7,

Please use the below code. 

Apex:-

if( curriculum.Product_Code__c =='C2' && curriculum.No_of_ups__c==null )
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please fill the field value !!!...........'));
return null;
}

VF page:
Please insert the below tag inside the visualforce page within page block.

<apex:pageMessages >
</apex:pageMessages>

Please mark it as a best answer if it resolves your problem.

Thank You,
Sohel Mohd
Money Care 7Money Care 7
Hi @Sohel Mohd I have tried that if( curriculum .Product_Code__c =="C2" && curriculum .No_of_ups__c==null ) but its showing error like Compile Error: line 96:41 no viable alternative at character '"' at line 96 column 41
SFDC GuestSFDC Guest
Hi Money Care7,

Please use the below code. 

Apex:-

if( curriculum.Product_Code__c=='C2' && curriculum.No_of_ups__c==null )
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please fill the field value !!!...........'));
return null;
}

VF page:
Please insert the below tag inside the visualforce page within page block.

<apex:pageMessages >
</apex:pageMessages>

Please mark it as a best answer if it resolves your problem.

Thank You,
Sohel Mohd
pranab khatuapranab khatua
Apex code:::::::::
try{
             if(accountcsvFileBody == null){
                 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select a CSV file.'));
                 return null;
            }
             accountcsvFileLines = accountcsvFileBody.toString().split('\n');                            
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The Uploaded file must be CSV format.'+e.getMessage()));
            return null;
        }
Visualforce Page:
 
<apex:page>
         <apex:pageMessages />

</apex:page>


 
Sitarama MurthySitarama Murthy
hi,
try this line :" ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value'));"

and in VF page add tag 
<apex:pageMessages ></apex:pageMessages>