Wednesday 2 January 2013


System.SObjectException: SObject row was retrieved via SOQL without querying the requested field:

This kind of exception that happens when we are trying to access one object property that actually we haven't got through an SOQL query.

Let me explain.

If an Object Lead has Id,Name,Email with it. And if we are writing the below query to retrieve its Id, Name from the object.

Lead Ld;

Ld = [select Id,Name from lead];

if you then access Email property from the Ld instance , sales force will throw the error     System.SObjectException: SObject row was retrieved via SOQL without querying the requested field:      

 To avoid retrieve all the required [here it's email] field in your SOQL query

 

Tuesday 1 January 2013

 Adding data to sets in apex, A small mistake that made me disappointed for a complete day.

In sets we have a built in function to add data to that sets

Eg: Set<String> Str;

Str.add('Hello');

But be careful that we should create  one instance otherwise salesforce won't allow you to insert data to this sets.

Also salesforce will not generate any compile time waring or error message while saving the code.

The right code for the above example is below

Set<String> Str =  new Set<String>();
Str.add('Hello');

Even though it's a blunder sometimes we might forget about this.