You need to sign in to do that
Don't have an account?
SDFC FirstLeveler
I am trying to create a Button on VF Page dynamic search, which will use to search dynamically the records in account but i am an error at line no. 12 Expression cannot be assigned.
The button will search account records if I dont put any values for any
input test fields.
VF page <apex:page controller="DynaSearch" > <apex:form > <apex:pageBlock title="Search"> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputLabel Value="Name"/> <apex:inputText value="{!aName}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel Value="Type"/> <apex:inputText value="{!aType}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockButtons location="Bottom"> <apex:commandButton value="Search" Action="{!search}"/> <apex:commandButton value="Desired Search" Action="{!desiredSearch}"/> </apex:pageBlockButtons> </apex:pageBlock> <apex:pageBlock title="Search Result" rendered="{! !ISNull(a)}"> <apex:pageBlockTable value="{!a}" var="b"> <apex:column value="{!b.Name}"/> <apex:column Value="{!b.Type}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page> Controller Class: public class DynaSearch { public list <Account> a {set;get;} public string aName {set;get;} public string aType {set;get;} public void search(){ a=[SELECT Name, Type from Account where name=:aName and Type=:aType]; } public void desiredSearch(){ string Dsearch; if((aName= Null && aName= '') && (aType= Null && aType='')){ Dsearch ='SELECT Name, Type from Account'; } else if ((aName!=Null && aName!= '') && (aType!=Null && aType!='')){ Dsearch= 'SELECT name, Type from Account where name=\' '+aName+' \' and type=\' '+aType+' \''; } else { if(aName!=Null && aName!= ''){ Dsearch= 'SELECT name, Type from Account where name=\' '+aName+' \''; } else{ if(aType!=Null && aType!=''){ Dsearch= ' SELECT name, Type from Account where type=\' '+aType+' \''; } } } a= Database.query(Dsearch); } }
input test fields.
May I suggest you please refer the below link for reference for code on Dynamic Search Functionality.
- https://dfc-org-production.force.com/forums/ForumsMain?id=9060G000000UaVBQA0
Hope it will be helpful.please mark it as the best answer if the information is informative.
Best Regards
Rahul Kumar
please change below line:
if((aName == Null && aName== '') && (aType == Null && aType !=''))
Please check once and let me know.
Thanks
Varaprasad
please check once below code..
Hope this helps!!!
Let me know if you need more assistance on this.
Thanks
Varaprasad