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
Nitin SharmaNitin Sharma 

I want to create a vf page for displaying account in two section One for Active account and another for Inactive account. depend on search string.

I created vf page and controller but while I am searching, getting an error 
''line 1:56 no viable alternative at character '"'
Error is in expression '{!search}' in component <apex:commandButton> in page testactiveacc: Class.activeAccount.search: line 18, column 1
"

Vf page
<apex:page standardController="Account" extensions="activeAccount" tabStyle="Account">  
  <apex:form > 
  <apex:sectionHeader title="User Global Search" subtitle="Result"/> 
  <apex:pageBlock >
      <apex:pageBlockSection columns="1">
          <apex:pageBlockSectionItem >
              <label>Quick Search</label>
              <apex:outputPanel >
                  <apex:inputText value="{!searchstring}" label="Input"/>
                  <apex:commandButton value="Search records" action="{!search}" reRender="pgId1,pgId2" status="ajaxId"/>
                  &nbsp;<apex:actionStatus startText="Searching..." id="ajaxId"></apex:actionStatus>
              </apex:outputPanel>
          </apex:pageBlockSectionItem>
      </apex:pageBlockSection>
  </apex:pageBlock>
  
  
    
     
   <apex:pageBlock title="Search Active Result" id="pgId1">  
    <apex:pageblockTable value="{!acc}" var="a">  
     <apex:column headerValue="Name" >  
      <apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>       
     </apex:column> 
     <apex:column headerValue="Active" >  
       <apex:outputlink >{!a.Active__c}</apex:outputlink>
     </apex:column> 
     
     <apex:column value="{!a.id}"/>  
    </apex:pageBlockTable>     
   </apex:pageBlock>   
   
   <apex:pageBlock title="Search Inactive Result" id="pgId2">  
    <apex:pageblockTable value="{!acc1}" var="a">  
     <apex:column headerValue="Name" >  
      <apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>       
     </apex:column> 
    <apex:column headerValue="Active" >  
       <apex:outputlink >{!a.Active__c}</apex:outputlink>
     </apex:column>
     
     <apex:column value="{!a.id}"/>  
    </apex:pageBlockTable>     
   </apex:pageBlock>   
   
  </apex:form>  
 </apex:page>

Controller class
public with sharing class activeAccount {
  
   public list <Account> acc {get;set;}
   public list <Account> acc1 {get;set;}
   public string searchstring {get;set;} 
  
   public string value1 {get;set;} 
   
   
    
   public activeAccount (ApexPages.StandardController controller) {
     
   }  
   public void search(){  
     if(searchstring != null && searchstring != '' ){  
     string searchquery='select Name, id,Active__c from Account where Active__c ="Yes" AND Name like \'%'+searchstring+'%\'  Limit 10';  
       string searchquery1='select Name, id,Active__c from Account where Active__c ="No" AND Name like \'%'+searchstring+'%\'  Limit 10';  
     acc = Database.query(searchquery); 
     acc1 = Database.query(searchquery1); 
     }
     }
     
    
   }
Code not working. Can any one help.
 
Best Answer chosen by Nitin Sharma
Amit Singh 1Amit Singh 1
Try below code for apex. double codes(") are not supported into Apex.
public with sharing class activeAccount {
  
   public list <Account> acc {get;set;}
   public list <Account> acc1 {get;set;}
   public string searchstring {get;set;} 
  
   public string value1 {get;set;} 
   
   
    
   public activeAccount (ApexPages.StandardController controller) {
     
   }  
   public void search(){  
     if(searchstring != null && searchstring != '' ){  
     string searchquery='select Name, id,Active__c from Account where Active__c =\'Yes\' AND Name like \'%'+searchstring+'%\'  Limit 10';  
       string searchquery1='select Name, id,Active__c from Account where Active__c =\'No\' AND Name like \'%'+searchstring+'%\'  Limit 10';  
     acc = Database.query(searchquery); 
     acc1 = Database.query(searchquery1); 
     }
     }
     
    
   }

 

All Answers

Amit Singh 1Amit Singh 1
Try below code for apex. double codes(") are not supported into Apex.
public with sharing class activeAccount {
  
   public list <Account> acc {get;set;}
   public list <Account> acc1 {get;set;}
   public string searchstring {get;set;} 
  
   public string value1 {get;set;} 
   
   
    
   public activeAccount (ApexPages.StandardController controller) {
     
   }  
   public void search(){  
     if(searchstring != null && searchstring != '' ){  
     string searchquery='select Name, id,Active__c from Account where Active__c =\'Yes\' AND Name like \'%'+searchstring+'%\'  Limit 10';  
       string searchquery1='select Name, id,Active__c from Account where Active__c =\'No\' AND Name like \'%'+searchstring+'%\'  Limit 10';  
     acc = Database.query(searchquery); 
     acc1 = Database.query(searchquery1); 
     }
     }
     
    
   }

 
This was selected as the best answer
Nitin SharmaNitin Sharma
Thanks Amit singh.
Nitin SharmaNitin Sharma
@Amit 
But I am not able to override account tab with this VF page.
Can you help
 
Amit Singh 1Amit Singh 1
What problem u facing while overiding the vf page What steps are u following?
Nitin SharmaNitin Sharma
VF page not available in the list for override account tab with VF page.
Amit Singh 1Amit Singh 1
Please verify that you are using below steps
1) Setup -> Accounts -> Button Links and Actions -> Select the button you want to override (View)->  Select Visualforce Page -> Select your page.

As I have trige in my org and it's working.
Nitin SharmaNitin Sharma
I want to override account tab with this vf page. Step i followed :-
1) Setup -> Accounts -> Button Links and Actions -> Account Tab->Edit->  Select Visualforce Page -> 
VF page not available in list...
Amit Singh 1Amit Singh 1
You need to include recordSetVar="accounts" attribute into Your VF page.

Also you need to create a new Constructor like below
public activeAccount (ApexPages.StandardSetController stdcontroller) {
     
   }