I am trying to run SOQL statement in salesforce.schema tool of FORCE.COM the following query:

Select c.LastName, c.FirstName From Contact c
WHERE (FirstName+' '+LastName) In ('Good Name','Bad Name')

It produces an error.

Can I do this kind of things with SOQL ? If yes, then how I can concatenate fields in the query ?

  • 1
    I guess its better to create formula field and use that instead in query – Mohith Shrivastava Jun 2 '14 at 5:36

SOQL does not support concatenation operation like SQL.

But here is work around for you.

Select c.LastName, c.FirstName From Contact c WHERE name In ('Good Name','Bad Name')

If above soql is for sample and you want to use this on some other fields then you can create formula field that will concatenate two fields and use that in your SOQL.

| improve this answer | |

So the answer is no rightaway .There is no concatenation function in SOQL.

The best is to create a formula field and use the same in your query or why dont you use Name field of contact directly .

Name field is anyways concatenation of FirstName and LastName .

| 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.