SObjectStream
SObjectStream
is a lazy collection of SObject
instances which implements Iterator<SObject>
.
#
ofConstructs an SObjectStream
with the provided Iterable<SObject>
.
Signature
static SObjectStream of(Iterable<SObject> records)
Example
// List<Accounts> accounts = [...]SObjectStream.of(accounts);SObjectStream.of(Trigger.old);
#
hasNextSignature
virtual Boolean hasNext()
Example
SObjectStream accountStream = SObjectStream.of(Trigger.new); while (accountStream.hasNext()) { Account acc = (Account) accountStream.next(); }
#
nextSignature
virtual SObject next()
Example
SObjectStream largeOpportunities = SObjectStream.of(Trigger.new).filter(Fn.Match.field(Opportunity.Amount).gt(100000));while (largeOpportunities.hasNext()) { Opportunity opp = (Opportunity) largeOpportunities.next();}
#
filterReturns a stream consisting of the elements of this stream that match the given predicate
.
Signature
SObjectStream filter(SObjectPredicate predicate)
#
findReturns an OptionalSObject
wrapping the first record predicate
returns true
for, or an empty OptionalSObject
if no element is found. This consumes the stream.
Signature
OptionalSObject find(SObjectPredicate predicate)
#
forEachIterates through the stream and invokes a function for each record. This consumes the stream.
Signature
void forEach(SObjectFunction fn)
#
mapAllSignature
SObjectStream mapAll(SObjectToSObjectFunction fn)
#
mapSomeSignature
SObjectStream mapSome(SObjectPredicate predicate, SObjectToSObjectFunction fn)
#
removeReturns a stream consisting of the elements of this stream that do not match the given predicate
.
Signature
SObjectStream remove(SObjectPredicate predicate)
Example
#
toListCollects the stream into a List
. This consumes the stream.
Signature
List<SObject> toList()