Finding Rows in a Child Rowset Using findRowsMatchingCriteria

In addition to using view criteria to filter a view object that you create using newView(), you can also use one to retrieve a subset of the rows in a related collection.

For example, if a TroubleTicket custom object contains a child object collection of related activities, you can process selected activities in the related collection using code as shown below:

def vo = newView('TroubleTicket_c')
vo.appendViewCriteria("Priority_c = 1 and Status_c = 'Open'")
vo.executeQuery()
def vc = null
// Process all open P1 trouble tickets
while (vo.hasNext()) {
  def curTicket = vo.next()
  def activities = curTicket.ActivityCollection_c
  if (vc == null) {
    addBindVariable(activities,'TodaysDate','date')
    vc = newViewCriteria(activities,"ActivityType_c in ('OC','IC') and CreationDate > :TodaysDate")
  }
  // Process the activities created today for inbound/outbound calls
  setBindVariable(activities,'TodaysDate',today())
  def iter = activities.findRowsMatchingCriteria(vc,-1)
  while (iter.hasNext()) {
    def activity = iter.next()
    // process the activity here
  }
}

The newViewCriteria() function accepts an optional third parameter ignoreNullBindVarValues of boolean type that you can use to indicate whether filter expression predicates containing null bind variable values should be ignored. If omitted, the default value of this parameter is false.