[SalesForce] Apex: HTML email status to get open count

I'm writing some Apex to list how many times a certain email has been opened. How can I access the "HTML Email Status" object from the lead?

List<Lead> leads = [SELECT Id, Email, (SELECT Id, Subject FROM ActivityHistories WHERE Subject LIKE 'Email: Hello, %.') FROM Lead];
for (Lead l: leads) {
    if (l.activityHistories.size() > 0) {
        System.debug('History: ' + l.activityHistories);
    }
}

I don't think I can get the read count from the activity histories object, so what can I do to change it?

Best Answer

You'll have to get creative, because the object you're looking for is EmailStatus, which is currently only available as a describeSObjects parameter. You can probably use Andrew Fawcett's Metadata Wrapper to get the describe for this object, but you can't use any normal queries on the object.