buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public with sharing class NewSearchProductController {
 
    public String BaseUrl{get;set;}
    public String ConditionType{get;set;}
    public String ByCondition{get;set;}
    public List<ProductObj> 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<ProductObj>();
    }
 
    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<Product2> 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;}
    }
}