Understanding Salesforce SOQL

What is Salesforce SOQL?

Salesforce SOQL refers to an object query language that is based on one of the most popular database programming languages known as SQL. SOQL is an object oriented query language that is normally used to query data in the Force.com platform. The data model that is used here is based on objects that are linked to each other by relationships. The relationship navigation in this language allows for utilization of data from different object thereby utilizing implicit joins. To put this statement in simple terms, the relationship syntax in sales force SOQL helps joining or connecting data using path traversal.

Salesforce Object Query Language allows you to access virtually anything about any record that exists in your Salesforce database.

Significance of SOQL The fist significance of Salesforce SOQL is that it can be used together with Apex in a trigger. In most cases SOQL is used with Apex and the process is very easy and straight forward.

The second significance is that it Salesforce SOQL allows the users to carry out cross object action in a trigger. This means that it allows you to access objects that are not available in your trigger. Sometimes back, workflow was being used in triggers. The main limitation of using workflow was that you could not do cross object action. This is a limitation that is easily and effectively tacked by Salesforce SOQL. If for example you are writing a trigger on Sales, SOQL allows you to access data and information from a totally unrelated object.

Finally, SOQL is significant in that its mastery is key to the understanding and mastering Apex. Once one starts writing more complex codes, you soon encounter governor limits. Codes can be prevented from hitting such limits by effective use of SOQL. Additional Triggers information is available on salesforce trigger tutorial page. I hope it will deliver more benefits for you.

Where to Write Salesforce SOQL Queries There exist a lot of areas where the queries are written. In some cases; one ends up writing them without knowing that the have written Salesforce SOQL queries. One important area where the queries can be written is in the Data Loaders. In this case, you can just bypass the IU and type the query you want to write in the box.

Apart from the Data Loaders, there are still better places to write these object oriented queries. The Salesforce new tool known as Workbench is another place where the objected oriented queries can be written. To write the queries, all one needs to do is to login to Workbench and follow the guidelines on how to start the procedure.

Features and Properties of Salesforce SOQL Salesforce SOQL has capabilities as well as patterns that allow the developers using it to conceptualize familiar concepts and put them in the required perspectives. Concepts such as joins in SQL are changed into perspective with respect to the SOQL syntax and capabilities.

Salesforce Object Query Language is used to construct simple yet powerful query strings in various applications. They include Query string parameters, Schemer Explorer, Getter Method, Visual force Controller and Apex statement. It is similar to the SELECT command in the Structural Query Language (SQL) and therefore allows you to source object, retrieve a list of fields, and select rows in source object. This is made possible through the use of a combination of the SELECT statement and filtering statements that facilitates returning of data that may be optionally be ordered.

The Salesforce SOQL uses indexes that tend to make it filter queries at a faster rate. The indexes that are used in it include:
  •  Primary keys such as ID, name and the owners field
  •  The Audit Dates that may include the Date of last modification
  •  Custom fields. The customs fields are normally marked as External ID and Unique

There also exists some field that cannot be indexed by this application or database language. They include:
  • The multi-select pick list
  •  Currency fields in an organization that uses multiple currencies
  •  Text fields that are too long
  •  A group of formula fields
  • ·Binary fields that include type blob field type, encrypted texts and file

Relationships Used in SOQL There are two kinds of relationships that are available that allow for building an application on this platform. These two relationships are both 1-many but the difference comes in the kind of support that they offer to the developer. The relationships are defined in terms of a child and parent.

Look up Relationship These kind of relationships that are available in SOQL are flexible in nature; but can be used to create more complex relationships as a building block. In the look up relationships, the orphans are allowed. Therefore, a relationship does not have to exist between individual records though the data model allows a relationship between a child and parent object. Here, existence of a relationship does not dictate usage and visibility of a related record. Finally, this relationship allows for roll up of a value from child records without affecting other related values or records.

Detail Master Relationship This second relationship that exists in the Silver force SOQL is a special case of the first relationship discussed above. It therefore comes with built in semantics where orphans are not allowed in the relationship. This implies that a child record cannot exist on its own. Sharing rules also applies here and whatever records that are set for parent record applies to the child record. Finally, special behavior is also provided in the platform that strictly affects the life cycle of child records. This means that rolling out of a value from the parent record also rolls up the child record value. Additional information is available on how to create master detail relationship in salesforce page.

When to Use Salesforce SOQL

This application is suitable for use on certain specific circumstances. They include
  •  When you know where the object you are querying resides
  •  When you would like to get or source data from a single object or from multiple objects that are related.
  •  When you want to count the total number of records that meet a set criteria
  •  When you would like to sort results or outcomes as a section of the query
  •  In retrieving data from fields, checklist fields and number filed.

Conclusion Salesforce SOQL therefore allows you to construct powerful query strings similar to SELECT command in SQL. Moreover, Salesforce SOQL facilitates specification of source object, list of fields to be retrieved and the conditions of selecting rows from a source object. Read more about triggers on Salesforce trigger best practices.
mm
Amanda is the Lead Author & Editor of Rainforce Blog. Amanda established the Rainforce blog to create a source for news and discussion about some of the issues, challenges, news, and ideas relating to Salesforce usage.