+ Start a Discussion
Sohan Rawat 5Sohan Rawat 5 

Accept a Input from end user.

Hi, 

Can someone give me a little guidance here to understand how taking a input from user works here is Salesforce.

I was going through Apex developer's guide and I'vea almost read half of the book, but still didn't see any example to take a input from user. Like in Java we can use a DataInput stream or scanner class to take a input from user, but I've not seen anything like in Apex.

Can someone point me to the documentation which can help me to understand how apex lets your customer to input the data in Salesforce.

Any help will be highly appreciated.

Thanks
Tejpal KumawatTejpal Kumawat
Hello Sohan,

In apex there are no need DataInput stream or scanner class to take a input like JAVA. You need only create a variable  in controller & connect with apex inputText value in VF Page.

Regards
Tej Pal Kumawat
Skype : tejpalkumawat1991

If this answers your question mark Best Answer it as solution and then hit Like!
Tejpal KumawatTejpal Kumawat
You can debug value in save method
public class MyController{
    public string var1{get; set;}
    public MyController() {
        
    }
	public void save(){
	    system.debug(var1);
	}
}
<apex:page controller="MyController">
    <apex:pageMessages id="pgId"></apex:pageMessages>
    <apex:form id="frmId">
        <apex:inputText value="{!var1}"/>
        <apex:commandButton value="Save" action="{!save}" reRender="pgId, frmId"/>
    </apex:form>
</apex:page>
Regards
Tej Pal Kumawat
Skype : tejpalkumawat1991

If this answers your question mark Best Answer it as solution and then hit Like!

 
SFDC k5SFDC k5
Hello,

Salesfore platform allows 3 different types of methods below to link VF page to a custom controller happens 

Setter - Passes the user-specified values from a VF page to a controller
Getter - Returns the values from a controlle
Action - Performs logic

Getter & Action - Will be prompted when you create a new VF page
Setter - You need to create manually

If this answers your question mark Best Answer it as solution and then hit Like! 

Reference - https://developer.salesforce.com/docs/atlas.en-us.198.0.pages.meta/pages/pages_controller_methods.htm
Reference - (James Loghry) https://developer.salesforce.com/forums/ForumsMain?id=906F00000005KCMIA2

If this answers your question mark Best Answer it as solution and then hit Like!  (https://developer.salesforce.com/docs/atlas.en-us.198.0.pages.meta/pages/pages_controller_methods.htm)


Please try the example below. FYI, Some part it is still incomplete, but you will get the picture.

Custom VF Page

 
<apex:page controller="DocEx1_Controller3" docType="html-5.0" id="redrawArea">
   <apex:form >
      <apex:pageBlock mode="edit" id="block">
    
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
               <apex:outputLabel for="searchText">Search By Date</apex:outputLabel>
               <apex:input type="date" value="{!searchByDate}"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>

         <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
               <apex:outputLabel for="searchText">Search By Name</apex:outputLabel>
               <apex:inputText id="searchByName" value="{!searchByName}"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>

         <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="searchText">Search By Rating</apex:outputLabel>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:selectRadio value="{!searchByRating}">
                    <apex:selectOption itemLabel="Cold" itemValue="Cold"></apex:selectOption>
                    <apex:selectOption itemLabel="Hot" itemValue="Hot"></apex:selectOption>
                    <apex:selectOption itemLabel="Warm" itemValue="Warm"></apex:selectOption>
                </apex:selectRadio>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
            
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <!-- Implement Web Service -->
                <apex:outputLabel for="searchText">Search By State</apex:outputLabel>
                <apex:selectList size="1" value="{!searchByState}">
                    <apex:selectOption itemLabel="" itemValue=""></apex:selectOption>
                    <apex:selectOption itemLabel="KS" itemValue="KS"></apex:selectOption>
                    <apex:selectOption itemLabel="CA" itemValue="CA"></apex:selectOption>
                </apex:selectList>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>

        <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
                <!-- Implement Web Service -->
                <apex:outputLabel for="searchText">Logical Operator</apex:outputLabel>
                <apex:selectList size="1" value="{!searchCriteria}">
                    <apex:selectOption itemLabel="" itemValue=""></apex:selectOption>
                    <apex:selectOption itemLabel="AND" itemValue="AND"></apex:selectOption>
                    <apex:selectOption itemLabel="OR" itemValue="OR"></apex:selectOption>
                </apex:selectList>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>

        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="searchText">Search </apex:outputLabel>
                <apex:commandButton value="Go1!" action="{!doSearch}" rerender="block" status="status"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>

        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="searchText">Search </apex:outputLabel>
                <apex:commandButton value="Reset!" action="{!doReset}" rerender="block" status="status"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        
        <apex:actionStatus id="status" startText="requesting..."/>
        
        <apex:pageBlockSection title="Results" id="results" columns="1">
           <apex:pageBlockTable value="{!results}" var="l" 
                               rendered="{!NOT(ISNULL(results))}">
                               
            <apex:column headerValue="Action">
                    <apex:outputLink value="{!URLFOR($Action.Account.Edit, l.id)}" >Edit</apex:outputLink>
                    <!--<apex:outputlink value="/{!l.Id}">Edit</apex:outputlink>-->
                    
                    <!--<apex:commandLink action="{!doEdit}">Edit
                        <apex:param name="paramId" value="{!l.id}"/>
                    </apex:commandLink>-->             
            </apex:column>
                               
              <apex:column value="{!l.name}"/>
              <apex:column value="{!l.rating}"/>
              <apex:column value="{!l.billingstate}"/>
           </apex:pageBlockTable>
        </apex:pageBlockSection>
      </apex:pageBlock>
      
   </apex:form>
</apex:page>


Custom Controller
 
public class DocEx1_Controller3 {

    String searchCriteria;
    String searchByDate;
    String searchByName;
    String searchByRating1;
    String searchByRating2;
    String searchByRating;
    String searchByState;
    List<Account> results;
    
    public String getSearchCriteria() {
        return searchCriteria;
    }

    public void setSearchCriteria(String s) {
        searchCriteria=s;
    }
    
    public String getSearchByDate() {
        return searchByDate;
    }
    
    public void setSearchByDate(String s) {
        searchByDate=s;
    }

    
    public String getSearchByName() {
        return searchByName;
    }

    public void setSearchByName(String s) {
        searchByName=s;
    }

    public String getSearchByRating() {
        return searchByRating;
    }
    
    public void setSearchByRating(String s) {
        searchByRating=s;
    }

    public String getSearchByState() {
        return searchByState;
    }

    public void setSearchByState(String s) {
        searchByState=s;
    }

    // Go button - Kind of Working
    public PageReference doSearch() {
    
        String searchTerms = '';
        
        if(!String.isEmpty(searchByState)){
            searchTerms += '("' + searchByState + '")';
        }
        
        if(!String.isEmpty(searchByName)){
            if(!String.isEmpty(searchTerms)){
                searchTerms += ' OR ';
            }
            searchTerms += '("' + searchByName + '")';
        }
        
        if(!String.isEmpty(searchTerms)){
            results = (List<Account>)[FIND :searchTerms RETURNING Account(Name, Rating, BillingState)][0];
        }    
        return null;
    }

    // Edit Link - Not Working
    public PageReference doEdit() {
        String paramId = ApexPages.currentPage().getParameters().get('paramId');
        return null;
    }

    // Reset Button - Not Working
    public PageReference doReset() {
        PageReference pg = new PageReference(System.currentPageReference().getURL());
        pg.setRedirect(false);
        return pg;
    }

    public List<Account> getResults() {
        return results;
    }
    


}