Rather disappointingly for Blobs this assertion fails:
System.assert(Blob.valueOf('abc') == Blob.valueOf('abc'));
though the Apex Expression Operators documentation over ambitiously says that:
Unlike Java, == in Apex compares object value equality, not reference equality, except for user-defined types.
So it seems that to test equality where the blobs have the same size requires the blobs to be put through EncodingUtil.base64Encode which may lead to heap limit problems e.g.:
private static Boolean eq(Blob b1, Blob b2) {
if (b1.size() == b2.size()) {
String s1 = EncodingUtil.base64Encode(b1);
String s2 = EncodingUtil.base64Encode(b2);
return s1 == s2;
} else {
return false;
}
}
I there a better way to go?