public with sharing class NewSearchProductController { public String BaseUrl{get;set;} public String ConditionType{get;set;} public String ByCondition{get;set;} public List dataList{get;set;} public NewSearchProductController() { } public void init(){ BaseUrl = URL.getSalesforceBaseUrl().toExternalForm(); String path = URL.getCurrentRequestUrl().getPath(); if (path.indexOf('/apex') > 0) { BaseUrl += path.substring(0, path.indexOf('/apex')); } else if (path.indexOf('production/') > 0) { BaseUrl += '/production'; } dataList = new List(); } public void doSearch(){ System.debug('ByCondition:'+ByCondition); dataList.clear(); String soql = 'select id,Name,ProductCode,Product_ECCode__c,Description from Product2 where id != null'; if(ConditionType == 'name'){ soql += ' and Name like \'%' + ByCondition + '%\''; } if(ConditionType == 'code'){ soql += ' and ProductCode like \'%' + ByCondition + '%\''; } if(ConditionType == 'eccode'){ soql += ' and Product_ECCode__c like \'%' + ByCondition + '%\''; } soql += ' limit 100'; System.debug('soql:'+soql); List productList = Database.query(soql); if(productList!=null && productList.size()!=0){ System.debug('productList.size():'+productList.size()); for(Product2 p : productList){ ProductObj obj = new ProductObj(); obj.id = p.id; obj.code = p.ProductCode; obj.name = p.Name; obj.eccode = p.Product_ECCode__c; obj.description = p.Description; dataList.add(obj); } } } public class ProductObj{ public String code{get;set;} public String eccode{get;set;} public String name{get;set;} public String id{get;set;} public String description{get;set;} } }