Sunday 16 December 2012

Field expression not allowed for generic SObject.

Field expression not allowed for generic SObject : You cannot use direct reference or assignment when working with sObjects. Instead you must use their get and put methods.

So instead of
sObject s = [SELECT Id, Name FROM Account LIMIT 1];
// This is allowed
ID id = s.Id;
// The following lines result in errors when you try to save
String x = s.Name;
System.debug(id+' a ***** b '+x); 

you need to do:
sObject s = [SELECT Id, Name FROM Account LIMIT 1];
// This is allowed
ID id = s.Id;
// This is allowed
String x = String.valueOf( s.get('Name') );
System.debug(id+' a ***** b '+x);

Same applies to assigning values to sObjects. Instead of:
sObject s = [SELECT Id, Name FROM Account LIMIT 1];
// This is allowed
ID id = s.Id;
// The following lines result in errors when you try to save
s.Name = 'Test';
System.debug(id+' a ***** b '+x); 

you need to do:
sObject s = [SELECT Id, Name FROM Account LIMIT 1];
// This is allowed
ID id = s.Id;
// The following lines result in errors when you try to save
s.put('Name', 'Test'); 
System.debug(id+' a ***** b '+x); 

Monday 3 December 2012

Habits of Highly Efficient Visualforce Pages & Class

Habits of Highly Efficient Visualforce Pages & Class.

1) "Transcient" keyword to cut down view state

2) User Remoting to replace actionsupport, reduces view state and speed of return and allows for direct passing parameters, YOU are responsible for rerendering

3) Streaming API, actionPoller is crap

4) Asynchronous @future methods

5) Optimise SOQL queries (use limit, filter etc)

6) Standard Set Controllers

7) Limit data on the page, (135k viewstate, 15mb of markup)

8) Do not use salesforce resources (showheader false, standardstylesheets false)


Map of Id & List of An object for set Records of particular records.

Snippt of Code :

***********************************************************************

Map<Id, List < Temp__c > mapAccIdListTemp = new Map<Id, List<Temp__c>>();
List<Temp__c> listTemp = new List<Temp__c>();

for(Temp__c Temp : [SELECT Id, Account__c FROM Temp__c]){            
 if(mapAccIdListTemp.containsKey(Temp.Account__c)){
  listTemp = mapAccIdListTemp.get(Temp.Account__c);
 }
 else {
  listTemp = new List<Temp__c>();
 }
 listTemp.add(Temp);
 mapAccIdListTemp.put(Temp.Account__c, listTemp);
}

***********************************************************************