Friday, June 1, 2012

SOQL Features


Group by feature:
May some of you are aware with Group by having count in SFDC. However I am going to share the same here.
We have very good thing is Group By having count. We can put the count to filter the records. My requirement is that if email is duplicates in contact’s record then I need to exclude those records.
Here is the code for that, may it will help you too.
Code:
AggregateResult[] groupedResults = [Select Email from Contact where email =emailed@gmail.com’ group by Email having count(Email)<2];
Description:
Was trying something and came out with an interesting fact which can save us SOQL queries.
Salesforce Object initialization feature:
Up till now the process to update any object was to first query that object using its Ids, and than we used to update that list.
Now if we are having Id of the object than we need not do any SOQL. For ex-
Code:
Opportunity temp = new Opportunity(id = '0063000000Xh92q');
temp.name='Test Update';
update temp;
Description:
This code will update the opportunity with Id=’ '0063000000Xh92q'’. Using this approach we can save many SOQL queries.

No comments:

Post a Comment