0

I have a requirement where in dynamic query i have to change the format of a string.Below is the way i have tried i am getting following error after adding getTempStringFormatValue method in the below query:

expecting a right parentheses, found '('

queryString += ' AND (FirstName like :tmpsearchstring OR LastName like :tmpsearchstring OR Name like :tmpsearchstring OR EMail like :tmpsearchstring OR Phone like :getTempStringFormatValue(tmpsearchstring))';

  public static String getTempStringFormatValue(String s) {
    String phoneNumber;
    System.debug('Phone value'+s);
    if (s!=null) 
    { 
     phoneNumber = '('+s.substring(0,3)+')'+' '+s.substring(3,6)+'-'+s.substring(6,10);
     System.debug('format phone'+phoneNumber);
    }

    return phoneNumber;
}
3

You can't call a method inside a dynamic soql query.

You have to store the result in a variable before calling your query. Like this:

String tmpString = getTempStringFormatValue(tmpsearchstring);
queryString += ' AND (FirstName like :tmpsearchstring OR LastName like :tmpsearchstring OR Name like :tmpsearchstring OR EMail like :tmpsearchstring OR Phone like :tmpString)';
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.