• SFDC Lightning 18
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 11
    Replies
Hi Guys, Is it possible to embed iframes in lightning component.please let me know any blogs with sample code.
Hi Team Please help me the below test calsses for apex.Thanks in advanced.

Apex class 1 : 
 
public with sharing class OpportunityEditForm_Ctrl {
    private static Map<String, Schema.FieldSet> fieldSetMap;
    
    @AuraEnabled
    public static FieldSetForm getForm(Id recordId, String objectName, String fieldSetName) {
        
        getObjectFieldSets(objectName);
        FieldSetForm form = new FieldSetForm();
        try{
            form.scopes = [SELECT Id, Name,Approved_Scope__c,Opportunity__c,Price_Type__c,Scope_Description__c,TotalValue__c 
                               FROM Scope__c WHERE Opportunity__c =: recordId];
            
            system.debug('===fieldSetName===='+fieldSetName);
            if(!String.isBlank(fieldSetName)){
                form.fields.addAll(getFields(fieldSetName));
        }
        
        }catch(Exception ex){
            System.debug('--- ' + ex.getMessage() + '--- ' + ex.getLineNumber());
            throw new AuraHandledException(ex.getMessage());
        }
        return form;
    }
    
    @AuraEnabled
    public static Id submitUIValues(String jsonObject, String recordId, List<Scope__c> lstScopes){
        Id returnId = null;
        try{
            System.debug('jsonObject ' + jsonObject);
            System.debug('recordId ' + recordId);
            Opportunity objOPP = (Opportunity) JSON.deserialize(jsonObject, Opportunity.Class);
            Map<Id, Opportunity> mapOpp = new Map<Id, Opportunity>{recordId => objOPP};
            system.debug('===mapOpp=='+mapOpp);
            getObjectFieldSets(Id.valueOf(recordId).getSobjectType().getDescribe().getName());
            List<String> lstFields = getFields('Clone_Opportunity_Field_Set');
            
            List<sObject> clonedOppty = SObjectAllFieldCloner.cloneObjects(new List<Id>{recordId}, Opportunity.getsObjectType(), 
                                                                          mapOpp, lstFields);
            if(clonedOppty.isEmpty()){
                return null;
            }
            objOPP = (Opportunity)clonedOppty[0];
            /* objOPP.Pricebook2Id =  [SELECT Id, Pricebook2Id FROM Opportunity WHERE Id =: recordId].Pricebook2Id;    */
            insert objOPP;
            
            Map<Id, Scope__c> oliMap = new Map<Id, Scope__c>(lstScopes);
            List<String> lstProductFields = new List<String>{
                'Name', 'Price_Type__c', 'TotalValue__c', 'Scope_Description__c'
            }; 
            List<Sobject> lstSobjectProducts = SObjectAllFieldCloner.cloneObjects(new List<Id>(new Map<Id, Scope__c>(lstScopes).KeySet()), 
                                                                                                             Scope__c.getsObjectType(),
                                                                                 oliMap, lstProductFields);
            
            for(Sobject OLI: lstSobjectProducts){
                OLI.put('Opportunity__c', objOPP.Id);
            }
            System.debug('------ lstSobjectProducts' + lstSobjectProducts);
            insert lstSobjectProducts;
            System.debug('------ lstSobjectProducts' + lstSobjectProducts);
            returnId = objOPP.Id;
        }
        catch(Exception ex){
            System.debug('--- ' + ex.getMessage() + '--- ' + ex.getLineNumber());
            throw new AuraHandledException(ex.getMessage());
        }
        return returnId;
    }
    
    private static void getObjectFieldSets(String objectName){
        Schema.SObjectType objectType = Schema.getGlobalDescribe().get(objectName);
        Schema.DescribeSObjectResult objectDescribe = objectType.getDescribe();
        fieldSetMap = objectDescribe.fieldSets.getMap();
    }
    
    
    private static List<String> getFields( String fieldSetName) {
        Schema.FieldSet fieldSet = fieldSetMap.get(fieldSetName);
        List<Schema.FieldSetMember> fieldSetMembers = fieldSet.getFields();
        List<String> fields = new List<String>();
        for (Schema.FieldSetMember fsm : fieldSetMembers) {
            fields.add(fsm.fieldPath);
        }
        return fields;
    }
    
    public class FieldSetForm {
        @AuraEnabled public List<String> fields;
        @AuraEnabled public List<Scope__c> scopes;
        public FieldSetForm() {
            fields = new List<String>();
            scopes = new List<Scope__c>();
        }
    }
}

Apex Class 2
 
public class SObjectAllFieldCloner {
    
    // Clone a list of objects to a particular object type
    // Parameters
    // - List<sObject> sObjects - the list of objects to be cloned
    // - Schema.SobjectType objectType - the type of object to be cloned.
    // The sObjects you pass in must include the ID field,
    // and the object must exist already in the database,
    // otherwise the method will not work.
    public static List<sObject> cloneObjects(List<Id> sObjectIds, Schema.SObjectType objectType, 
                                                Map<Id, Sobject> mapSobject, List<String> lstFields){
        
        // A list of fields for the sObject being cloned
        List<String> sObjectFields = new List<String>();
        // A list of new cloned sObjects
        List<sObject> clonedSObjects = new List<sObject>();
        
        // Get all the fields from the selected object type using
        // the get describe method on the object type.
        if(objectType != null){
            sObjectFields.addAll(objectType.getDescribe().fields.getMap().keySet());
        }
        /* Using the list of sObject IDs and the object type,
        we can construct a string based SOQL query
        to retrieve the field values of all the objects.*/
        
        String allSObjectFieldsQuery = 'SELECT ' + sObjectFields.get(0);
        
        for (Integer i=1 ; i < sObjectFields.size() ; i++){
            allSObjectFieldsQuery += ', ' + sObjectFields.get(i);
        }
        
        allSObjectFieldsQuery += ' FROM ' +
                                objectType.getDescribe().getName() +
                                ' WHERE ID IN: sObjectIds' ;
        
        
        System.debug('SOQL **** ' + allSObjectFieldsQuery);
        
        try{
            // Execute the query. For every result returned,
            // use the clone method on the generic sObject
            // and add to the collection of cloned objects
            for (SObject sObjectFromDatabase:Database.query(allSObjectFieldsQuery)){
                Sobject sobjFromCmp = mapSobject.get(sObjectFromDatabase.Id);
                for(String fieldAPI:lstFields){
                    system.debug('===='+fieldAPI);
                    sObjectFromDatabase.put(fieldAPI, sobjFromCmp.get(fieldAPI));
                }
                if(objectType.getDescribe().getName() == 'OpportunityLineItem'){//added this because it was throwing error like we can't provide unitprice and total together
                    sObjectFromDatabase.put('TotalPrice', null);
                }
                clonedSObjects.add(sObjectFromDatabase.clone(false,true));
            }
            System.debug('clonedSObjects **** ' + clonedSObjects);
        } catch (exception e){
            System.debug('======>>'+e);
        }
        return clonedSObjects;
    }
}

 
Guys Please help me the below test calsses for apex.Thanks in advanced.

Apex class 1 : 
 
public with sharing class OpportunityEditForm_Ctrl {
    private static Map<String, Schema.FieldSet> fieldSetMap;
    
    @AuraEnabled
    public static FieldSetForm getForm(Id recordId, String objectName, String fieldSetName) {
        
        getObjectFieldSets(objectName);
        FieldSetForm form = new FieldSetForm();
        try{
            form.scopes = [SELECT Id, Name,Approved_Scope__c,Opportunity__c,Price_Type__c,Scope_Description__c,TotalValue__c 
                               FROM Scope__c WHERE Opportunity__c =: recordId];
            
            system.debug('===fieldSetName===='+fieldSetName);
            if(!String.isBlank(fieldSetName)){
                form.fields.addAll(getFields(fieldSetName));
        }
        
        }catch(Exception ex){
            System.debug('--- ' + ex.getMessage() + '--- ' + ex.getLineNumber());
            throw new AuraHandledException(ex.getMessage());
        }
        return form;
    }
    
    @AuraEnabled
    public static Id submitUIValues(String jsonObject, String recordId, List<Scope__c> lstScopes){
        Id returnId = null;
        try{
            System.debug('jsonObject ' + jsonObject);
            System.debug('recordId ' + recordId);
            Opportunity objOPP = (Opportunity) JSON.deserialize(jsonObject, Opportunity.Class);
            Map<Id, Opportunity> mapOpp = new Map<Id, Opportunity>{recordId => objOPP};
            system.debug('===mapOpp=='+mapOpp);
            getObjectFieldSets(Id.valueOf(recordId).getSobjectType().getDescribe().getName());
            List<String> lstFields = getFields('Clone_Opportunity_Field_Set');
            
            List<sObject> clonedOppty = SObjectAllFieldCloner.cloneObjects(new List<Id>{recordId}, Opportunity.getsObjectType(), 
                                                                          mapOpp, lstFields);
            if(clonedOppty.isEmpty()){
                return null;
            }
            objOPP = (Opportunity)clonedOppty[0];
            /* objOPP.Pricebook2Id =  [SELECT Id, Pricebook2Id FROM Opportunity WHERE Id =: recordId].Pricebook2Id;    */
            insert objOPP;
            
            Map<Id, Scope__c> oliMap = new Map<Id, Scope__c>(lstScopes);
            List<String> lstProductFields = new List<String>{
                'Name', 'Price_Type__c', 'TotalValue__c', 'Scope_Description__c'
            }; 
            List<Sobject> lstSobjectProducts = SObjectAllFieldCloner.cloneObjects(new List<Id>(new Map<Id, Scope__c>(lstScopes).KeySet()), 
                                                                                                             Scope__c.getsObjectType(),
                                                                                 oliMap, lstProductFields);
            
            for(Sobject OLI: lstSobjectProducts){
                OLI.put('Opportunity__c', objOPP.Id);
            }
            System.debug('------ lstSobjectProducts' + lstSobjectProducts);
            insert lstSobjectProducts;
            System.debug('------ lstSobjectProducts' + lstSobjectProducts);
            returnId = objOPP.Id;
        }
        catch(Exception ex){
            System.debug('--- ' + ex.getMessage() + '--- ' + ex.getLineNumber());
            throw new AuraHandledException(ex.getMessage());
        }
        return returnId;
    }
    
    private static void getObjectFieldSets(String objectName){
        Schema.SObjectType objectType = Schema.getGlobalDescribe().get(objectName);
        Schema.DescribeSObjectResult objectDescribe = objectType.getDescribe();
        fieldSetMap = objectDescribe.fieldSets.getMap();
    }
    
    
    private static List<String> getFields( String fieldSetName) {
        Schema.FieldSet fieldSet = fieldSetMap.get(fieldSetName);
        List<Schema.FieldSetMember> fieldSetMembers = fieldSet.getFields();
        List<String> fields = new List<String>();
        for (Schema.FieldSetMember fsm : fieldSetMembers) {
            fields.add(fsm.fieldPath);
        }
        return fields;
    }
    
    public class FieldSetForm {
        @AuraEnabled public List<String> fields;
        @AuraEnabled public List<Scope__c> scopes;
        public FieldSetForm() {
            fields = new List<String>();
            scopes = new List<Scope__c>();
        }
    }
}

Apex class 2 :
 
public class SObjectAllFieldCloner {
    
    // Clone a list of objects to a particular object type
    // Parameters
    // - List<sObject> sObjects - the list of objects to be cloned
    // - Schema.SobjectType objectType - the type of object to be cloned.
    // The sObjects you pass in must include the ID field,
    // and the object must exist already in the database,
    // otherwise the method will not work.
    public static List<sObject> cloneObjects(List<Id> sObjectIds, Schema.SObjectType objectType, 
                                                Map<Id, Sobject> mapSobject, List<String> lstFields){
        
        // A list of fields for the sObject being cloned
        List<String> sObjectFields = new List<String>();
        // A list of new cloned sObjects
        List<sObject> clonedSObjects = new List<sObject>();
        
        // Get all the fields from the selected object type using
        // the get describe method on the object type.
        if(objectType != null){
            sObjectFields.addAll(objectType.getDescribe().fields.getMap().keySet());
        }
        /* Using the list of sObject IDs and the object type,
        we can construct a string based SOQL query
        to retrieve the field values of all the objects.*/
        
        String allSObjectFieldsQuery = 'SELECT ' + sObjectFields.get(0);
        
        for (Integer i=1 ; i < sObjectFields.size() ; i++){
            allSObjectFieldsQuery += ', ' + sObjectFields.get(i);
        }
        
        allSObjectFieldsQuery += ' FROM ' +
                                objectType.getDescribe().getName() +
                                ' WHERE ID IN: sObjectIds' ;
        
        
        System.debug('SOQL **** ' + allSObjectFieldsQuery);
        
        try{
            // Execute the query. For every result returned,
            // use the clone method on the generic sObject
            // and add to the collection of cloned objects
            for (SObject sObjectFromDatabase:Database.query(allSObjectFieldsQuery)){
                Sobject sobjFromCmp = mapSobject.get(sObjectFromDatabase.Id);
                for(String fieldAPI:lstFields){
                    system.debug('===='+fieldAPI);
                    sObjectFromDatabase.put(fieldAPI, sobjFromCmp.get(fieldAPI));
                }
                if(objectType.getDescribe().getName() == 'OpportunityLineItem'){//added this because it was throwing error like we can't provide unitprice and total together
                    sObjectFromDatabase.put('TotalPrice', null);
                }
                clonedSObjects.add(sObjectFromDatabase.clone(false,true));
            }
            System.debug('clonedSObjects **** ' + clonedSObjects);
        } catch (exception e){
            System.debug('======>>'+e);
        }
        return clonedSObjects;
    }
}

 
CountCheckbox : CountCheckbox: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object ()

 
trigger CountCheckbox on Contact (after delete, after insert, after undelete,
after update) {

    Contact[] cons;
    if (Trigger.isDelete)
        cons = Trigger.old;
    else
        cons = Trigger.new;

    // get list of accounts
    Set<ID> acctIds = new Set<ID>();
    for (Contact con : cons) {
            acctIds.add(con.AccountId);
    }
    
    List<account> accountsToUpdate=new list<Account>();
   
   
    Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([select Id
                                                            ,AccountId,Is_Promoter__c,Is_Detractor__c,Is_Passive__c,Is_Promoter_ETS__c,Is_Detractor_ETS__c,Is_Passive_ETS__c,CES_Value__c,CES_Count__c
                                                            from Contact
                                                            where AccountId in :acctIds]);

    Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
                                                                 ,RMT_Promoters_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);
    Map<ID, Account> acctsToUpdate2 = new Map<ID, Account>([select Id
                                                                 ,RMT_Detractors_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);    
    Map<ID, Account> acctsToUpdate3 = new Map<ID, Account>([select Id
                                                                 ,RMT_Passive_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);   
    Map<ID, Account> acctsToUpdate4 = new Map<ID, Account>([select Id
                                                                 ,ETS_Promoters_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);
    Map<ID, Account> acctsToUpdate5 = new Map<ID, Account>([select Id
                                                                 ,ETS_Detractors_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);    
    Map<ID, Account> acctsToUpdate6 = new Map<ID, Account>([select Id
                                                                 ,ETS_Passive_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]); 
    Map<ID, Account> acctsToUpdate7 = new Map<ID, Account>([select Id
                                                                 ,No_of_CES_response__c
                                                                  from Account
                                                                  where Id in :acctIds]);     
    Map<ID, Account> acctsToUpdate8 = new Map<ID, Account>([select Id
                                                                 ,Total_sum_of_CES_response__c
                                                                  from Account
                                                                  where Id in :acctIds]); 

    if(!acctsToUpdate.isEmpty())
    {
    for (Account acct : acctsToUpdate.values()) 
    {
        Set<ID> conIds = new Set<ID>();
        for (Contact con : contactsForAccounts.values()) 
        {
            if (con.AccountId == acct.Id && con.Is_Promoter__c == TRUE)
                conIds.add(con.Id);
        }
        if (acct.RMT_Promoters_Count__c != conIds.size())
            acct.RMT_Promoters_Count__c = conIds.size();
    }

    update acctsToUpdate.values();
    }  
    if(!acctsToUpdate2.isEmpty())
    {
    for (Account acct2 : acctsToUpdate2.values()) {
        Set<ID> conIds2 = new Set<ID>();
        for (Contact con2 : contactsForAccounts.values()) {
            if (con2.AccountId == acct2.Id && con2.Is_Detractor__c == TRUE)
                conIds2.add(con2.Id);
        }
        if (acct2.RMT_Detractors_Count__c != conIds2.size())
            acct2.RMT_Detractors_Count__c = conIds2.size();
    }
    
    update acctsToUpdate2.values();
    }
    if(!acctsToUpdate3.isEmpty())
    {
    for (Account acct3 : acctsToUpdate3.values()) {
        Set<ID> conIds3 = new Set<ID>();
        for (Contact con3 : contactsForAccounts.values()) {
            if (con3.AccountId == acct3.Id && con3.Is_Passive__c == TRUE)
                conIds3.add(con3.Id);
        }
        if (acct3.RMT_Passive_Count__c != conIds3.size())
            acct3.RMT_Passive_Count__c = conIds3.size();
    }

    update acctsToUpdate3.values();
    }
    if(!acctsToUpdate4.isEmpty())
    {
    for (Account acct4 : acctsToUpdate4.values()) {
        Set<ID> conIds4 = new Set<ID>();
        for (Contact con4 : contactsForAccounts.values()) {
            if (con4.AccountId == acct4.Id && con4.Is_Promoter_ETS__c == TRUE)
                conIds4.add(con4.Id);
        }
        if (acct4.ETS_Promoters_Count__c != conIds4.size())
            acct4.ETS_Promoters_Count__c = conIds4.size();
    }

    update acctsToUpdate4.values();
    }
    if(!acctsToUpdate5.isEmpty())
    {
    for (Account acct5 : acctsToUpdate5.values()) {
        Set<ID> conIds5 = new Set<ID>();
        for (Contact con5 : contactsForAccounts.values()) {
            if (con5.AccountId == acct5.Id && con5.Is_Detractor_ETS__c == TRUE)
                conIds5.add(con5.Id);
        }
        if (acct5.ETS_Detractors_Count__c != conIds5.size())
            acct5.ETS_Detractors_Count__c = conIds5.size();
    }

    update acctsToUpdate5.values();
    }
    if(!acctsToUpdate6.isEmpty())
    {
    for (Account acct6 : acctsToUpdate6.values()) {
        Set<ID> conIds6 = new Set<ID>();
        for (Contact con6 : contactsForAccounts.values()) {
            if (con6.AccountId == acct6.Id && con6.Is_Passive_ETS__c == TRUE)
                conIds6.add(con6.Id);
        }
        if (acct6.ETS_Passive_Count__c != conIds6.size())
            acct6.ETS_Passive_Count__c = conIds6.size();
    }

    update acctsToUpdate6.values();
    }
    if(!acctsToUpdate7.isEmpty())
    {
    for (Account acct7 : acctsToUpdate7.values()) {
        Set<ID> conIds7 = new Set<ID>();
        for (Contact con7 : contactsForAccounts.values()) {
            if (con7.AccountId == acct7.Id && con7.CES_Count__c != 0 )
                conIds7.add(con7.Id);
        }
        if (acct7.No_of_CES_response__c != conIds7.size())
            acct7.No_of_CES_response__c = conIds7.size();
    }
    
    update acctsToUpdate7.values();
    }
    
     Map<Id, Account> acc= new Map<Id, Account>([Select Id, Total_sum_of_CES_response__c From Account Where Id In :acctIds]);
    AggregateResult[] groupedResults = [SELECT AccountId,SUM(CES_Value__c)amt FROM contact where AccountId in:acctIds group by AccountId];
    if(!groupedResults.isEmpty())
    {
      for (AggregateResult ar : groupedResults ) {
        acc.get(String.valueOf(ar.get('Accountid'))).Total_sum_of_CES_response__c = Integer.valueOf(ar.get('amt'));
        accountsToUpdate.add(acc.get(String.valueOf(ar.get('Accountid'))));
    }
    if(!accountsToUpdate.isEmpty())    
{
     update accountsToUpdate;    
}
    }
}

 
Hi friends, I need hlep on this trigger to bulkify, this trigger is rollupsummary fields to update in account, can you guys please suggest to change the trigger in best way, actually trigger is working fiine in sandbox, but in production some times cutomer getting error like this -- CountCheckbox : CountCheckbox: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object ().

 
Trigger CountCheckbox on Contact (after delete, after insert, after undelete,
after update) {

    Contact[] cons;
    if (Trigger.isDelete)
        cons = Trigger.old;
    else
        cons = Trigger.new;

    // get list of accounts
    Set<ID> acctIds = new Set<ID>();
    for (Contact con : cons) {
            acctIds.add(con.AccountId);
    }
    
    List<account> accountsToUpdate=new list<Account>();
   
   
    Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([select Id
                                                            ,AccountId,Is_Promoter__c,Is_Detractor__c,Is_Passive__c,Is_Promoter_ETS__c,Is_Detractor_ETS__c,Is_Passive_ETS__c,CES_Value__c,CES_Count__c
                                                            from Contact
                                                            where AccountId in :acctIds]);

    Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
                                                                 ,RMT_Promoters_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);
    Map<ID, Account> acctsToUpdate2 = new Map<ID, Account>([select Id
                                                                 ,RMT_Detractors_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);    
    Map<ID, Account> acctsToUpdate3 = new Map<ID, Account>([select Id
                                                                 ,RMT_Passive_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);   
    Map<ID, Account> acctsToUpdate4 = new Map<ID, Account>([select Id
                                                                 ,ETS_Promoters_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);
    Map<ID, Account> acctsToUpdate5 = new Map<ID, Account>([select Id
                                                                 ,ETS_Detractors_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);    
    Map<ID, Account> acctsToUpdate6 = new Map<ID, Account>([select Id
                                                                 ,ETS_Passive_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]); 
    Map<ID, Account> acctsToUpdate7 = new Map<ID, Account>([select Id
                                                                 ,No_of_CES_response__c
                                                                  from Account
                                                                  where Id in :acctIds]);     
    Map<ID, Account> acctsToUpdate8 = new Map<ID, Account>([select Id
                                                                 ,Total_sum_of_CES_response__c
                                                                  from Account
                                                                  where Id in :acctIds]); 

    for (Account acct : acctsToUpdate.values()) {
        Set<ID> conIds = new Set<ID>();
        for (Contact con : contactsForAccounts.values()) {
            if (con.AccountId == acct.Id && con.Is_Promoter__c == TRUE)
                conIds.add(con.Id);
        }
        if (acct.RMT_Promoters_Count__c != conIds.size())
            acct.RMT_Promoters_Count__c = conIds.size();
    }

    update acctsToUpdate.values();
    
    for (Account acct2 : acctsToUpdate2.values()) {
        Set<ID> conIds2 = new Set<ID>();
        for (Contact con2 : contactsForAccounts.values()) {
            if (con2.AccountId == acct2.Id && con2.Is_Detractor__c == TRUE)
                conIds2.add(con2.Id);
        }
        if (acct2.RMT_Detractors_Count__c != conIds2.size())
            acct2.RMT_Detractors_Count__c = conIds2.size();
    }

    update acctsToUpdate2.values();
    
    for (Account acct3 : acctsToUpdate3.values()) {
        Set<ID> conIds3 = new Set<ID>();
        for (Contact con3 : contactsForAccounts.values()) {
            if (con3.AccountId == acct3.Id && con3.Is_Passive__c == TRUE)
                conIds3.add(con3.Id);
        }
        if (acct3.RMT_Passive_Count__c != conIds3.size())
            acct3.RMT_Passive_Count__c = conIds3.size();
    }

    update acctsToUpdate3.values();
    

    
    for (Account acct4 : acctsToUpdate4.values()) {
        Set<ID> conIds4 = new Set<ID>();
        for (Contact con4 : contactsForAccounts.values()) {
            if (con4.AccountId == acct4.Id && con4.Is_Promoter_ETS__c == TRUE)
                conIds4.add(con4.Id);
        }
        if (acct4.ETS_Promoters_Count__c != conIds4.size())
            acct4.ETS_Promoters_Count__c = conIds4.size();
    }

    update acctsToUpdate4.values();
    
    for (Account acct5 : acctsToUpdate5.values()) {
        Set<ID> conIds5 = new Set<ID>();
        for (Contact con5 : contactsForAccounts.values()) {
            if (con5.AccountId == acct5.Id && con5.Is_Detractor_ETS__c == TRUE)
                conIds5.add(con5.Id);
        }
        if (acct5.ETS_Detractors_Count__c != conIds5.size())
            acct5.ETS_Detractors_Count__c = conIds5.size();
    }

    update acctsToUpdate5.values();
    
    for (Account acct6 : acctsToUpdate6.values()) {
        Set<ID> conIds6 = new Set<ID>();
        for (Contact con6 : contactsForAccounts.values()) {
            if (con6.AccountId == acct6.Id && con6.Is_Passive_ETS__c == TRUE)
                conIds6.add(con6.Id);
        }
        if (acct6.ETS_Passive_Count__c != conIds6.size())
            acct6.ETS_Passive_Count__c = conIds6.size();
    }

    update acctsToUpdate6.values();
    
    for (Account acct7 : acctsToUpdate7.values()) {
        Set<ID> conIds7 = new Set<ID>();
        for (Contact con7 : contactsForAccounts.values()) {
            if (con7.AccountId == acct7.Id && con7.CES_Count__c != 0 )
                conIds7.add(con7.Id);
        }
        if (acct7.No_of_CES_response__c != conIds7.size())
            acct7.No_of_CES_response__c = conIds7.size();
    }
    
    update acctsToUpdate7.values();
    
    
     Map<Id, Account> acc= new Map<Id, Account>([Select Id, Total_sum_of_CES_response__c From Account Where Id In :acctIds]);
    AggregateResult[] groupedResults = [SELECT AccountId,SUM(CES_Value__c)amt FROM contact where AccountId in:acctIds group by AccountId];

      for (AggregateResult ar : groupedResults ) {
        acc.get(String.valueOf(ar.get('Accountid'))).Total_sum_of_CES_response__c = Integer.valueOf(ar.get('amt'));
        accountsToUpdate.add(acc.get(String.valueOf(ar.get('Accountid'))));
    }
    update accountsToUpdate;    
    
}

 
Hi, I need to update the trigger for mass update when opportunity created new record there are some lookup fileds (opp.Client__c = p.Client__c) are mapped. I am using data loader to update opportunity records, but lookup's fields not updating.Please check the below code.Thanks Advanced.

 
Trigger UpdateAccLookups on Opportunity (before insert, before update) 
{ 

    Set<Id> ProjectIds = new Set<Id>();
        for (Opportunity  o : trigger.new) 
            {
                ProjectIds.add(o.Project__c);
            }


Map<Id, Project__c> ProjectMap = new Map<Id, Project__c>();

    list<Project__c> Projects = new list<Project__c>();
    Projects = [Select Id, Name,Remarks__c,Main_Contractor__c,Client__c,Architect_Consultant__c,Facade_Consultant__c,Country__c,City__c,Other_City__c from Project__c where Id IN : ProjectIds];

    for (Opportunity  opp : trigger.new) 
    {
       for(project__C p : Projects){        
            opp.Main_Contractor__c = p.Main_Contractor__c;
            opp.Client__c = p.Client__c;
            opp.AccountID = p.Client__c;
            opp.Architect_Consultant__c = p.Architect_Consultant__c;
            opp.Facade_Consultant__c = p.Facade_Consultant__c;
            opp.Country__c = p.Country__c;
            opp.City__c= p.City__c;
            opp.Other_City__c = p.Other_City__c; 
 
            
      }  
    }
    
}
Hi Team,

My client using data import wizard to insert the records Max 1000 records, after inserting records backend trigger is executed only 200 records remaining records not updating showing EHR_TS__c Null values, But when I use data loader tool trigger is working fine & updating all the records same CSV file I am using.

It's very urgent for me, if anybody can please help me on this highly appreciative.

Below is the code i am using.

***************************** TRIGGER **************************************************
Trigger UpdateEHRate on Time_Sheet__c (before insert,before update,after update, after insert)
{        

try {
         
    if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isUpdate && Trigger.isAfter)){   
        if(checkRecursive.isFirstRun()){

            List<Time_Sheet__c> timeList = EHRTriggerHandler.UpdateEHRate(trigger.New);
            if(timeList.size() > 0){
                //update timeList;
                Database.update(timeList, false);
            }
        } 
    }
}
catch(DmlException de) {
System.debug('--->The following DMLexception has occurred: ' + de.getMessage());
Integer numErrors = de.getNumDml();
    System.debug('---->getNumDml=' + numErrors);
    for(Integer i=0;i<numErrors;i++) 
    {
        System.debug('--->getDmlFieldNames=' + de.getDmlFieldNames(i));
        System.debug('--->getDmlMessage=' + de.getDmlMessage(i));  
    }
}
catch(Exception e) {
System.debug('--->The following exception has occurred: ' + e.getMessage());
}
}

**************************** APEX CLASS  **********************************************

public class EHRTriggerHandler{
    
    public static List<Time_Sheet__c> UpdateEHRate(List<Time_Sheet__c> lstTS){ 
       List<Time_Sheet__c> timeList = new List<Time_Sheet__c>();
        System.debug('@@@@@@@1'+timeList);
       set<Id> TSIds = new set<Id>();
       Map<Id ,boolean> mapTimeSheet = new Map<Id,boolean>();
        for(Time_Sheet__c EHR : lstTS) {    
            TSIds.add(EHR.Employee__c);
        }                       
        
        List<Estimated_Hourly_Rate__c> EHRlist = [SELECT Id, Name,Employee__c,Start_Date__c,End_Date__c,Estimated_Hourly_Rate_Variable__c 
                                              FROM Estimated_Hourly_Rate__c 
                                              WHERE Employee__c =:TSIds];  
        
        Map<id,List<Estimated_Hourly_Rate__c>> mapEs = new Map<id,List<Estimated_Hourly_Rate__c>>();
        
        for (Estimated_Hourly_Rate__c c : EHRlist) {
                List<Estimated_Hourly_Rate__c> l = mapEs.get(c.Employee__c);
                if (l == null) {
                    l = new List<Estimated_Hourly_Rate__c>();
                    mapEs.put(c.Employee__c, l);
                }
            l.add(c);
        }
        
        boolean isMatchFound = false;        
        //if(EHRlist!=null && !EHRlist.isEmpty()) {
         for(Time_Sheet__c timeSheetRec :lstTS){
             Time_Sheet__c timee = new Time_Sheet__c();  
             
             List<Estimated_Hourly_Rate__c> listes = mapEs.get(timeSheetRec.Employee__c);
            for(Estimated_Hourly_Rate__c EHR : listes) {   
                     if(timeSheetRec.Record_Date__c >= EHR.Start_Date__c && timeSheetRec.Record_Date__c <= EHR.End_Date__c ){                    
                        timee.id = timeSheetRec.id;
                        timee.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c; 
                        //timeSheetRec.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c;  
                        isMatchFound = true;
                        
                    } 
                }
                
                 timeList.add(timee);              
            }  
          //}             
           
        if(!isMatchFound){
            lstTS[0].addError('The given Record date does not fall under any of the Estimated Hourly Rates record(s)');
        }
        
        return timeList;
  }  
}
Hi,

My client using data import wizard to insert the records Max 1000 records, after inserting records backend trigger is executed only 200 records remaining records not upating showing EHR_TS__c Null values, But when i use data loader tool trigger is working fine & updating all the records same csv file i am using.

Its very urget for me, if anybody can please help me on this highly appreciative.

Below is the code i am using.

***************************** TRIGGER **************************************************
Trigger UpdateEHRate on Time_Sheet__c (before insert,before update,after update, after insert)
{        

try {
         
    if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isUpdate && Trigger.isAfter)){   
        if(checkRecursive.isFirstRun()){

            List<Time_Sheet__c> timeList = EHRTriggerHandler.UpdateEHRate(trigger.New);
            if(timeList.size() > 0){
                //update timeList;
                Database.update(timeList, false);
            }
        } 
    }
}
catch(DmlException de) {
System.debug('--->The following DMLexception has occurred: ' + de.getMessage());
Integer numErrors = de.getNumDml();
    System.debug('---->getNumDml=' + numErrors);
    for(Integer i=0;i<numErrors;i++) 
    {
        System.debug('--->getDmlFieldNames=' + de.getDmlFieldNames(i));
        System.debug('--->getDmlMessage=' + de.getDmlMessage(i));  
    }
}
catch(Exception e) {
System.debug('--->The following exception has occurred: ' + e.getMessage());
}
}

**************************** APEX CLASS  **********************************************

public class EHRTriggerHandler{
    
    public static List<Time_Sheet__c> UpdateEHRate(List<Time_Sheet__c> lstTS){ 
       List<Time_Sheet__c> timeList = new List<Time_Sheet__c>();
        System.debug('@@@@@@@1'+timeList);
       set<Id> TSIds = new set<Id>();
       Map<Id ,boolean> mapTimeSheet = new Map<Id,boolean>();
        for(Time_Sheet__c EHR : lstTS) {    
            TSIds.add(EHR.Employee__c);
        }                       
        
        List<Estimated_Hourly_Rate__c> EHRlist = [SELECT Id, Name,Employee__c,Start_Date__c,End_Date__c,Estimated_Hourly_Rate_Variable__c 
                                              FROM Estimated_Hourly_Rate__c 
                                              WHERE Employee__c =:TSIds];  
        
        Map<id,List<Estimated_Hourly_Rate__c>> mapEs = new Map<id,List<Estimated_Hourly_Rate__c>>();
        
        for (Estimated_Hourly_Rate__c c : EHRlist) {
                List<Estimated_Hourly_Rate__c> l = mapEs.get(c.Employee__c);
                if (l == null) {
                    l = new List<Estimated_Hourly_Rate__c>();
                    mapEs.put(c.Employee__c, l);
                }
            l.add(c);
        }
        
        boolean isMatchFound = false;        
        //if(EHRlist!=null && !EHRlist.isEmpty()) {
         for(Time_Sheet__c timeSheetRec :lstTS){
             Time_Sheet__c timee = new Time_Sheet__c();  
             
             List<Estimated_Hourly_Rate__c> listes = mapEs.get(timeSheetRec.Employee__c);
            for(Estimated_Hourly_Rate__c EHR : listes) {   
                     if(timeSheetRec.Record_Date__c >= EHR.Start_Date__c && timeSheetRec.Record_Date__c <= EHR.End_Date__c ){                    
                        timee.id = timeSheetRec.id;
                        timee.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c; 
                        //timeSheetRec.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c;  
                        isMatchFound = true;
                        
                    } 
                }
                
                 timeList.add(timee);              
            }  
          //}             
           
        if(!isMatchFound){
            lstTS[0].addError('The given Record date does not fall under any of the Estimated Hourly Rates record(s)');
        }
        
        return timeList;
  }  
}
Hi Team,

Trigger not fetching the values all, i am inserting new records through data import wizard, i am not getting any error but after insert some records are updating and some records are not update, Example today inserted 500 records though data import wizard now its inserting 500 records but out of 500, 200 records its updating the EHR_TS__c value and remaining 300 not updating, and after i exported 300 records and update only ID, at that time 300 records its updating.

Please Help me where i am mistake in code its very urgent, below is my code Trigger & Class ,Thanks Advanced.

************************************ TRIGGER  ***********************************************************

Trigger UpdateEHRate on Time_Sheet__c (before insert,before update,after update, after insert)
{        
    if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isUpdate && Trigger.isAfter)){   
        if(checkRecursive.isFirstRun()){

            List<Time_Sheet__c> timeList = EHRTriggerHandler.UpdateEHRate(trigger.New);
            if(timeList.size() > 0){
                update timeList;
            }
        }
    }
}

**************************************** APEX CLASS ****************************************************

public class EHRTriggerHandler{
    
    public static List<Time_Sheet__c> UpdateEHRate(List<Time_Sheet__c> lstTS){ 
       List<Time_Sheet__c> timeList = new List<Time_Sheet__c>();
        System.debug('@@@@@@@1'+timeList);
       set<Id> TSIds = new set<Id>();
       Map<Id ,boolean> mapTimeSheet = new Map<Id,boolean>();
        for(Time_Sheet__c EHR : lstTS) {    
            TSIds.add(EHR.Employee__c);
        }                       
        
        List<Estimated_Hourly_Rate__c> EHRlist = [SELECT Id, Name,Employee__c,Start_Date__c,End_Date__c,Estimated_Hourly_Rate_Variable__c 
                                              FROM Estimated_Hourly_Rate__c 
                                              WHERE Employee__c =:TSIds];  
        
        Map<id,List<Estimated_Hourly_Rate__c>> mapEs = new Map<id,List<Estimated_Hourly_Rate__c>>();
        
        for (Estimated_Hourly_Rate__c c : EHRlist) {
                List<Estimated_Hourly_Rate__c> l = mapEs.get(c.Employee__c);
                if (l == null) {
                    l = new List<Estimated_Hourly_Rate__c>();
                    mapEs.put(c.Employee__c, l);
                }
            l.add(c);
        }
        
        boolean isMatchFound = false;        
        //if(EHRlist!=null && !EHRlist.isEmpty()) {
         for(Time_Sheet__c timeSheetRec :lstTS){
             Time_Sheet__c timee = new Time_Sheet__c();  
             
             List<Estimated_Hourly_Rate__c> listes = mapEs.get(timeSheetRec.Employee__c);
            for(Estimated_Hourly_Rate__c EHR : listes) {   
                     if(timeSheetRec.Record_Date__c >= EHR.Start_Date__c && timeSheetRec.Record_Date__c <= EHR.End_Date__c ){                    
                        timee.id = timeSheetRec.id;
                        timee.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c; 
                        //timeSheetRec.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c;  
                        isMatchFound = true;
                        
                    } 
                }
                
                 timeList.add(timee);              
            }  
          //}             
           
        if(!isMatchFound){
            lstTS[0].addError('The given Record date does not fall under any of the Estimated Hourly Rates record(s)');
        }
        
        return timeList;
  }  
}
Hi Guys, Is it possible to embed iframes in lightning component.please let me know any blogs with sample code.
Hi friends, I need hlep on this trigger to bulkify, this trigger is rollupsummary fields to update in account, can you guys please suggest to change the trigger in best way, actually trigger is working fiine in sandbox, but in production some times cutomer getting error like this -- CountCheckbox : CountCheckbox: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object ().

 
Trigger CountCheckbox on Contact (after delete, after insert, after undelete,
after update) {

    Contact[] cons;
    if (Trigger.isDelete)
        cons = Trigger.old;
    else
        cons = Trigger.new;

    // get list of accounts
    Set<ID> acctIds = new Set<ID>();
    for (Contact con : cons) {
            acctIds.add(con.AccountId);
    }
    
    List<account> accountsToUpdate=new list<Account>();
   
   
    Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([select Id
                                                            ,AccountId,Is_Promoter__c,Is_Detractor__c,Is_Passive__c,Is_Promoter_ETS__c,Is_Detractor_ETS__c,Is_Passive_ETS__c,CES_Value__c,CES_Count__c
                                                            from Contact
                                                            where AccountId in :acctIds]);

    Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
                                                                 ,RMT_Promoters_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);
    Map<ID, Account> acctsToUpdate2 = new Map<ID, Account>([select Id
                                                                 ,RMT_Detractors_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);    
    Map<ID, Account> acctsToUpdate3 = new Map<ID, Account>([select Id
                                                                 ,RMT_Passive_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);   
    Map<ID, Account> acctsToUpdate4 = new Map<ID, Account>([select Id
                                                                 ,ETS_Promoters_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);
    Map<ID, Account> acctsToUpdate5 = new Map<ID, Account>([select Id
                                                                 ,ETS_Detractors_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]);    
    Map<ID, Account> acctsToUpdate6 = new Map<ID, Account>([select Id
                                                                 ,ETS_Passive_Count__c
                                                                  from Account
                                                                  where Id in :acctIds]); 
    Map<ID, Account> acctsToUpdate7 = new Map<ID, Account>([select Id
                                                                 ,No_of_CES_response__c
                                                                  from Account
                                                                  where Id in :acctIds]);     
    Map<ID, Account> acctsToUpdate8 = new Map<ID, Account>([select Id
                                                                 ,Total_sum_of_CES_response__c
                                                                  from Account
                                                                  where Id in :acctIds]); 

    for (Account acct : acctsToUpdate.values()) {
        Set<ID> conIds = new Set<ID>();
        for (Contact con : contactsForAccounts.values()) {
            if (con.AccountId == acct.Id && con.Is_Promoter__c == TRUE)
                conIds.add(con.Id);
        }
        if (acct.RMT_Promoters_Count__c != conIds.size())
            acct.RMT_Promoters_Count__c = conIds.size();
    }

    update acctsToUpdate.values();
    
    for (Account acct2 : acctsToUpdate2.values()) {
        Set<ID> conIds2 = new Set<ID>();
        for (Contact con2 : contactsForAccounts.values()) {
            if (con2.AccountId == acct2.Id && con2.Is_Detractor__c == TRUE)
                conIds2.add(con2.Id);
        }
        if (acct2.RMT_Detractors_Count__c != conIds2.size())
            acct2.RMT_Detractors_Count__c = conIds2.size();
    }

    update acctsToUpdate2.values();
    
    for (Account acct3 : acctsToUpdate3.values()) {
        Set<ID> conIds3 = new Set<ID>();
        for (Contact con3 : contactsForAccounts.values()) {
            if (con3.AccountId == acct3.Id && con3.Is_Passive__c == TRUE)
                conIds3.add(con3.Id);
        }
        if (acct3.RMT_Passive_Count__c != conIds3.size())
            acct3.RMT_Passive_Count__c = conIds3.size();
    }

    update acctsToUpdate3.values();
    

    
    for (Account acct4 : acctsToUpdate4.values()) {
        Set<ID> conIds4 = new Set<ID>();
        for (Contact con4 : contactsForAccounts.values()) {
            if (con4.AccountId == acct4.Id && con4.Is_Promoter_ETS__c == TRUE)
                conIds4.add(con4.Id);
        }
        if (acct4.ETS_Promoters_Count__c != conIds4.size())
            acct4.ETS_Promoters_Count__c = conIds4.size();
    }

    update acctsToUpdate4.values();
    
    for (Account acct5 : acctsToUpdate5.values()) {
        Set<ID> conIds5 = new Set<ID>();
        for (Contact con5 : contactsForAccounts.values()) {
            if (con5.AccountId == acct5.Id && con5.Is_Detractor_ETS__c == TRUE)
                conIds5.add(con5.Id);
        }
        if (acct5.ETS_Detractors_Count__c != conIds5.size())
            acct5.ETS_Detractors_Count__c = conIds5.size();
    }

    update acctsToUpdate5.values();
    
    for (Account acct6 : acctsToUpdate6.values()) {
        Set<ID> conIds6 = new Set<ID>();
        for (Contact con6 : contactsForAccounts.values()) {
            if (con6.AccountId == acct6.Id && con6.Is_Passive_ETS__c == TRUE)
                conIds6.add(con6.Id);
        }
        if (acct6.ETS_Passive_Count__c != conIds6.size())
            acct6.ETS_Passive_Count__c = conIds6.size();
    }

    update acctsToUpdate6.values();
    
    for (Account acct7 : acctsToUpdate7.values()) {
        Set<ID> conIds7 = new Set<ID>();
        for (Contact con7 : contactsForAccounts.values()) {
            if (con7.AccountId == acct7.Id && con7.CES_Count__c != 0 )
                conIds7.add(con7.Id);
        }
        if (acct7.No_of_CES_response__c != conIds7.size())
            acct7.No_of_CES_response__c = conIds7.size();
    }
    
    update acctsToUpdate7.values();
    
    
     Map<Id, Account> acc= new Map<Id, Account>([Select Id, Total_sum_of_CES_response__c From Account Where Id In :acctIds]);
    AggregateResult[] groupedResults = [SELECT AccountId,SUM(CES_Value__c)amt FROM contact where AccountId in:acctIds group by AccountId];

      for (AggregateResult ar : groupedResults ) {
        acc.get(String.valueOf(ar.get('Accountid'))).Total_sum_of_CES_response__c = Integer.valueOf(ar.get('amt'));
        accountsToUpdate.add(acc.get(String.valueOf(ar.get('Accountid'))));
    }
    update accountsToUpdate;    
    
}

 
Hi, I need to update the trigger for mass update when opportunity created new record there are some lookup fileds (opp.Client__c = p.Client__c) are mapped. I am using data loader to update opportunity records, but lookup's fields not updating.Please check the below code.Thanks Advanced.

 
Trigger UpdateAccLookups on Opportunity (before insert, before update) 
{ 

    Set<Id> ProjectIds = new Set<Id>();
        for (Opportunity  o : trigger.new) 
            {
                ProjectIds.add(o.Project__c);
            }


Map<Id, Project__c> ProjectMap = new Map<Id, Project__c>();

    list<Project__c> Projects = new list<Project__c>();
    Projects = [Select Id, Name,Remarks__c,Main_Contractor__c,Client__c,Architect_Consultant__c,Facade_Consultant__c,Country__c,City__c,Other_City__c from Project__c where Id IN : ProjectIds];

    for (Opportunity  opp : trigger.new) 
    {
       for(project__C p : Projects){        
            opp.Main_Contractor__c = p.Main_Contractor__c;
            opp.Client__c = p.Client__c;
            opp.AccountID = p.Client__c;
            opp.Architect_Consultant__c = p.Architect_Consultant__c;
            opp.Facade_Consultant__c = p.Facade_Consultant__c;
            opp.Country__c = p.Country__c;
            opp.City__c= p.City__c;
            opp.Other_City__c = p.Other_City__c; 
 
            
      }  
    }
    
}
Hi Team,

My client using data import wizard to insert the records Max 1000 records, after inserting records backend trigger is executed only 200 records remaining records not updating showing EHR_TS__c Null values, But when I use data loader tool trigger is working fine & updating all the records same CSV file I am using.

It's very urgent for me, if anybody can please help me on this highly appreciative.

Below is the code i am using.

***************************** TRIGGER **************************************************
Trigger UpdateEHRate on Time_Sheet__c (before insert,before update,after update, after insert)
{        

try {
         
    if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isUpdate && Trigger.isAfter)){   
        if(checkRecursive.isFirstRun()){

            List<Time_Sheet__c> timeList = EHRTriggerHandler.UpdateEHRate(trigger.New);
            if(timeList.size() > 0){
                //update timeList;
                Database.update(timeList, false);
            }
        } 
    }
}
catch(DmlException de) {
System.debug('--->The following DMLexception has occurred: ' + de.getMessage());
Integer numErrors = de.getNumDml();
    System.debug('---->getNumDml=' + numErrors);
    for(Integer i=0;i<numErrors;i++) 
    {
        System.debug('--->getDmlFieldNames=' + de.getDmlFieldNames(i));
        System.debug('--->getDmlMessage=' + de.getDmlMessage(i));  
    }
}
catch(Exception e) {
System.debug('--->The following exception has occurred: ' + e.getMessage());
}
}

**************************** APEX CLASS  **********************************************

public class EHRTriggerHandler{
    
    public static List<Time_Sheet__c> UpdateEHRate(List<Time_Sheet__c> lstTS){ 
       List<Time_Sheet__c> timeList = new List<Time_Sheet__c>();
        System.debug('@@@@@@@1'+timeList);
       set<Id> TSIds = new set<Id>();
       Map<Id ,boolean> mapTimeSheet = new Map<Id,boolean>();
        for(Time_Sheet__c EHR : lstTS) {    
            TSIds.add(EHR.Employee__c);
        }                       
        
        List<Estimated_Hourly_Rate__c> EHRlist = [SELECT Id, Name,Employee__c,Start_Date__c,End_Date__c,Estimated_Hourly_Rate_Variable__c 
                                              FROM Estimated_Hourly_Rate__c 
                                              WHERE Employee__c =:TSIds];  
        
        Map<id,List<Estimated_Hourly_Rate__c>> mapEs = new Map<id,List<Estimated_Hourly_Rate__c>>();
        
        for (Estimated_Hourly_Rate__c c : EHRlist) {
                List<Estimated_Hourly_Rate__c> l = mapEs.get(c.Employee__c);
                if (l == null) {
                    l = new List<Estimated_Hourly_Rate__c>();
                    mapEs.put(c.Employee__c, l);
                }
            l.add(c);
        }
        
        boolean isMatchFound = false;        
        //if(EHRlist!=null && !EHRlist.isEmpty()) {
         for(Time_Sheet__c timeSheetRec :lstTS){
             Time_Sheet__c timee = new Time_Sheet__c();  
             
             List<Estimated_Hourly_Rate__c> listes = mapEs.get(timeSheetRec.Employee__c);
            for(Estimated_Hourly_Rate__c EHR : listes) {   
                     if(timeSheetRec.Record_Date__c >= EHR.Start_Date__c && timeSheetRec.Record_Date__c <= EHR.End_Date__c ){                    
                        timee.id = timeSheetRec.id;
                        timee.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c; 
                        //timeSheetRec.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c;  
                        isMatchFound = true;
                        
                    } 
                }
                
                 timeList.add(timee);              
            }  
          //}             
           
        if(!isMatchFound){
            lstTS[0].addError('The given Record date does not fall under any of the Estimated Hourly Rates record(s)');
        }
        
        return timeList;
  }  
}
Hi Team,

Trigger not fetching the values all, i am inserting new records through data import wizard, i am not getting any error but after insert some records are updating and some records are not update, Example today inserted 500 records though data import wizard now its inserting 500 records but out of 500, 200 records its updating the EHR_TS__c value and remaining 300 not updating, and after i exported 300 records and update only ID, at that time 300 records its updating.

Please Help me where i am mistake in code its very urgent, below is my code Trigger & Class ,Thanks Advanced.

************************************ TRIGGER  ***********************************************************

Trigger UpdateEHRate on Time_Sheet__c (before insert,before update,after update, after insert)
{        
    if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isUpdate && Trigger.isAfter)){   
        if(checkRecursive.isFirstRun()){

            List<Time_Sheet__c> timeList = EHRTriggerHandler.UpdateEHRate(trigger.New);
            if(timeList.size() > 0){
                update timeList;
            }
        }
    }
}

**************************************** APEX CLASS ****************************************************

public class EHRTriggerHandler{
    
    public static List<Time_Sheet__c> UpdateEHRate(List<Time_Sheet__c> lstTS){ 
       List<Time_Sheet__c> timeList = new List<Time_Sheet__c>();
        System.debug('@@@@@@@1'+timeList);
       set<Id> TSIds = new set<Id>();
       Map<Id ,boolean> mapTimeSheet = new Map<Id,boolean>();
        for(Time_Sheet__c EHR : lstTS) {    
            TSIds.add(EHR.Employee__c);
        }                       
        
        List<Estimated_Hourly_Rate__c> EHRlist = [SELECT Id, Name,Employee__c,Start_Date__c,End_Date__c,Estimated_Hourly_Rate_Variable__c 
                                              FROM Estimated_Hourly_Rate__c 
                                              WHERE Employee__c =:TSIds];  
        
        Map<id,List<Estimated_Hourly_Rate__c>> mapEs = new Map<id,List<Estimated_Hourly_Rate__c>>();
        
        for (Estimated_Hourly_Rate__c c : EHRlist) {
                List<Estimated_Hourly_Rate__c> l = mapEs.get(c.Employee__c);
                if (l == null) {
                    l = new List<Estimated_Hourly_Rate__c>();
                    mapEs.put(c.Employee__c, l);
                }
            l.add(c);
        }
        
        boolean isMatchFound = false;        
        //if(EHRlist!=null && !EHRlist.isEmpty()) {
         for(Time_Sheet__c timeSheetRec :lstTS){
             Time_Sheet__c timee = new Time_Sheet__c();  
             
             List<Estimated_Hourly_Rate__c> listes = mapEs.get(timeSheetRec.Employee__c);
            for(Estimated_Hourly_Rate__c EHR : listes) {   
                     if(timeSheetRec.Record_Date__c >= EHR.Start_Date__c && timeSheetRec.Record_Date__c <= EHR.End_Date__c ){                    
                        timee.id = timeSheetRec.id;
                        timee.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c; 
                        //timeSheetRec.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c;  
                        isMatchFound = true;
                        
                    } 
                }
                
                 timeList.add(timee);              
            }  
          //}             
           
        if(!isMatchFound){
            lstTS[0].addError('The given Record date does not fall under any of the Estimated Hourly Rates record(s)');
        }
        
        return timeList;
  }  
}