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
    Nov 11, 2019 at 18:20
  • @AdrianLarson this link you sent doesn't show how to make dynamic "fields" clause Nov 11, 2019 at 18:23
  • You only have to read between the lines a tiny bit to see it.
    – Adrian Larson
    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? Nov 13, 2019 at 16:56
  • Yes, multiple elements would look like: new List<String> { 'a', 'b', 'c', 'etc.' };.
    – Adrian Larson
    Nov 13, 2019 at 16:56
  • Thank you so much! 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 .