0

I have the following method that I'm using SOSL to search against the Product2 object:

public PageReference searchProducts()
{
    try {
        List<List<Product2>> searchResults = [FIND :keyword IN ALL FIELDS RETURNING Product2(Id, Name, Manufacturer__c, Style_Number__c, Color__c, Size__c, Product_Name__c, Tag_Style__c)];    
        results = new List<Product2>();
        string query = 'select Id, Name, Manufacturer__c, Style_Number__c, Color__c, Size__c, Product_Name__c, Tag_Style__c from Product2 where Manufacturer__c like \'' + keyword + '%\'';
        List<Product2> accountMatches = Database.query(query);      
        for(Product2 p : searchResults[0]) {
            results.add(p);
        }
        results.addAll(accountMatches);
        resultSetSize = results.size();
    }
    catch(Exception ex) {
        resultSetSize = null;
        ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage());
        ApexPages.addMessage(msg);
    }
    return null;
}  

The manufacturer__c field is a formula field which looks up to the account is not a searchable field because it gets the value at runtime. I was thinking of creating a new field on the product called "searchableManufacturer__c" as a text field and populate it with the formula value and use that field to search against the account. Is there another way to search the account name and include in the results besides creating a new field and workflow to populate the text field from the formula?

1 Answer 1

0

The three main methods for copying data this way are: triggers, workflows, and Process Builder. Any of the three methods will work, but you'll probably want to prefer clicks over code, if possible.

2
  • thanks for the response. I was attempting to try and search both the account and product table and use an inner class to store the values from both objects in a generic sObject to avoid creating another field and workflow to populate a searchable text field that is a duplicate.
    – Dman100
    Jun 5, 2018 at 20:51
  • I got it working. See edited method code above.
    – Dman100
    Jun 5, 2018 at 23:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .