function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Force.platformForce.platform 

apexPage.addMessage

Hello All, my requirement is, when user dont enter quntity in inputText on vf and try to place order then warning message should disoplay.
but its not showing warning.
VF page:
<apex:page controller="EComm_Bucket_Controller" action="{!itemInMyBucket}" >
<style>
        .myFormStyle {
            background-color: Moccasin ;
            border:2px solid Violet;
        }
    </style>
    
    <style>
  /*for page block */     
.bPageBlock{
        width : 100%;
        }
        </style>
        
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $(".bPageBlock").css("background-color","Aquamarine");
        $(".bPageBlock").css("border-color","Aquamarine");
    });
    </script>
    
<apex:form styleClass="myFormStyle " >
  <apex:pageBlock title="My Bucket" >
  <apex:pageMessages > </apex:pageMessages>
  <apex:pageblockSection >
  <apex:pageBlockTable value="{!itemInBucket}" var="i">
  
    <apex:column value="{!i.name}"/>
    <apex:column value="{!i.Product_Name__c}"/>
    
    <apex:column headerValue="Quantity" >
    <apex:inputText value="{!q}" />
    </apex:column>
    
    <apex:column headerValue="Name" >
    <apex:inputText value="{!n}" />
    </apex:column>
    
    <apex:column headerValue="Address" >
    <apex:inputText value="{!a}" />
    </apex:column>
    
    <apex:Column >
    <apex:commandLink value="Place Order" action="{!placeOrderForSinglePro}">
    <apex:param name="Pname" value="{!i.Product_Name__c}"/>
    <!--<apex:param name="quantity" value="{!q}" assignTo="{!q}"/>-->
    </apex:commandLink>
    </apex:column>
    </apex:pageBlockTable> 
  </apex:pageblockSection> 
  </apex:pageBlock>
  <apex:commandLink value="View Order" action="{!openOrderPage}"/>
  <apex:commandLink value="Previous Page" style="float:right;" action="{!redirect}"/>
  </apex:form>
</apex:page>

Controller:
public class EComm_Bucket_Controller 
{  
Public List<EOrder_Item__c> itemInBucket{get; set;}
public Integer q{get; set;}
public String n{get; set;}
public String a{get; set;}

  public pageReference itemInMyBucket()
  {
     itemInBucket=[select id,name,Quantity__C,Product_Name__c from EOrder_Item__c WHERE Name!=NULL AND Flag__c=TRUE];
     System.debug('list=='+itemInBucket);
     return null;
  }
  
  //------------------Place Order Button-for single record-------------------------
  public pageReference placeOrderForSinglePro()
  {
    Id Prodname=ApexPages.currentPage().getParameters().get('Pname');
    string var = ApexPages.currentPage().getParameters().get('quantity');
  //----------to check q has value or zero
  
  
    
    EOrder__c ord=new EOrder__c(EP_del__c=Prodname,OQuantity__c=q,Contact_Name__c=n,Delivery_Address__c=a,Order_Status__c='Placed');
    if(ord.OQuantity__c==NULL)
    {
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value'));
    return null;
    }
    else
    {
    insert ord;
    }
    
   //------------------show only one item on bucket page----------
    List<EOrder_Item__c> processeditemInBucket = [select id,name, Quantity__C,Product_Name__c from EOrder_Item__c WHERE Name!=NULL AND Flag__c=TRUE];
    for(EOrder_Item__c v:processeditemInBucket)
        {
            v.Flag__c =FALSE;
            
        }
      update  processeditemInBucket;
    return null;
  }
  
  //----------------------Place order for All-for multiple record-----------------------
  public PageReference placeOrderForAllPro()
  {
   return null;
  }

 public PageReference redirect()
    {
   PageReference pr = new PageReference('/apex/EComm_Landing_Page');
   return pr;
   }
   
   
   
   public PageReference openOrderPage()
    {
   PageReference pr = new PageReference('/apex/Final_Order_Page');
   return pr;
   }
}
Best Answer chosen by Force.platform
Waqar Hussain SFWaqar Hussain SF
Hi Arati, 

Use below code.
 
<apex:page controller="EComm_Bucket_Controller" action="{!itemInMyBucket}" >
<style>
        .myFormStyle {
            background-color: Moccasin ;
            border:2px solid Violet;
        }
    </style>
    
    <style>
  /*for page block */     
.bPageBlock{
        width : 100%;
        }
        </style>
        
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $(".bPageBlock").css("background-color","Aquamarine");
        $(".bPageBlock").css("border-color","Aquamarine");
    });
    </script>
    
<apex:form styleClass="myFormStyle " >
  <apex:pageBlock title="My Bucket" id="pb" >
  <apex:pageMessages > </apex:pageMessages>
  <apex:pageblockSection >
  <apex:pageBlockTable value="{!itemInBucket}" var="i">
  
    <apex:column value="{!i.name}"/>
    <apex:column value="{!i.Product_Name__c}"/>
    
    <apex:column headerValue="Quantity" >
    <apex:inputText value="{!q}" />
    </apex:column>
    
    <apex:column headerValue="Name" >
    <apex:inputText value="{!n}" />
    </apex:column>
    
    <apex:column headerValue="Address" >
    <apex:inputText value="{!a}" />
    </apex:column>
    
    <apex:Column >
    <apex:commandLink value="Place Order" action="{!placeOrderForSinglePro}">
    <apex:param name="Pname" value="{!i.Product_Name__c}"/>
    </apex:commandLink>
    </apex:column>
    </apex:pageBlockTable> 
  </apex:pageblockSection> 
  </apex:pageBlock>
  <apex:commandLink value="View Order" action="{!openOrderPage}" rerender="pb"/>
  <apex:commandLink value="Previous Page" style="float:right;" action="{!redirect}"/>
  </apex:form>
</apex:page>

public class EComm_Bucket_Controller 
{  
Public List<EOrder_Item__c> itemInBucket{get; set;}
public Integer q{get; set;}
public String n{get; set;}
public String a{get; set;}

  public pageReference itemInMyBucket()
  {
     itemInBucket=[select id,name,Quantity__C,Product_Name__c from EOrder_Item__c WHERE Name!=NULL AND Flag__c=TRUE];
     System.debug('list=='+itemInBucket);
     return null;
  }
  
  //------------------Place Order Button-for single record-------------------------
  public pageReference placeOrderForSinglePro()
  {
    Id Prodname=ApexPages.currentPage().getParameters().get('Pname');
    string var = ApexPages.currentPage().getParameters().get('quantity');
  //----------to check q has value or zero
  
  
    
    EOrder__c ord=new EOrder__c(EP_del__c=Prodname,OQuantity__c=q,Contact_Name__c=n,Delivery_Address__c=a,Order_Status__c='Placed');
    if(ord.OQuantity__c==NULL)
    {
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value'));
    return null;
    }
    else
    {
    insert ord;
    }
    
   //------------------show only one item on bucket page----------
    List<EOrder_Item__c> processeditemInBucket = [select id,name, Quantity__C,Product_Name__c from EOrder_Item__c WHERE Name!=NULL AND Flag__c=TRUE];
    for(EOrder_Item__c v:processeditemInBucket)
        {
            v.Flag__c =FALSE;
            
        }
      update  processeditemInBucket;
    return null;
  }
  
  //----------------------Place order for All-for multiple record-----------------------
  public PageReference placeOrderForAllPro()
  {
   return null;
  }

 public PageReference redirect()
    {
   PageReference pr = new PageReference('/apex/EComm_Landing_Page');
   return pr;
   }
   
   
   
   public PageReference openOrderPage()
    {
	if(q== null){
		ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Please Enter quantity.');
		ApexPages.addMessage(myMsg);
		return null;
	}
   PageReference pr = new PageReference('/apex/Final_Order_Page');
   return pr;
   }
}

 

All Answers

Neetu_BansalNeetu_Bansal
Hello Aarti,

Please put reRender for page messages to display error.

Thanks,
Neetu
Waqar Hussain SFWaqar Hussain SF
Hi Arati, 

Use below code.
 
<apex:page controller="EComm_Bucket_Controller" action="{!itemInMyBucket}" >
<style>
        .myFormStyle {
            background-color: Moccasin ;
            border:2px solid Violet;
        }
    </style>
    
    <style>
  /*for page block */     
.bPageBlock{
        width : 100%;
        }
        </style>
        
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $(".bPageBlock").css("background-color","Aquamarine");
        $(".bPageBlock").css("border-color","Aquamarine");
    });
    </script>
    
<apex:form styleClass="myFormStyle " >
  <apex:pageBlock title="My Bucket" id="pb" >
  <apex:pageMessages > </apex:pageMessages>
  <apex:pageblockSection >
  <apex:pageBlockTable value="{!itemInBucket}" var="i">
  
    <apex:column value="{!i.name}"/>
    <apex:column value="{!i.Product_Name__c}"/>
    
    <apex:column headerValue="Quantity" >
    <apex:inputText value="{!q}" />
    </apex:column>
    
    <apex:column headerValue="Name" >
    <apex:inputText value="{!n}" />
    </apex:column>
    
    <apex:column headerValue="Address" >
    <apex:inputText value="{!a}" />
    </apex:column>
    
    <apex:Column >
    <apex:commandLink value="Place Order" action="{!placeOrderForSinglePro}">
    <apex:param name="Pname" value="{!i.Product_Name__c}"/>
    </apex:commandLink>
    </apex:column>
    </apex:pageBlockTable> 
  </apex:pageblockSection> 
  </apex:pageBlock>
  <apex:commandLink value="View Order" action="{!openOrderPage}" rerender="pb"/>
  <apex:commandLink value="Previous Page" style="float:right;" action="{!redirect}"/>
  </apex:form>
</apex:page>

public class EComm_Bucket_Controller 
{  
Public List<EOrder_Item__c> itemInBucket{get; set;}
public Integer q{get; set;}
public String n{get; set;}
public String a{get; set;}

  public pageReference itemInMyBucket()
  {
     itemInBucket=[select id,name,Quantity__C,Product_Name__c from EOrder_Item__c WHERE Name!=NULL AND Flag__c=TRUE];
     System.debug('list=='+itemInBucket);
     return null;
  }
  
  //------------------Place Order Button-for single record-------------------------
  public pageReference placeOrderForSinglePro()
  {
    Id Prodname=ApexPages.currentPage().getParameters().get('Pname');
    string var = ApexPages.currentPage().getParameters().get('quantity');
  //----------to check q has value or zero
  
  
    
    EOrder__c ord=new EOrder__c(EP_del__c=Prodname,OQuantity__c=q,Contact_Name__c=n,Delivery_Address__c=a,Order_Status__c='Placed');
    if(ord.OQuantity__c==NULL)
    {
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value'));
    return null;
    }
    else
    {
    insert ord;
    }
    
   //------------------show only one item on bucket page----------
    List<EOrder_Item__c> processeditemInBucket = [select id,name, Quantity__C,Product_Name__c from EOrder_Item__c WHERE Name!=NULL AND Flag__c=TRUE];
    for(EOrder_Item__c v:processeditemInBucket)
        {
            v.Flag__c =FALSE;
            
        }
      update  processeditemInBucket;
    return null;
  }
  
  //----------------------Place order for All-for multiple record-----------------------
  public PageReference placeOrderForAllPro()
  {
   return null;
  }

 public PageReference redirect()
    {
   PageReference pr = new PageReference('/apex/EComm_Landing_Page');
   return pr;
   }
   
   
   
   public PageReference openOrderPage()
    {
	if(q== null){
		ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Please Enter quantity.');
		ApexPages.addMessage(myMsg);
		return null;
	}
   PageReference pr = new PageReference('/apex/Final_Order_Page');
   return pr;
   }
}

 
This was selected as the best answer