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
Ramu SfdcRamu Sfdc 

When ever we click he search we should display the perticular users, colud you please help on this

Hi All,

I have developed A vf page ,when ever we click the search button  some licenced users should display the table. when ever i click it was displaying all the users in the table .

When ever we click he search we should display the perticular users, colud you please help on this.

Thanks in advace .

Regards,
Ramu.Vf page
Debaranjan GhoshDebaranjan Ghosh
Hello

Can you please your VFP code here?
 
Debaranjan GhoshDebaranjan Ghosh
Can you please pasteyour VFP code here?
Ramu SfdcRamu Sfdc
vf htmlVf page 2

controller:
controller
Thanks for the replay debarajan, these are the vf code we dont have access to copy paste out side and it wont allow to paste anywhere.
Debaranjan GhoshDebaranjan Ghosh
Please do me a Favour Ramu . Can you please write the code in a note pad seeing the screenshot and paste it here. I am simply running out of time so requesting you to paste it in this way.
 
Debaranjan GhoshDebaranjan Ghosh
Also I can see a Red Marked </apex:pageblockTable> is there anyt error ?
Debaranjan GhoshDebaranjan Ghosh
I am posting sample search screen for Accounts which is working in the way you are expecting you can comapre it with your code to find the difference which needs to be chnaged
VFP--------------------------------------------------------------------
<apex:page Controller="SearchInVFController">
    <apex:form>
        <apex:inputText value="{!searchKey}" label="Input"/>
        <apex:commandButton value="Search records" action="{!search}"/>
        <apex:commandButton value="Clear records" action="{!clear}"/>
        <apex:pageBlock title="Search Result">
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller----------------------------------------------------------------------------
public class SearchInVFController {
    public list <Account> acc {get;set;}
    public String searchKey {get;set;}
    public SearchInVFController( ) {
    }
    public void search(){
        string searchquery='select Name,id from account where name like \'%'+searchKey+'%\' Limit 10';
        acc= Database.query(searchquery);
    }
    public void clear(){
        acc.clear();
    }
}
Ramu SfdcRamu Sfdc
Thanks Debarajan.
Ramu SfdcRamu Sfdc

When we enter email id of an user and click on seach button i need to display a list of Active users in a apex controller.

Other wise it has to display all the users.

Probelm that i am facing:

I can display all the Active and inactive users in apex controller 

based on your code for examle



 public list <Account> acc {get;set;}
public void search(){
list<Account> lstac = new list<Account>();
If(picklistvalue==abcd){
        string searchquery='select Name,id from account where name like \'%'+searchKey+'%\' Limit 10';
        acc.add(lstac);
}else{
         string searchquery='select Name,id from account where name like \'%'+searchKey+'%\' Limit 10';>>>>> exmp conditon I know
        }
        acc= Database.query(searchquery);
    }

is this is the correct way?

please help me urgent.....

Thanks in advance

Debaranjan GhoshDebaranjan Ghosh
Hello Ramu

I can see in your previous code you used a 2 filter conditions
1. for Active users ( IsActive__c = true )
2. For email id ( OR email__c = \ ' '+SearchStrings+'\')

which is missing in your last code
As a result of which you are getting all the Active and inactive users in apex controller
So you need to change search() as 
public void search(){
        string searchquery='select Name,id from account where IsActive__c = true and email__c like \'%'+searchKey+'%\' Limit 10';
        acc= Database.query(searchquery);
    }

And that should work.
 
Ramu SfdcRamu Sfdc
Hi Debarajan 

My actual code is 




public class userviewcontroller{
    public string searchstring {get;set;}
    public List<userwrapper> userlist {get;set;}
    public strig oppId {get;set;}
    Map<string,user__x> usermap  {get;set;}
    
    public userviewcontroller(ApexPages.StanderdController controller)
    {
    searchstring ='';
    userlist = new List<userwrapper>();
    usermap= new Map<string,user__x>();
    oppId = controller.getId();
    }
    public void serach(){
        opportunity op =new oppertunity();
        if(op.product__c =='Business product'){
            
            string searchquery = 'select Id, ExternalId, Email__c,Pc_number__c,ISLicenced from User__x Where ISLicenced=true And (Email__c=\''+searchstring +'/' OR Pc_number__c=\''+searchstring +'/')';
                
                }else{
                    string searchquery = 'select Id, ExternalId,Email__c,Pc_number__c,ISActive from User__x Where ISActive=true And (Email__c=\''+searchstring +'/' OR Pc_number__c=\''+searchstring +'/')';
                        List<user__x> users = Database.query(searchquery);
                    userlist = new List<userwrapper>();
                    for(user__x Us =users){
                        userlist.add(
                            userwrapper(Us)
                        );
                        usermap.put(Us.ExternalId,Us)
                            }
                }
    }
    
}

Here in if condition we are displaying Licenced users in else we are displaying all 
 
But I am facing issue here

opportunity op =new oppertunity();
        if(op.product__c =='Business product'){
            
            string searchquery = 'select Id, ExternalId, Email__c,Pc_number__c,ISLicenced from User__x Where ISLicenced=true And (Email__c=\''+searchstring +'/' OR Pc_number__c=\''+searchstring +'/')';
                
                }

Could you please correct my code
Debaranjan GhoshDebaranjan Ghosh
Sorry for late reply . Is your problem solved now?
 
Debaranjan GhoshDebaranjan Ghosh
I can see a difference between your dynamic sql and mine

mine

where name like \'%'+searchKey+'%\'
where IsActive__c = true and email__c like \'%'+searchKey+'%\'

yours :
Where ISLicenced=true And (Email__c=\''+searchstring +'/' OR Pc_number__c=\''+searchstring +'/')';

so can you put
system.debug(searchquery);
after
string searchquery = 'select Id, ExternalId, Email__c,Pc_number__c,ISLicenced from User__x Where ISLicenced=true And (Email__c=\''+searchstring +'/' OR Pc_number__c=\''+searchstring +'/')';
to check what SOQL it make and execute the same from Dev Console Query Editor to ensure it was a Valid SOQL