function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

SOQL Substring within Select Statement

How would you substring an ID within a select statement.  Would like only the first 15 characters of the ID. 

For instance:  Select id.substring(0, 15) from Opportunity

Rahul SharmaRahul Sharma

Hi WorkingForYou,

I don't think, we can substring records of SOQL query result in query itself.
Can think of 2 options:

1. Iterate over Opportunity list, perform substring and store it a Map for processing furthur.
2. Another easier way to achieve it would be with creating a formula field which copies first 15 char's and retrieve n use that field in Query.

vinod ram 9vinod ram 9
As we know that, Select command in SOQL allows you specify the source object ( Custom or Standard ), and list of fields to retrieve and conditions for selecting the Rowsin sources object.

SOQL doesn’t support all advanced features of the SQL SELECT command. For example, you can’t use SOQL to perform arbitrary join operations, use wildcards in field lists, or use calculation expressions.

Please click on below link for your reference,