• veeru_pari
  • NEWBIE
  • 20 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 6
    Likes Received
  • 0
    Likes Given
  • 24
    Questions
  • 52
    Replies
Hi,
I have a requirement like , in a page the user will post the question and the other user or anny other  user can give reply to the question ie he can post the answer and  that Q&A need to  be stored in an object .so how can i achieve this.please let me know any code is there for this functionality in salesforce? 


Thanks
veeraiah
Hi,
I have requirement like i need to search topics based on Tags in vf page so can i please get the code for this functionality.like how we search on stackoverflow
Hi,
I have requirement like i need to search topics based on keys in vf page so can i please get the code for this functionality
Hi,
I have appliction where i am having q&a stored in custom object when i create a new record as of now i am able to searh then in a vf page. Now my req is i need to post the ques from fron end ie from vf page .As of now i am posting it in backend that is in Custom obj.So please let me know the code how to post the ques from front end?


The code i have written is as follows

VFpage:
<apex:page controller="QuesSearchCont" sidebar="false">
<apex:form >
  <apex:pageMessages id="errors" />

  <apex:pageBlock title="Find Me A Question & Answer!" mode="edit">

  <table width="100%" border="0">
  <tr> 
    <td width="200" valign="top">

      <apex:pageBlock title="Parameters" mode="edit" id="criteria">

      <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("question").value,
          document.getElementById("answer").value);
      }
      </script>

      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="Question__c" value="" />
          <apex:param name="Answer__c" value="" />
         
         
      </apex:actionFunction>

      <table cellpadding="0" cellspacing="0">
      <tr>
        <td style="font-weight:bold;">QUESTION<br/>
        <input type="text" id="question" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">ANSWER<br/>
       <input type="text" id="answer" onkeyup="doSearch();"/>
        </td>
      </tr>
            </table>

      </apex:pageBlock>

    </td>
    <td valign="top">

    <apex:pageBlock mode="edit" id="results">

        <apex:pageBlockTable value="{!faq}" var="faqs">

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Question" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="question" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
              <apex:outputField value="{!faqs.Question__c}"/>
            </apex:column>

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Answer" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="answer" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
               <apex:outputField value="{!faqs.Answer__c}"/>
            </apex:column>
        </apex:pageBlockTable>

    </apex:pageBlock>

    </td>
  </tr>
  </table>

  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />          
  </apex:pageBlock>   

  </apex:pageBlock>

  </apex:form>
</apex:page>
Controller:
public with sharing class QuesSearchCont {
// the soql without the order and limit
private String soql {get;set;}
  // the collection of contacts to display
  public List<FAQ__c> faq {get;set;}

  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }

  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'Question__c'; } return sortField;  }
    set;
  }

  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }

  // init the controller and display some sample data when the page loads
  public QuesSearchCont() {
    soql = 'select Question__c, Answer__c from FAQ__c where Question__c!= null';
    runQuery();
  }

  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }

  // runs the actual query
  public void runQuery() {

    try {
      faq = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessages(e);
    }

  }

  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
try{
FAQ__c f=new FAQ__c();
    String question = Apexpages.currentPage().getParameters().get('Question__c');
    String answer = Apexpages.currentPage().getParameters().get('Answer__c');
   
  
    
    soql = 'select Question__c, Answer__c from FAQ__c where Question__c!= null';
     if (!question.equals(''))
      soql += ' and Question__c LIKE \'%'+String.escapeSingleQuotes(question)+'%\'';
    if (!answer.equals(''))
      soql += ' and Answer__c LIKE \'%'+String.escapeSingleQuotes(answer)+'%\'';
   // if (!accountName.equals(''))
     // soql += ' and account.name LIKE \''+String.escapeSingleQuotes(accountName)+'%\''; 
    
    // run the query again
    }
     catch(NullPointerException ne){
     ApexPages.addMessages(ne);
    }
    runQuery();

    return null;
    }
  
 

}
The custom obj name is FAQ having fields question,answe and users.


Thanks
Veeraiah

Hi,
Can i please get the code how tow develop search functionality based on tags in salesforce.(tag search functionality).the user should be able to search the question and answer based on tags.like stackoverflow.


Thanks
Veeru
Hi,
My requirement is like stack overflow.In my req is in the vf page only the user should be able to add FAQs enter the tags and all .while searching it should be able to search using tags and keys also.In one word it should be the replica of stack overflow .Can any body plese provide the code for the same.

Thanks
Chowdary
Hi ,
Ia m getting the following error while runnung the code it is @line 26 in my code i have marked the line 26 please help me on this to solve the error
Visualforce Error

Help for this Page

System.NullPointerException: Argument 1 cannot be null
Class.FAQCu.getSearch: line 26, column 1 )

In the above code the line 26 is marked below it is in getSearch method below is the code where i have hilighted line 26 in the code

public class FAQCu {
public String selectedValue {get;set;}

public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>(); 
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
     // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   } 
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
     
        List<FAQ__c> temp = new List<FAQ__c>();
        String queryString;
   if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
26line//   temp = Database.query(queryString);

      return temp;
      }
    }

VF code 
<apex:page controller="FAQCu" id="theRepeat">
  <apex:form >
    <apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
        <apex:selectOptions value="{!userType}"/>
        <apex:actionSupport event="onchange" rerender="questions"/>
    </apex:selectList>
    <apex:dataTable value="{!search}" var="faq" id="questions">
        <apex:column >
            <apex:outputText value="{!faq.Question__c}"/>
        </apex:column>
        <apex:column >
            <apex:outputText value="{!faq.Answer__c}"/>
        </apex:column>
    </apex:dataTable>

</apex:form>

</apex:page>

Thanks
Veeraiah
My actual requirement was like
i have a custom object in that i have fields questions(data type text area),answers(answer also same ) an pick list having internal user,external user and All users. now my requirement is i want to display the pick list values in vf page and if the user selects internal option in picklist then page should display question and answer related to internal and if he selects ExternalUser it should display Questio and answer of  External user and if he selects all user it should display All the Q&A .So how could i achieve this.For that i wrote the above code .i am getting the pick list but not the Q&A related to that.Please help me on this.
Hi ,
I am getting this error while using the below code in vf(System.NullPointerException: Argument 1 cannot be null )
public class FAQCu {
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();   
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }   
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
       
        List<FAQ__c> temp = new List<FAQ__c>();
     String queryString;
   if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \'AllUsers\' ';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \'InternalUsers\' ';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \'InternalUsers\' ';
/Line 26/temp = Database.query(queryString);
      return temp;
      }
    }
VF
apex:page controller="FAQCu" id="theRepeat">
<apex:form >

<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
  <apex:selectOptions value="{!userType}"/>
</apex:selectList>
</apex:form>
<apex:repeat value="{!search}" var="string" id="theRepeat">
<apex:outputText value="{!string}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>
I am getting the nullpointer while displaying the controller code in vf using output panel .How can i resolve this

public class FAQCu {
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();   
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }   
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
       
        List<FAQ__c> temp = new List<FAQ__c>();
     String queryString;
   if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' AllUsers\' ';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' InternalUsers\' ';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' InternalUsers\' ';
temp = Database.query(queryString);
  
      return temp;
      }
    }
Vf page

<apex:page controller="FAQCu">
<apex:form >

<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
  <apex:selectOptions value="{!userType}"/>
</apex:selectList>
</apex:form>
</apex:page>

In the above vf where and what tags should i write to display theoutput?Please help on this

Thanks

Hi,
I want to display the output of the getsearch method in the below code in vf page so that if i select one pick list i should get the answer

public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();   
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
     // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }   
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
       
        List<FAQ__c> temp = new List<FAQ__c>();
     String queryString;
   if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
      
   temp = Database.query(queryString);
  
      return temp;
      }
Hi ,

In the below code if i try to run i am getting. the error like this (FAQCu Compile Error: Comparison arguments must be compatible types: LIST<String>, String at line 20 column 12)I have hilighted the errior in bold letters in the below code

public class FAQCu {
public List<String> selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();  
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
     // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }  
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
      
        List<FAQ__c> temp = new List<FAQ__c>();
        String queryString;
       Line 20// if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
   temp = Database.query(queryString);
 
      return temp;
      }
    }

and the vf page is:
<apex:page controller="FAQCu">
<apex:form >

<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
  <apex:selectOptions value="{!userType}"/>
</apex:selectList>

</apex:form>
</apex:page>

Please help me on this

Thanks
Veeraiah
Hi,
I have other query where i have a custom object in that i have fields questions(data type text area),answers(answer also same ) an pick list having internal user,external user and All users. now my requirement is i want to display the pick list values in vf page and if the user selects internal option in picklist then page shpuld display question and answer related to internal and if he selects all it should display all the ques and answers.

Will you u please tell me how to achieve this req

Thanks in advance

Veeraiah
Hi ,
i have search code below  where i can search a question with its beginning letter or if i give full question but i want to get the question even  if i given any letter  or word in middile of that question. please help me on this .I hope there might be wrong in like condition.Can i please know how can i solve this?

Here is the code for that
Vf page
<apex:page controller="QuesSearchCont" sidebar="false">
<apex:form >
  <apex:pageMessages id="errors" />

  <apex:pageBlock title="Find Me A Question & Answer!" mode="edit">

  <table width="100%" border="0">
  <tr>
    <td width="200" valign="top">

      <apex:pageBlock title="Parameters" mode="edit" id="criteria">

      <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("question").value,
          document.getElementById("answer").value);
      }
      </script>

      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="Question__c" value="" />
          <apex:param name="Answer__c" value="" />
       
       
      </apex:actionFunction>

      <table cellpadding="0" cellspacing="0">
      <tr>
        <td style="font-weight:bold;">QUESTION<br/>
        <input type="text" id="question" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">ANSWER<br/>
       <input type="text" id="answer" onkeyup="doSearch();"/>
        </td>
      </tr>
            </table>

      </apex:pageBlock>

    </td>
    <td valign="top">

    <apex:pageBlock mode="edit" id="results">

        <apex:pageBlockTable value="{!faq}" var="faqs">

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Question" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="question" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
              <apex:outputField value="{!faqs.Question__c}"/>
            </apex:column>

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Answer" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="answer" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
               <apex:outputField value="{!faqs.Answer__c}"/>
            </apex:column>
        </apex:pageBlockTable>

    </apex:pageBlock>

    </td>
  </tr>
  </table>

  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />        
  </apex:pageBlock> 

  </apex:pageBlock>

  </apex:form>
</apex:page>

Controler:public with sharing class QuesSearchCont {
// the soql without the order and limit
private String soql {get;set;}
  // the collection of contacts to display
  public List<FAQ__c> faq {get;set;}

  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }

  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'Question__c'; } return sortField;  }
    set;
  }

  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }

  // init the controller and display some sample data when the page loads
  public QuesSearchCont() {
    soql = 'select Question__c, Answer__c from FAQ__c where Question__c!= null';
    runQuery();
  }

  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }

  // runs the actual query
  public void runQuery() {

    try {
      faq = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessages(e);
    }

  }

  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
try{
FAQ__c f=new FAQ__c();
    String question = Apexpages.currentPage().getParameters().get('Question__c');
    String answer = Apexpages.currentPage().getParameters().get('Answer__c');
 

  
    soql = 'select Question__c, Answer__c from FAQ__c where Question__c!= null';
    if (!question.equals(''))
      soql += ' and Question__c LIKE \''+String.escapeSingleQuotes(question)+'%\'';
    if (!answer.equals(''))
      soql += ' and Answer__c LIKE \''+String.escapeSingleQuotes(answer)+'%\'';
   // if (!accountName.equals(''))
     // soql += ' and account.name LIKE \''+String.escapeSingleQuotes(accountName)+'%\'';
  
    // run the query again
    }
     catch(NullPointerException ne){
     ApexPages.addMessages(ne);
    }
    runQuery();

    return null;
    }



}
Hi,
My task is how to store FAQ's in a custom object.From the the custom oject i need to display it on vf page.in vf page i need to have two radio buttons like internal and external(assume user are of type internal and external),if we select internal page should display internal FAQs and i f i select external it should display external FAQ's. And also i need to have a searchbox on the page and it should return the FAQs based on search criteria based on keys and tags.


please help me on this

Hi

i have to automate my tool.The prob is i have controller which calculetes govarnor limits of a page.for this i need to include my controller page in each and every page to calculate the limits of that paricular page.i need a global include kind of thing which will actually calculate the limits without including in each and every page.

 

here is what i am doing

 

<apex:include pageName="Glimits"/> as of now iam including this tag as part of every page i actually dont want to include this tag as part of every page but it should work for every page.so ineed some global include kind of access likethat.

 

Thanks,

Veeraiah

Hi ,

Can i know  how to get the classname  from the show depandency view in apex pages

 

In develop>>page>>if we click VFpage we will get the showdependencies so the page is dependent on the Apexclass

 

Now using code i want to get that ApexClass related to the page and store it in a variable.so how can i achieve this

 

 

Thanks,

Veeraiah

Hi,

How can i get the dependent class name of visualforcePage dynamically ..

 

In DEvelop...>Pages..> here we have (show dependencies) .if we click that ShowDependeciesthen it will show the

Apex Class, Trigger and Page References

.

 

Now my ques is how can we get that dependency class,trigger or Pagereference  associated with that page dynamically.And we need  to store that class name in a variable.This we should get for what ever the page we run as there will be many pages.

String variable= 'value'(The Value will be That dependent class name);Here i should store the dependency but it should happen dynamically we should not pass the value manually.

 

Pls reply on this

 

Thanks,

Veeraiah

Hi ,

here is the code snippet which has my ques

 

String variable= 'Batch_CaseEmail'(class name);//Here the value in the string is class name.I want to get the class names like that dynamically after the batch is run from (Monitorin--ApexJobs--ApexClass('Batch_CaseEmail')).There are many batch classes those we need to get dynamicalli and store in variable and this variable is provided as value in Name field marked in below SOQL query
    global Integer getBatchesCount() {
    List<AsyncApexJob> lstjobs=[
    SELECT
        Id,
        TotalJobItems
    FROM
        AsyncApexJob
    WHERE CompletedDate = LAST_N_DAYS:365 AND JobType='BatchApex' AND ApexClassId IN (SELECT Id FROM ApexClass WHERE NamespacePrefix =null  AND Name =:variable)];

Integer jobItemsCount = 0;
Integer batchesCount = 0;
for(AsyncApexJob async : lstjobs) {
    jobItemsCount +=async.TotalJobItems;
    batchesCount++;
   
    }

   return batchesCount;
    }

 

}

 

So ho can i achieve this .Please help me on this

 

Thanks,

Veeraiah

 

Hi ,

Can i please know how can we read APex batch  monitoring
using apex.So the i want to know the count of the batch jobs and need to display the count on VF page or insert in to the custom obj.

 

Thanks,

Veeraiah

 

Hi,
I have appliction where i am having q&a stored in custom object when i create a new record as of now i am able to searh then in a vf page. Now my req is i need to post the ques from fron end ie from vf page .As of now i am posting it in backend that is in Custom obj.So please let me know the code how to post the ques from front end?


The code i have written is as follows

VFpage:
<apex:page controller="QuesSearchCont" sidebar="false">
<apex:form >
  <apex:pageMessages id="errors" />

  <apex:pageBlock title="Find Me A Question & Answer!" mode="edit">

  <table width="100%" border="0">
  <tr> 
    <td width="200" valign="top">

      <apex:pageBlock title="Parameters" mode="edit" id="criteria">

      <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("question").value,
          document.getElementById("answer").value);
      }
      </script>

      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="Question__c" value="" />
          <apex:param name="Answer__c" value="" />
         
         
      </apex:actionFunction>

      <table cellpadding="0" cellspacing="0">
      <tr>
        <td style="font-weight:bold;">QUESTION<br/>
        <input type="text" id="question" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">ANSWER<br/>
       <input type="text" id="answer" onkeyup="doSearch();"/>
        </td>
      </tr>
            </table>

      </apex:pageBlock>

    </td>
    <td valign="top">

    <apex:pageBlock mode="edit" id="results">

        <apex:pageBlockTable value="{!faq}" var="faqs">

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Question" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="question" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
              <apex:outputField value="{!faqs.Question__c}"/>
            </apex:column>

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Answer" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="answer" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
               <apex:outputField value="{!faqs.Answer__c}"/>
            </apex:column>
        </apex:pageBlockTable>

    </apex:pageBlock>

    </td>
  </tr>
  </table>

  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />          
  </apex:pageBlock>   

  </apex:pageBlock>

  </apex:form>
</apex:page>
Controller:
public with sharing class QuesSearchCont {
// the soql without the order and limit
private String soql {get;set;}
  // the collection of contacts to display
  public List<FAQ__c> faq {get;set;}

  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }

  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'Question__c'; } return sortField;  }
    set;
  }

  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }

  // init the controller and display some sample data when the page loads
  public QuesSearchCont() {
    soql = 'select Question__c, Answer__c from FAQ__c where Question__c!= null';
    runQuery();
  }

  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }

  // runs the actual query
  public void runQuery() {

    try {
      faq = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessages(e);
    }

  }

  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
try{
FAQ__c f=new FAQ__c();
    String question = Apexpages.currentPage().getParameters().get('Question__c');
    String answer = Apexpages.currentPage().getParameters().get('Answer__c');
   
  
    
    soql = 'select Question__c, Answer__c from FAQ__c where Question__c!= null';
     if (!question.equals(''))
      soql += ' and Question__c LIKE \'%'+String.escapeSingleQuotes(question)+'%\'';
    if (!answer.equals(''))
      soql += ' and Answer__c LIKE \'%'+String.escapeSingleQuotes(answer)+'%\'';
   // if (!accountName.equals(''))
     // soql += ' and account.name LIKE \''+String.escapeSingleQuotes(accountName)+'%\''; 
    
    // run the query again
    }
     catch(NullPointerException ne){
     ApexPages.addMessages(ne);
    }
    runQuery();

    return null;
    }
  
 

}
The custom obj name is FAQ having fields question,answe and users.


Thanks
Veeraiah

Hi,
My requirement is like stack overflow.In my req is in the vf page only the user should be able to add FAQs enter the tags and all .while searching it should be able to search using tags and keys also.In one word it should be the replica of stack overflow .Can any body plese provide the code for the same.

Thanks
Chowdary
Hi ,
Ia m getting the following error while runnung the code it is @line 26 in my code i have marked the line 26 please help me on this to solve the error
Visualforce Error

Help for this Page

System.NullPointerException: Argument 1 cannot be null
Class.FAQCu.getSearch: line 26, column 1 )

In the above code the line 26 is marked below it is in getSearch method below is the code where i have hilighted line 26 in the code

public class FAQCu {
public String selectedValue {get;set;}

public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>(); 
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
     // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   } 
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
     
        List<FAQ__c> temp = new List<FAQ__c>();
        String queryString;
   if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
26line//   temp = Database.query(queryString);

      return temp;
      }
    }

VF code 
<apex:page controller="FAQCu" id="theRepeat">
  <apex:form >
    <apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
        <apex:selectOptions value="{!userType}"/>
        <apex:actionSupport event="onchange" rerender="questions"/>
    </apex:selectList>
    <apex:dataTable value="{!search}" var="faq" id="questions">
        <apex:column >
            <apex:outputText value="{!faq.Question__c}"/>
        </apex:column>
        <apex:column >
            <apex:outputText value="{!faq.Answer__c}"/>
        </apex:column>
    </apex:dataTable>

</apex:form>

</apex:page>

Thanks
Veeraiah
My actual requirement was like
i have a custom object in that i have fields questions(data type text area),answers(answer also same ) an pick list having internal user,external user and All users. now my requirement is i want to display the pick list values in vf page and if the user selects internal option in picklist then page should display question and answer related to internal and if he selects ExternalUser it should display Questio and answer of  External user and if he selects all user it should display All the Q&A .So how could i achieve this.For that i wrote the above code .i am getting the pick list but not the Q&A related to that.Please help me on this.
Hi ,
I am getting this error while using the below code in vf(System.NullPointerException: Argument 1 cannot be null )
public class FAQCu {
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();   
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }   
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
       
        List<FAQ__c> temp = new List<FAQ__c>();
     String queryString;
   if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \'AllUsers\' ';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \'InternalUsers\' ';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \'InternalUsers\' ';
/Line 26/temp = Database.query(queryString);
      return temp;
      }
    }
VF
apex:page controller="FAQCu" id="theRepeat">
<apex:form >

<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
  <apex:selectOptions value="{!userType}"/>
</apex:selectList>
</apex:form>
<apex:repeat value="{!search}" var="string" id="theRepeat">
<apex:outputText value="{!string}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>
I am getting the nullpointer while displaying the controller code in vf using output panel .How can i resolve this

public class FAQCu {
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();   
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }   
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
       
        List<FAQ__c> temp = new List<FAQ__c>();
     String queryString;
   if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' AllUsers\' ';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' InternalUsers\' ';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' InternalUsers\' ';
temp = Database.query(queryString);
  
      return temp;
      }
    }
Vf page

<apex:page controller="FAQCu">
<apex:form >

<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
  <apex:selectOptions value="{!userType}"/>
</apex:selectList>
</apex:form>
</apex:page>

In the above vf where and what tags should i write to display theoutput?Please help on this

Thanks

Hi,
Can i please get the code how tow develop search functionality based on tags in salesforce.(tag search functionality).the user should be able to search the question and answer based on tags.like stackoverflow.


Thanks
Veeru
Hi,
My requirement is like stack overflow.In my req is in the vf page only the user should be able to add FAQs enter the tags and all .while searching it should be able to search using tags and keys also.In one word it should be the replica of stack overflow .Can any body plese provide the code for the same.

Thanks
Chowdary
I am getting the nullpointer while displaying the controller code in vf using output panel .How can i resolve this

public class FAQCu {
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();   
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }   
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
       
        List<FAQ__c> temp = new List<FAQ__c>();
     String queryString;
   if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' AllUsers\' ';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' InternalUsers\' ';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' InternalUsers\' ';
temp = Database.query(queryString);
  
      return temp;
      }
    }
Vf page

<apex:page controller="FAQCu">
<apex:form >

<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
  <apex:selectOptions value="{!userType}"/>
</apex:selectList>
</apex:form>
</apex:page>

In the above vf where and what tags should i write to display theoutput?Please help on this

Thanks

Hi,
I want to display the output of the getsearch method in the below code in vf page so that if i select one pick list i should get the answer

public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();   
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
     // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }   
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
       
        List<FAQ__c> temp = new List<FAQ__c>();
     String queryString;
   if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
      
   temp = Database.query(queryString);
  
      return temp;
      }
Hi ,

In the below code if i try to run i am getting. the error like this (FAQCu Compile Error: Comparison arguments must be compatible types: LIST<String>, String at line 20 column 12)I have hilighted the errior in bold letters in the below code

public class FAQCu {
public List<String> selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();  
   Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
     // options.add(new SelectOption('All','All'));
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }  
   return options;
}
public List<FAQ__c> getSearch(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
      
        List<FAQ__c> temp = new List<FAQ__c>();
        String queryString;
       Line 20// if(selectedValue=='AllUsers')
   queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
   else if(selectedValue=='InternalUsers')
   queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
   else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
   temp = Database.query(queryString);
 
      return temp;
      }
    }

and the vf page is:
<apex:page controller="FAQCu">
<apex:form >

<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
  <apex:selectOptions value="{!userType}"/>
</apex:selectList>

</apex:form>
</apex:page>

Please help me on this

Thanks
Veeraiah
Hi,
I have other query where i have a custom object in that i have fields questions(data type text area),answers(answer also same ) an pick list having internal user,external user and All users. now my requirement is i want to display the pick list values in vf page and if the user selects internal option in picklist then page shpuld display question and answer related to internal and if he selects all it should display all the ques and answers.

Will you u please tell me how to achieve this req

Thanks in advance

Veeraiah
Hi ,
i have search code below  where i can search a question with its beginning letter or if i give full question but i want to get the question even  if i given any letter  or word in middile of that question. please help me on this .I hope there might be wrong in like condition.Can i please know how can i solve this?

Here is the code for that
Vf page
<apex:page controller="QuesSearchCont" sidebar="false">
<apex:form >
  <apex:pageMessages id="errors" />

  <apex:pageBlock title="Find Me A Question & Answer!" mode="edit">

  <table width="100%" border="0">
  <tr>
    <td width="200" valign="top">

      <apex:pageBlock title="Parameters" mode="edit" id="criteria">

      <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("question").value,
          document.getElementById("answer").value);
      }
      </script>

      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="Question__c" value="" />
          <apex:param name="Answer__c" value="" />
       
       
      </apex:actionFunction>

      <table cellpadding="0" cellspacing="0">
      <tr>
        <td style="font-weight:bold;">QUESTION<br/>
        <input type="text" id="question" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">ANSWER<br/>
       <input type="text" id="answer" onkeyup="doSearch();"/>
        </td>
      </tr>
            </table>

      </apex:pageBlock>

    </td>
    <td valign="top">

    <apex:pageBlock mode="edit" id="results">

        <apex:pageBlockTable value="{!faq}" var="faqs">

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Question" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="question" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
              <apex:outputField value="{!faqs.Question__c}"/>
            </apex:column>

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Answer" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="answer" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
               <apex:outputField value="{!faqs.Answer__c}"/>
            </apex:column>
        </apex:pageBlockTable>

    </apex:pageBlock>

    </td>
  </tr>
  </table>

  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />        
  </apex:pageBlock> 

  </apex:pageBlock>

  </apex:form>
</apex:page>

Controler:public with sharing class QuesSearchCont {
// the soql without the order and limit
private String soql {get;set;}
  // the collection of contacts to display
  public List<FAQ__c> faq {get;set;}

  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }

  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'Question__c'; } return sortField;  }
    set;
  }

  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }

  // init the controller and display some sample data when the page loads
  public QuesSearchCont() {
    soql = 'select Question__c, Answer__c from FAQ__c where Question__c!= null';
    runQuery();
  }

  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }

  // runs the actual query
  public void runQuery() {

    try {
      faq = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessages(e);
    }

  }

  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
try{
FAQ__c f=new FAQ__c();
    String question = Apexpages.currentPage().getParameters().get('Question__c');
    String answer = Apexpages.currentPage().getParameters().get('Answer__c');
 

  
    soql = 'select Question__c, Answer__c from FAQ__c where Question__c!= null';
    if (!question.equals(''))
      soql += ' and Question__c LIKE \''+String.escapeSingleQuotes(question)+'%\'';
    if (!answer.equals(''))
      soql += ' and Answer__c LIKE \''+String.escapeSingleQuotes(answer)+'%\'';
   // if (!accountName.equals(''))
     // soql += ' and account.name LIKE \''+String.escapeSingleQuotes(accountName)+'%\'';
  
    // run the query again
    }
     catch(NullPointerException ne){
     ApexPages.addMessages(ne);
    }
    runQuery();

    return null;
    }



}