Search
Twitter

Entries in query (3)

Monday
May132013

APEX: Retrieve a Custom Object Field's History

Let's say you have the field "Address" in a custom object labeled "Customer" and you're looking to obtain that particular field's history and tracking details along with the dates on which changes were made. Today, I'll share a query that will help you do just that:

 

SELECT ParentId, OldValue, NewValue, Field, CreatedById, CreatedDate FROM Customer_History where parentId = :CustomerId and Field ='Address__c'
Wednesday
Mar202013

SOQL Date Formats

Coming from an SQL background, I’ve always had issues with SOQL’s date format. So, today, I’m going to share with you some tips on how to utilize SOQL Date queries, specifically using Built in Date Functions:

Before we dig in too deep though, we must know the syntax for Date in Force.com:

YYYY-MM-DD

 

In Force.com, there are two ways of querying Date:

#1 Specify the date in the query

The following query will return all Id’s for all the leads that were created on 2012-12-12 : Select ID, Date from Lead where Date= dateValue (2012-12-12)


#2 Query with a Built in Function

For example, the following query will return all Id’s for the Lead that were created yesterday: Select Id, Date from Lead where Date= YESTERDAY

I hope this helps!

Tuesday
Oct092012

Fix System Query Exception Error

 

What the Heck is This? "System.QueryException: List Has No Rows for Assignment to SObject"

So I was quering Account a = [Select name from account where id=: strld];

and an exception was thrown: System.QueryExceptoin: List has no rows for assignment to SObject.

 

Here is the mistake I made and how to fix it:

List<Account>lst = [Select name from account where id=: strld];