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
phanip adminphanip admin 

Visual force using input text field and one button(like submit).                     You enter any value in input text field after click button show as pass or you not enter anything click the button show as fail 

Hi Averyone..

My name is phanindra im new from salesforce

i have attend a last week interview in MNC Company

He asking one senerio in Visual force ?

Senerio is  : input text field and one button(like submit).
                    You enter any value in input text field after click button show as pass or you not enter anything click the button show as fail 

Please give me Reply ASAP: )

Thanks in Advance..
Best Answer chosen by phanip admin
Deepak Kumar 138Deepak Kumar 138
This is the sample code - 

Class code - 
Public class MyController{
    public String userInput{get;set;}
    
    public PageReference doSubmit(){
        if(userInput==NULL || userInput=='' ){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Fail'));
            
        }
        else{
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Pass'));
        }
        
        return null;
    }
}

VF Page code - 
<apex:page controller="MyController">
  <apex:form>
  <apex:pageBlock>
      <apex:pageMessages></apex:pageMessages>
      
          <apex:pageBlockSection>
              <apex:inputText value="{!userInput}"/>
              
          </apex:pageBlockSection>
          <apex:pageBlockButtons>
              <apex:commandButton action="{!doSubmit}" value="Submit"/>
          </apex:pageBlockButtons>
      
  </apex:pageBlock>
  </apex:form>
</apex:page>

Note - please make as best answer if it helps.

All Answers

Deepak Kumar 138Deepak Kumar 138
This is the sample code - 

Class code - 
Public class MyController{
    public String userInput{get;set;}
    
    public PageReference doSubmit(){
        if(userInput==NULL || userInput=='' ){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Fail'));
            
        }
        else{
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Pass'));
        }
        
        return null;
    }
}

VF Page code - 
<apex:page controller="MyController">
  <apex:form>
  <apex:pageBlock>
      <apex:pageMessages></apex:pageMessages>
      
          <apex:pageBlockSection>
              <apex:inputText value="{!userInput}"/>
              
          </apex:pageBlockSection>
          <apex:pageBlockButtons>
              <apex:commandButton action="{!doSubmit}" value="Submit"/>
          </apex:pageBlockButtons>
      
  </apex:pageBlock>
  </apex:form>
</apex:page>

Note - please make as best answer if it helps.
This was selected as the best answer
phanip adminphanip admin
Thanks a ton Deepak:
phanip adminphanip admin
Hi Guys

In validation rules we have an one object have fields is city and pincodes and is there another object which have link as cities and pincodes link and we want Check before saving that links which proper for example DELHI you don't enter BANGALORE pincodes for which function validation rule will be used?