Advanced SOQL Statements - FOR VIEW, FOR REFERENCE, UPDATE VIEWSTAT, FOR UPDATE, ALL ROWS - SOQL Basic | Salesforce Funda


FOR VIEW :  This is used to fetch records from last day fetched records.

FOR REFERENCE : To update LastReferencedDate this is used.

UPDATE VIEWSTAT : This updates the articles view statistics for fetched records.The UPDATE VIEWSTAT clause is used in a SELECT statement to report on Salesforce Knowledge article searches and views. It allows developers to update an article’s view statistics.You can use this syntax to increase the view count for every article you have access to online.

FOR UPDATE : FOR UPDATE keyword locks the queried records from being updated by any other Apex Code or Transaction.When the records are locked, other User cannot update them.

ALL ROWS : ALL ROWS keyword in a SOQL query retrieves all the records from the database, including those that have been deleted. This keyword is mostly used to undelete records from the Recycle Bin.

//ALL ROWS  ==>ONLY RUN IN APEX CONTEXT
SELECT ID, Name FROM Account WHERE isDeleted = true ALL ROWS
//FOR UPDATE ==>ONLY RUN IN APEX CONTEXT
SELECT Name, ID, Industry FROM Account WHERE INDUSTRY = 'Media' FOR UPDATE
//FOR REFERENCE
SELECT id, Name, lastreferenceddate FROM Account FOR REFERENCE
//FOR VIEW
SELECT id, Name, lastreferenceddate FROM Account FOR VIEW
//UPDATE VIEWSTAT
SELECT Title FROM FAQ__kav WHERE PublishStatus='online' and Language = 'en_US' and KnowledgeArticleVersion = 'ka230000000PCiy' UPDATE VIEWSTAT

Feature :-