In Salesforce, with the SOQL language (Salesforce Object Query Language) is possible to run queries, in order to extract some data from the Salesforce internal database. In SOQL, the method length() does not exist (in SQL exist). To make a query, filtering the record extraction by the number of characters in a specific field, we have two possibilities:
- Create a formula field (e.g. FormulaCity__c) of type Number, and write inside it a simple formula witch calculates the length of the characters:
After doing this, we can make the query with the new formula field:
SELECT Id FROM CustomObject__c WHERE FormulaCity__c = 5
- Otherwise, make the query using the LIKE operator:
SELECT Id FROM CustomObject__c WHERE City__c LIKE '_____'
Both the queries extract all the records that have, in the City__c field, a string with a length of 5 characters.