Salesforce interview questions and answers : All about SOQL : Part 1

Que 1. What is replacement of SELECT *  in SOQL?

Ans 1. SELECT FIELDS(ALL) FROM Account.

            SELECT FIELDS(STANDARD) FROM Account

            SELECT FIELDS(CUSTOM) FROM Account

* Can not add duplicates fields in select statement

Que 2. Which standard objects acts as Junction object ?

Ans 2. 

1. OpportunityLineItem

2. OpportunityContactRole

3. CaseSolution

4. CaseArticle

5 PriceBookEntry

Que 3. What is FOR UPDATE in SOQL?

Ans 3. FOR UPDATE is used for - prevent race conditions

                                                    - thread safety problems

      e.g. Account[] accts=[Select Id from Account limit 2 FOR UPDATE];

To lock records,records can't be modified by other user either through code or UI.

Que 4. What are types of SOQL queries?

Ans 4. 

1. Parent to Child (Inner query)

When we want to get related child records from for a particular parent records or set of parent record then we use concept of inner query.

e.g. SELECT Id,Name,(SELECT Id,Name from Contacts ) From Account where Id in :accList

2. Child to Parent

Sometimes we want to fetch Parent records while working on child records then we go for child to Parent query

e.g SELECT Id,AccountId,Name,Account.ShippingAddrerss From Contact

Que 5. Write SOQL query to Select All Contacts from Contact object where FirstName is equal to LastName.

Ans 5.

1. Create a formula field checkbox IsFirstAndLastNameSame on Contact.
2. Write the condition as FirstName==LastName .
3. Now you can write SOQL As below :
[ SELECT Id,FirstName ,LastName FROM Contact where IsFirstAndLastNameSame__c=true]

Comments

Popular posts from this blog

Salesforce interview questions and answers : All About Triggers : Part 1

All About Future methods