HOW TO USE OFFSET IN SOQL QUERY?

OFFSET:
OFFSET_SOSL

OFFSET is used to specify the starting row offset into the result set returned by your query. Using OFFSET is helpful for paging into large result sets, in scenarios where you need to quickly jump to a particular subset of the entire results. As the offset calculation is done on the server and only the result subset is returned, using OFFSET is more efficient than retrieving the full result set and then filtering the results locally.

Syntax:
SELECT fieldList
FROM objectType
[WHERE conditionExpression]
ORDER BY fieldOrderByList
LIMIT number_of_rows_to_return
OFFSET number_of_rows_to_skip

Example:
The SOQL query normally returned 100 rows, you could use OFFSET 20 in your query to skip the first 20 rows and returns 21th row to 120th rows.

SELECT Name FROM Account 
WHERE Industry = 'Media' 
ORDER BY Name 
LIMIT 100 
OFFSET 20

Also Read: Pagination Using Offset 
Before using OFFSET Go through this points:

1. The maximum offset is 2,000 rows. Requesting an offset greater than 2,000 will result in a NUMBER_OUTSIDE_VALID_RANGE error.

2. OFFSET is must to be used in a top-level query, and is not allowed in most sub-queries, so the following query is invalid and will return a MALFORMED_QUERY error.

SELECT Name, Id
FROM Account
WHERE Id IN
(
  SELECT Id
  FROM contact
  LIMIT 100
  OFFSET 20
)
ORDER BY Name
OFFSET 20
A sub-query can use OFFSET only if the parent query has a LIMIT 1 clause. Thsi is a pilot feature it is to change in future releases.

3. When using OFFSET, only the first batch of records will be returned for a given query. If you want to retrieve the next batch you’ll need to re-execute the query with a higher offset value.

4. The OFFSET clause is allowed in SOQL used in SOAP API, REST API, and Apex. It’s not allowed in SOQL used within Bulk API or Streaming API.

COMMENTS

BLOGGER
Name

Apex Apex Default Methods Apex Methods Apex_Collections Apps Batch Apex Books CRM eBooks Data Import Wizard Data Management DataLoader Dataloader.io Difference Between Error in Salesforce FAQ's FAQ's-Apex FAQ's-Apps FAQ's-CRM FAQ's-Data loader FAQ's-SOQL & SOSL FAQ'S-Triggers FAQ's-User Profile & Security FAQ's-VF Force.com Explorer Force.com Ide Formulas & Functions Integration Interview Questions Only Latest_Updates Limits&Best Practices Online-Training Reports and Dashboards Salesforce Deployment Salesforce Realtime Examples On Development Salesforce Realtime Task On Admin Salesforce Realtime Tasks Salesforce Realtime Tasks- Apex Salesforce Training Salesforce1 Mobile Sites SOQL Spring'14 Release Triggers User Profile & Security VF Tags VisualForce Winter'14 Release Wizard for Accounts/Contacts Workbench Workflows and Approvals
false
ltr
item
Sfdc Gurukul- All in one place for salesforce and force.com step by step tutorial for beginners: HOW TO USE OFFSET IN SOQL QUERY?
HOW TO USE OFFSET IN SOQL QUERY?
how to use offset in soql,offset in soql salesforce,offset in soql,soql offset rows returned,soql offset statement,soql offset clause,soql offset rows returned,soql offset limit 200,offset soql,offset soql salesforce,soql offset pagination,sfdc soql offset
http://3.bp.blogspot.com/-Erf8R2KCDBI/UlKyrPiJRVI/AAAAAAAABCU/7GtRWPzQVpI/s1600/OFFSET_SOSL.png
http://3.bp.blogspot.com/-Erf8R2KCDBI/UlKyrPiJRVI/AAAAAAAABCU/7GtRWPzQVpI/s72-c/OFFSET_SOSL.png
Sfdc Gurukul- All in one place for salesforce and force.com step by step tutorial for beginners
http://sfdcgurukul.blogspot.com/2013/10/how-to-use-offset-in-soql-query.html
http://sfdcgurukul.blogspot.com/
http://sfdcgurukul.blogspot.com/
http://sfdcgurukul.blogspot.com/2013/10/how-to-use-offset-in-soql-query.html
true
4199533888133360731
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy