About SOQL (i)

Source: Internet
Author: User

SOQL is the query language in Salesforce, whose full name is Salesforce Object query Language.

Literally, this language is an object-based query language.

In Salesforce, we can build objects, and Salesforce has its own objects, which can be abstracted as a data Table for these objects.

Each object has the properties of the field, and Soql is querying fields under individual objects.

The basic syntax of SOQL is not very different from the SQL we know well, for example:

list<account> accounts = [select ID from Account];

Normally in Apex code, SOQL is unloaded [], and SOQL returns list<object>.

The example is to query the ID of all account under this object.

In SOQL, there is no join in this notation, in Salesforce, object and object have a relationship for lookup relationships, that is, a one-to-many relationship (a finds B, then B is the parent, and A is a child).

When 2 objects have a lookup relationship, SOQL can search through the parent's information (query up), or through the parent lookup (query down).

Use the relationship between account and contact in Salesforce to do an example (Conatact look up account)

list<account> accounts = [select Id,name, (select Id,name from Contact) from account];

At this point, we get a set of account and know all the contact information under each account,

In Apex Code we can use list<contacts> Contacts = Accounts[0]. Contact;

In this way, we can retrieve contacts information again.

Let's do an example of an upward query:list<contact> contacts = [select Id,name,account.name from contact];

In this way, we can get different contacts and he corresponds to his own customer name information.

For the time being, summarize up and down queries today.

About SOQL (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.