Tag Archives: Salesforce

Difference between Data Loader and Import Wizard in Salesforce

Import Wizard:

  • For simple imports of up to 50000 records.
  • It supports all custom objects and only few standard objects like Account, Contact, Leads, Solution.
  • It supports schedule export.
  • Delete operation is not available.
  • We cannot export data.
  • It doesn’t require installation.
  • While importing, duplicates can be ignored.

Data Loader:

  • For complex imports of any size more than 50000 records.
  • It supports all standard and custom objects.
  • It doesn’t support schedule export.
  • Delete operation is available.
  • We can export data of all custom & standard objects, and can import all custom & standard objects except User standard object.
  • It requires installation.
  • While importing, duplicates cannot be ignored.

Get All Salesforce Users in Role Hierarchy Using Apex


Public with sharing class Sample{
    Public List<string> CusrrentUserRole{get;set;}
    Public List<String> RolesInHierarchy{get;set;}
    Public Sample(){
        CusrrentUserRole = New List<string>();
        CusrrentUserRole.add([SELECT UserRoleId FROM User Where Id =:UserInfo.getUserId() LIMIT 1].UserRoleId);
    Public Void getRollInHierarchy(){
        RolesInHierarchy = New List<Id>();
        RolesInHierarchy = getAllRoleInHierarchy(CusrrentUserRole);
    Public List<string> getAllRoleInHierarchy (List<Id> UserRole) {     
        List<string> currentRoleIds = new List<string>();     
        for(UserRole userRoleName :[SELECT Id,name FROM UserRole Where ParentRoleId  = :UserRole AND ParentRoleID != null]){    
        if(currentRoleIds.size() > 0) {     
        List<String> RoleList = New List<String>();  
        for(UserRole r:[SELECT Name From UserRole Where Id In:currentRoleIds]){
        return RoleList;

Visualforce Page:

<apex:page controller="Sample">
     <apex:commandButton value="Show Roles below my Hierarchy" action="{!getRollInHierarchy}"/> 
   <apex:pageBlock >
   <b> Role below in Hierarchy are : </b>{!RolesInHierarchy}


Get All Objects and Its Fields in Salesforce Org

We can use Schema.getGlobalDescribe() to get all properties of sObject and its fields.

Apex Class:

public class SampleController {
    Public string selectedObj {get;set;}
    public String selectedField {get; set;}
    Public List<Selectoption> getObjList(){
        List<Schema.SObjectType> objList = Schema.getGlobalDescribe().Values();     
        List<SelectOption> objNames = new List<SelectOption>();
        objNames.add(new SelectOption('','-- Select --'));
        for(Schema.SObjectType obj : objList)
            objNames.add(new SelectOption(obj.getDescribe().getName(),obj.getDescribe().getLabel()));
        return objNames;
    public List<SelectOption> getObjectFields() {
        List<SelectOption> fieldNames = new List<SelectOption>();
        fieldNames.add(new SelectOption('','-- Select --'));
            Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            Schema.SObjectType ObjSchema = schemaMap.get(selectedObj);
            Map<String, Schema.SObjectField> fieldMap = ObjSchema.getDescribe().fields.getMap();
            for (String fieldName: fieldMap.keySet()) 
                fieldNames.add(new SelectOption(fieldName, fieldMap.get(fieldName).getDescribe().getLabel()));
        return fieldNames;

Visualforce Page:

<apex:page controller="SampleController">
            <apex:pageBlockSection columns="2">
                <apex:pageBlockSectionItem >
                    <apex:outputlabel value="Object Names :"/> 
                    <apex:actionRegion >      
                        <apex:selectList value="{!selectedObj}" size="1">
                            <apex:selectOptions value="{!ObjList}"/>
                            <apex:actionSupport event="onchange" rerender="objFields"/>
                <apex:pageBlockSectionItem >
                    <apex:outputlabel value="Field Names :"/>   
                    <apex:outputPanel id="objFields">   
                        <apex:actionRegion >  
                            <apex:selectList value="{!selectedField}" size="1">
                                <apex:selectOptions value="{!ObjectFields}"/>


Test Class For Future Method

Future Method:

public class AccountHelper {
	public static void UpdateAccounts(List<Id> accountIds){
		//Get those records based on the IDs
		List<Account> accList = [SELECT Name FROM Account WHERE Id IN : accountIds];
		//Process records

Test Class:

public class TestAccountHelper {
    private static User CreateUser(){
        String orgId = UserInfo.getOrganizationId();
        String standardUserProfileId = [SELECT Id From Profile WHERE Name = 'Standard User'].Id;
        User u = new User(
            FirstName = 'Test',
            LastName = 'User',
            Alias = 'TestUser', 
            profileId = standardUserProfileId ,
            Email = orgId + '@test.org',
            Username = orgId + '@test.org',
            EmailEncodingKey = 'ISO-8859-1',
            LanguageLocaleKey = 'en_US',
            LocaleSidKey = 'en_US',  
            TimeZoneSidKey = 'America/Los_Angeles'
        insert u;
        return u;
    private static Account CreateAccount(){
        Account acc = new Account( Name = 'Test Account', 
                                  Type = 'Technology Partner', 
                                  Industry = 'Technology',
                                  Phone = '9898989898'
        insert acc;
        return acc;
    private static testMethod void testUpdateAccounts(){
        User u = CreateUser();
        System.runAs(u) {
            Account acc = CreateAccount();
            List<Id> accountIds = new List<Id>();
        //Verify account is inserted
        List<Account> accList = [SELECT Id From Account WHERE Name = 'Test Account'];
        System.assertEquals(1, accList.size());