Tag Archives: salesforce apex controller

Salesforce Apex: Namespace and Field Name in AggregateResult

In Salesforce SOQL, we can use the aggregate function to summarize data in query. When an aggregate function is used, Salesforce will return the result as AggregateResult object and we can retrieve the value by calling AggregateResult.get(‘field name’). For example:

for(AggregateResult ar : [select count(Id), Business_Type__c from Account group by Business_Type__c]){
	system.debug(ar.get('expr0'));		//get the value of count(id)
	system.debug(ar.get('Business_Type__c'));	//get the grouped by field value

However, things get a little bit tricky when you have a namespace in the Salesforce instance and you have custom field in the SOQL. The sample query will still work, but you will get an error saying “Invalid aggregate result field” when you are trying to retrive the value of custom field.

To overcome this, you can choose to:

Option 1

Prepend the custom field with a namespace, for instance,

system.debug(ar.get('namespace__Business_Type__c'));	//get the grouped by field value

Option 2

Use alias in the SOQL to represent a custom field in query result.

for(AggregateResult ar : [select count(Id), Business_Type__c businesstype from Account group by Business_Type__c]){
	system.debug(ar.get('businesstype'));	//get the grouped by field value

Personally, I would prefer to use Option 2 as I don’t have to hard code the namespace in all the SOQL.

Wedid: Customized Quote Form with E-Signature


Salesforce has an out-of-box feature which allows user to create Quote with form templates and saved as PDF.
However, the customer is looking for additional feature to enable their clients to be able to sign on the quote electronically via mobile devices, i.e. smart phones, tablets, etc. As such, a customized Quote form with the support of electronic signature is implemented in Salesforce.


  • Generate customized Quote template including all the relevant information.
  • Signature can be signed on the customized form electronically.
  • The Quote form can be saved as PDF file with or without the signature.

Related Objects Quote
Components Visualforce page + Apex Controller
Complexity Difficult