Using a Simple View Criteria

To find custom or standard objects using a view criteria, perform the following steps:

  1. Create a view object with the newView() function

  2. Append a view criteria with the appendViewCriteria() function, using an appropriate filter expression

  3. Execute the query by calling executeQuery()

  4. Process the results

The example below queries the TroubleTicket custom object to find the trouble tickets assigned to a particular staff member with id 100000000089003 and which have a status of Working.

/*
 * Query all 'Working'-status trouble tickets assigned to a staff member with id 100000000089003
 */
// 1. Use the newView() function to get a view object
def vo = newView('TroubleTicket_c')
// 2. Append a view criteria using a filter expression
vo.appendViewCriteria("AssignedTo_Id_c = 100000000089003 and Status_c = 'Working'")
// 3. Execute the query
vo.executeQuery()
// 4. Process the results
if (vo.hasNext()) {
  def row = vo.next()
  // Do something here with the current result row
}