Skip to content

QueryFactory support: For Update #192

@cropredyHelix

Description

@cropredyHelix

A handy enhancement would be a new fluent method on fflib_QueryFactory that supports the For Update clause

.addForUpdate()

the addForUdpate would do a getOrderings().clear() as you can't Order By with For Update. This would avoid code within a Selector class like this:

public override String getOrderby() {return 'OrderItemNumber';}

/* other selector methods here... */

public virtual OrderItem[] selectSomethingCoolAvoidLockingIssues(set<ID> ids)  {
  fflib_QueryFactory oiQF = newQueryFactory()
		.setCondition('Id IN :ids' +
		              ' AND Type__c IN (\'FOO\',\'BAR\')' );
  oiQF.getOrderings().clear();	// no Order BY if FOR UPDATE
  String soql = oiQF.toSOQL() + ' FOR UPDATE';

  return Database.query(soql); 
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions