Tag Archives: Salesforce.com

How to add a list of records to a map in Salesforce?

Normally we used to do something like this:

Map<Id,Contact> mapContact =  new Map<Id,Contact>();
public static void addListToMap(List<Contact> conList){
	for(Contact con:conList){
		mapContact.put(con.id,con);
	}
}

Here the processing time will be more(CPU execution time will be more), because we are iterating over a for loop to construct a map.

The best way to construct the map where we can avoid iteration like this:

public static void addListToMap(List<Contact> conList){
	Map<Id,Contact> mapContact =  new Map<Id,Contact>(conList);
}

Here the processing time will be very less.

How SOQL differs from SQL?

  • No INSERT, UPDATE or DELETE statements, only SELECT.
  • No command execution.
  • No wild cards for fields, all fields must be explicitly typed.
  • No JOIN statement. However, we can include information from parent objects like Select name, phone, account.name from contact.
  • No UNION operator.
  • Queries cannot be chained together.

How to query data which was modified in specific time limit in Salesforce?

Below is the SOQL to query data which was modified between 8 PM and 10 PM.

Sample SOQL:

SELECT Id, LastModifiedDate FROM Contact WHERE LastModifiedDate = TODAY AND HOUR_IN_DAY(LastModifiedDate) >= 20 AND HOUR_IN_DAY(LastModifiedDate) < 22