Skip to content

Instantly share code, notes, and snippets.

@krystiancharubin
Created March 11, 2016 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krystiancharubin/597771a8e1c2de61584f to your computer and use it in GitHub Desktop.
Save krystiancharubin/597771a8e1c2de61584f to your computer and use it in GitHub Desktop.
global static String getSOQL(String objectTypeName, List < String > fieldList) {
List < String > conditionals = new List < String > ();
for (String field: fieldList) conditionals.add(field + ' != null');
String soql = 'SELECT {!fieldList} FROM {!objectTypeName} WHERE {!conditionals}';
return soql
.replace('{!fieldList}', String.join(fieldList, ','))
.replace('{!objectTypeName}', objectTypeName)
.replace('{!conditionals}', String.join(conditionals, ' OR '));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment