function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CarlBCarlB 

Why is this Apex code so slow?

Hello.

I have a class that I use as a wrapper around an SObject:
 
global abstract with sharing class BaseDataObject implements IDataObject {  

	private SObject m_Record;
	
	global BaseDataObject (SObject p_Record) {
		setRecord(p_Record);
	}

	global BaseDataObject () {
	}
	
	global virtual SObject getRecord() {
		return m_Record;
	}

	global virtual void setRecord(SObject p_Record) {
		m_Record = p_Record;
	}
	
	global virtual String getId() {
		return m_Record.id;
	}

	.
	.
	.
}

This class is held in a managed package which I have installed in another dev org, where I have another class that extends that class, e.g.
 
global with sharing class Example extends PKG.BaseDataObject {

	.
	.
	.

}

I then try to use this class, the performance is awful.  For example, if I do this:
 
Example ex = new Example(new Test__c());

ex.Id();

The call to "ex.Id()" takes (according to Salesforce's profiler) about 0.12 milliseconds.  Any other call that involves accessing the m_Record member variable seems to take equally long.

Why is this so slow and is there anything that can be done to speed it up?

Thanks,

Carl




 
sandeep@Salesforcesandeep@Salesforce
Hi CarlB,

Can you please confirm if it is consist behavior or was momentarily. If it is not consistent then it might be due to salesforce instace load otherwise execution took a bit long time.
CarlBCarlB
Hello.

I have tried my tests over a couple of different days and the results are consistent.

I have also tried where the constructor is not across a managed package boundary and it still takes a significant amount of time.

Regards,

Carl