2

In SOSL can I add a variable to the fields? As:

FIND {Clinica} IN Name Fields RETURNING Account(VARIABLE HERE)

Thanks

3
  • You would need Dynamic SOSL.
    – Adrian Larson
    Commented Nov 11, 2019 at 18:20
  • @AdrianLarson this link you sent doesn't show how to make dynamic "fields" clause Commented Nov 11, 2019 at 18:23
  • You only have to read between the lines a tiny bit to see it.
    – Adrian Larson
    Commented Nov 11, 2019 at 18:25

1 Answer 1

3

Dynamic SOSL is what you need.

List<String> fields = new List<String> { 'Name' };
String term = 'FIND \'Clinica\' IN Name Fields RETURNING Account (' + String.join(fields, ',') + ')';
3
  • Thanks, Adrian! if i need more than 1 field do i separate with comma? Commented Nov 13, 2019 at 16:56
  • Yes, multiple elements would look like: new List<String> { 'a', 'b', 'c', 'etc.' };.
    – Adrian Larson
    Commented Nov 13, 2019 at 16:56
  • Thank you so much! Commented Nov 13, 2019 at 16:57

You must log in to answer this question.

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