Skip to main content
2 of 2
added 336 characters in body
Boris Bachovski
  • 16.3k
  • 8
  • 50
  • 88

As far as I can see, this would do the job:

[SELECT Id, Email__c FROM Project__c WHERE Criteria__c = :criteria ORDER BY Some_Date__c, External_Id__c DESC][0]

Therefore your function would be:

public Project__c getRecord(String criteria) 
{
    return [SELECT Id, Email__c FROM Project__c WHERE Criteria__c = :criteria ORDER BY Some_Date__c, External_Id__c DESC][0];
}

You can add try catch block to make sure you don't get exceptions if there no such records btw...

Boris Bachovski
  • 16.3k
  • 8
  • 50
  • 88