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
Rakesh MRakesh M 

Database.query

Hi,

I have some data posted below in table No#1. When I select  value 'TS' through picklist, I'm not getting expected output as in Table No#2. After executing the code mentioned below. My output comes as in image No#1. Please help me in showing the data as expected in Table No#2.

Table No#1
CustomerName 1TypeAssignmentTotal
XKO_1234Aarushi TechnologyTSIDC03151311703,482.19
XKO_1234Aarushi TechnologyTSILL031526229510,435.92
XKO_1234Aarushi TechnologyBCUTIBR52015081700-4,704.41
XKO_1234Aarushi TechnologyVDCRIDC041636186-3,420.00
XKO_1234Aarushi TechnologyVDVPN0816977251328,477.71
XKO_1234Aarushi TechnologyABETH101205766037,122.82
XKO_1234Aarushi TechnologyBCILL0314200209968.23

Table No#2
CustomerName 1TypeAssignmentTotal
XKO_1234Aarushi TechnologyTSIDC03151311703,482.19
XKO_1234Aarushi TechnologyTSILL031526229510,435.92

Image No#1
User-added image

Code for Program:-
public class soql 
{
    public list<f_97__c> f{set;get;}
    public list<selectoption> options{set;get;} 
    public list<string> selected{set;get;}
    public string query {set;get;}
    public soql(){
        options =new list<selectoption>();
        selected=new list<string>();
        list<string> types = new list<string>{'TS','BC','VD','BR','AC','AB'};
        selectoption n = new selectoption('none','-None-');
        options.add(n);
        for(string s:types){
            selectoption op = new selectoption(s,s);
            options.add(op);
        }
    }
    public void method(){
        f=[select name_1__c, sap_code__c, assignment__c,type__c,total__c from f_97__c limit 999];
    }
    public void getdata(){        
        for(String s: selected)
        {       
            if(s!='none'){                          
                query ='select name_1__c, sap_code__c,assignment__c,type__c,total__c from f_97__c where type__c=:s';
            }
        }
        f=Database.query(query);
    }    
}
<apex:page controller="soql" tabStyle="lead">
 <apex:form >
 <apex:pageBlock title="f.97">
 <apex:pageBlockButtons location="top">
<apex:commandButton value="Outstanding" action="{!method}"/>
<apex:commandButton value="Filter" action="{!getdata}"/>
</apex:pageBlockButtons>
<apex:pageblocksection >
<apex:pageblocksectionitem >
<apex:outputtext value="Select Type"/>
<apex:selectList multiselect="true" value="{!selected}" size="1" >
 <apex:selectOptions value="{!options}" />
 </apex:selectList>
</apex:pageblocksectionitem>
</apex:pageblocksection>
<apex:pageBlockTable value="{!f}" var="a">
 <apex:column value="{!a.SAP_CODE__c}"/>
<apex:column value="{!a.Name_1__c}"/>
 <apex:column value="{!a.Type__c}"/>
 <apex:column value="{!a.Assignment__c}"/>
<apex:column value="{!a.Total__c}"/>
 </apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Thanks in advance.

Warm Regards,
Rakesh Mungelkar.