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
salesforce@14salesforce@14 

Add Radio Button in Dynamic search functionality.

Hi All,
 
         I need to add radio button functionality in already implemented dynamic search filter condition. Create 2 radio buttons as AND and OR in VF Page, if i click on AND button , all filter search condition criteria should satisfy and if i click  OR button, any one of the filter search condition should satisfy.

Thanks in advance.
sandeep sankhlasandeep sankhla
Hi,

Simply create 2 buttons on VF page and bind them with get set variables from page..by default value will be false..onclick change that to true and where you are making dynamic query there you can check the value and add OR or AND conditiona ccordingly..

let me kbiw if you need any code help on this...

Thanks
Sandeep
surasura
I have wriiten some dummy code here  hope it help
<apex:form>
    <apex:pageBlock title="TestPage" id="block" >
     
      <!-- other stuff -->
       <apex:selectRadio value="{!SearchOption}">
            <apex:selectOption itemLabel="AND Search" itemvalue="AND"/>
            <apex:Selectoption itemLabel="OR Search" itemvalue="OR"/>
            <apex:actionsupport event="onchange" rerender="block" action="{!yourSearch}"/>
       </apex:selectRadio>
      
      <!-- result table --->
   
    </apex:pageBlock>
    
    </apex:form>
 
public with sharing class TestControlller{
    public String SearchOption{get;set;}
    
    //other stuff
    
    public void yoursearch()
    {
    
         if(SearchOption == 'AND')
         {
            //AND Logic
         
         
         }
         
         else
         {
         
           // OR logic
         
         }
         
         
    
    
    
    }
    
    
}

 
salesforce@14salesforce@14
Thanks for your reply.

Hi sandeep sankhla,

                                    can u give me the code for this functionality.

Thanks.
                                  
sandeep sankhlasandeep sankhla
Hi ,

You can refer the code which Sura has mentiuoned and if still you dont get then let me know...also share your code where you have created dynamic query so I can guide you there only ..

Thanks
salesforce@14salesforce@14
Hi sandeep sankhla,

         I tried but i am not getting. This is my part of code.

    if(wherecond != '')
          {
            Fullquery = 'SELECT '+fieldsToDisplay + ' FROM '+objectname+' WHERE '+ wherecond +' ORDER BY NAME LIMIT 100';
            system.debug('==Fullquery===='+Fullquery);
            masterlist=Database.query(Fullquery);
            selectedfields = fieldsToDisplay.split(',');
            system.debug('==selectedfields===='+selectedfields);
          }


Thanks.
sandeep sankhlasandeep sankhla
Plese share the code where you are framing "wherecond"  ...
sandeep sankhlasandeep sankhla
Hi..

So as Sura mentione dyou just declare a string variable on pageside which will hold the value if it is AND or OR...then simply in you rdosearch method when we are preoaring the string and adding and you add this variable

wherecond =wherecond+' '+returendcondtion+' and '; replace this line with

wherecond =wherecond+' '+returendcondtion+SearchOption;

also replace this line also
 wherecond = wherecond.subString(0,wherecond.lastIndexOf(' and '));
with
 wherecond = wherecond.subString(0,wherecond.lastIndexOf(SearchOption));

so if SearchOption will haev AND it will append AND else OR it will Append..

please check and let me know if it helps..

thanks

 
salesforce@14salesforce@14
Hi

Thank you very much. I try the following code and let you know.

Thanks.


 
sandeep sankhlasandeep sankhla
Hi ,

Then you can set the default value from constructor...

in your constructor you can initalize that string to default value which is AND or OR..then it will work..

Thanks
Sandeep
sandeep sankhlasandeep sankhla
Hi sai,

You just need to set the default value for your string..please check and let me know if that helps..

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer


 
salesforce@14salesforce@14
Hi sandeep sankhla,

I did like this.

 Public List<SelectOption> getradiobutton()
    {
        Option = new List<SelectOption>();  
        Option.add(new SelectOption('AND','AND'));
        Option.add(new SelectOption('OR','OR'));
        return Option;
    }

I passed this string in the page like 
            <apex:selectOptions value="{!radiobutton}"> </apex:selectOptions>
But i am not getting ouput.

Thanks.
sandeep sankhlasandeep sankhla
In constructor you do this..

radiobutton = 'AND';
salesforce@14salesforce@14
Hi,

But i dont understand what is the need of this.

Thanks.
 
sandeep sankhlasandeep sankhla
Hi,

You should provide default value ...

Can you paste your entire pade and class code..let me have a look ..
sandeep sankhlasandeep sankhla
Hi ,

Have you tried what I said..as A best practise we should always initalize all our variables before using so I was asking to initalize
radio = default value in constructor..

If you need default value then you can assign else you can assign blank and if you dont select anything it will not add any filter in your query..

Both the cases you can do..initalize it to blank
radio = "";

Thanks
salesforce@14salesforce@14
Hi,

I tried like this string radio=''; in constructor but i am not getting.

Thanks.
sandeep sankhlasandeep sankhla
Hi,

you need to check this string and then make the queru
if(wherecond != '' && radio != '')
                {
                    Fullquery = 'SELECT '+fieldsToDisplay + ' FROM '+objectname+' WHERE '+ wherecond +' ORDER BY NAME LIMIT 100';
                    system.debug('==Fullquery===='+Fullquery);
                    masterlist=Database.query(Fullquery);
                    selectedfields = fieldsToDisplay.split(',');
                    system.debug('==selectedfields===='+selectedfields);
                }
else
{
   Fullquery = 'SELECT '+fieldsToDisplay + ' FROM '+objectname+' ORDER BY NAME LIMIT 100';
                    system.debug('==Fullquery===='+Fullquery);
                    masterlist=Database.query(Fullquery);
                    selectedfields = fieldsToDisplay.split(',');
                    system.debug('==selectedfields===='+selectedfields);
}

if that is blank then no condition ..

Please add this else block and blank check in if condition and let me know if it helps..

Thanks,
Sandeep