Tag Archives: SOQL

Big Objects in Saleforce

What is Big Object?

  • Big Object means 100s of billions of record on AppCloud.
  • It is a new capability with highly scalable object to store and manage large amount of data on the Salesforce platform.
  • This feature helps to engage directly with customers by preserving all your historical customer event data.
  • Big Objects are built by Salesforce to provide consistent performance whether there is 1 million records, 100 million, or even 10 billion records.

Use Cases:

  • Audit and Tracking: Track and maintain a long-term view of your user’s usage of Salesforce or your customer’s usage of your products for analysis or compliance purposes.
  • 360 view of Customers: Now data models can be extended to contain billing infos/ecommerce transactions/any other info related to customers.
  • Historical Data Archive: Maintain access to historical data for analysis or compliance purposes while optimizing the performance of your core CRM or Force.com applications.

Considerations:

  • It is provided as a pilot to selected premium customers.
  • The Big Objects cannot be created from the UI. We have to take help of the Metadata APIs to create one.
  • Big Objects don’t support triggers however they support object and field permissions.
  • BigObject don’t support standard UI elements (Home Pages, Detail Pages, List Views), But It can be used in Visualforce Page and Lightning components.
  • Data can be populated to the Big Objects via SFDC APIs/Bulk APIs/using Apex(insertImmediate() method).
  • The only SOQL relationship queries available are based on a lookup field from a BigObject to a standard or custom object.
  • Mostly Async SOQL would be used for the querying the Big Objects. Single level child-to-parent relationship queries and aggregate queries are supported.
  • Big Objects don’t support transactions.
  • We can create up to 100 Big Objects per org. The limits for BigObject fields are similar to the limits on custom objects, and depend on your org’s license type.
  • Big Objects don’t appear in the Setup UI until they are deployed.
  • Big Objects don’t appear in Salesforce1.

SOQL Query To Get Users with Salesforce User License

Get all Users with User License:

List<User> userList = [Select Id, Name, Profile.UserLicense.Name From User];

Get Users with specific User License:

List<User> userList = [Select Id, Name, Profile.UserLicense.Name From User WHERE Profile.UserLicense.Name = 'Salesforce'];

System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop

You might get a QueryException in a SOQL for loop with the message Aggregate query has too many rows for direct assignment, use FOR loop. This exception is sometimes thrown when accessing a large set of child records (200 or more) of a retrieved sObject inside the loop, or when getting the size of such a record set.

For example, the query in the following SOQL for loop retrieves child contacts for a particular account. If this account contains more than 200 child contacts, the statements in the for loop cause an exception.

for (Account acc : [SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WHERE Id IN ('<ID value>')]) { 
    
}

In order to avoid System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop, make sure the sub query is limited as follows.

for (Account acc : [SELECT Id, Name, (SELECT Id, Name FROM Contacts LIMIT 200) FROM Account WHERE Id IN ('<ID value>')]) { 
    
}

How to get picklist values based on record type in Visualforce page?

Here in below example I’ve a custom object “Customer__c”, which has two record types “HR” and “Marketing”.

Apex Class:

public with sharing class recordTypeSample{

    public String selectedRT {get;set;}
    public List<SelectOption> recordTypeList {get;set;}
    public Customer__c customer {get;set;}
    
    public recordTypeSample(){
    
        customer = new Customer__c();
        recordTypeList = new List<SelectOption>();
        getRecordTypeList();
    
    }
    
    public void getRecordTypeList(){
         
        List<RecordType> rtList = [SELECT Id,Name FROM RecordType WHERE SObjectType='Customer__c'];
        recordTypeList.add(new SelectOption('--None--', '--None--'));
        for(RecordType rt : rtList)
        {
            recordTypeList.add(new SelectOption(rt.Id, rt.Name));
        }
    }
    
     public void getPickListValues(){
     
        if(selectedRT != null){
            customer = new Customer__c(RecordTypeId = selectedRT);
        }
    }
}

Visualforce Page:

<apex:page controller="recordTypeSample">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:selectList value="{!selectedRT}" size="1" multiselect="false" label="Record Type" title="Record Type" id="recordTypes"> 
                    <apex:actionSupport event="onchange" action="{!getPickListValues}" reRender="categoryPicList" />
                    <apex:selectOptions   value="{!RecordTypeList}" /> 
                </apex:selectList>
                <apex:inputField id="categoryPicList" value="{!customer.Category__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

HR Record Type Picklist :

Marketing Record Type Picklist :