function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
OivlaSforceOivlaSforce 

Trigger deploy

Hi,

 

I have a simple update trigger that modify the references of object thread when a Case is updated. The test is successful in sandbox environment but I have a problem on the assertion when I try to deploy It on the server and the deploy fails. . 

Someone can help me?

 

Thanks

 

Following the code:

 

trigger AccountUpdate on Case (before update) {
     
    for (Case c: Trigger.new){
        Case oldCase = Trigger.oldMap.get(c.ID);
        
        if (c.AccountId != oldCase.AccountId || c.ContactId != oldCase.ContactId) {
            List<Thread__c> threadList = [SELECT Account__c FROM Thread__c WHERE Case__c= :c.id];
            
            if(!threadList.isEmpty()){
                for(Thread__c t: threadList){
                    System.debug('#### Aggiorno i Thread...con '+c.AccountId);
                    t.Account__c = c.AccountId;
                    t.Contact__c = c.ContactId;
                }
                update threadList;
            }
        }
    }
    
    
}

 

@isTest
private class TriggerTests {
  
    
   static testMethod void AccountUpdateTriggerTest(){
       
        Account acct = new Account(name='test account');
        Contact ct = new Contact(AccountId=acct.Id,lastname='testing',firstname='E2C');
        insert acct;
        insert ct;
       
        Case c = new Case();
        c.AccountId = acct.id;
        c.ContactId = ct.id;
        insert c;
        
       List<Thread__c> threadList = new List<Thread__c>();
       for(Integer i=0; i<5; i++){
            Thread__c t = new Thread__c();
            t.Case__c = c.id;
            t.Account__c = c.AccountId;
            t.Contact__c = c.ContactId;
            threadList.add(t);
        }
        insert threadList;
       
        Account acct1 = new Account(name='test account nuovo');
        Contact ct1 = new Contact(AccountId=acct1.Id,lastname='testing_nuovo',firstname='E2C_nuovo');
        insert acct1;
        insert ct1;
        
        c.AccountId = acct1.id;
        c.ContactId = ct1.id;
        update c;
        
        threadList = [SELECT Account__c,Contact__c FROM Thread__c WHERE Case__c= :c.id];
        for(Thread__c th : threadList){
            System.assertEquals(c.AccountId,th.Account__c);
            System.assertEquals(c.ContactId,th.Contact__c);
        }
    } 

}
    

 

Best Answer chosen by Admin (Salesforce Developers) 
OivlaSforceOivlaSforce

I just resolved the problem. 

I had problems on test assertions.

However I resolved using the (SeeAllData=true) Annotation.

 

Thanks 

All Answers

priyanka.mv26priyanka.mv26

Are you getting the error "Too many SOQL rows"/"Too many DML statements" while deploying to production.? 

 

If yes, this is due to the select query and dml statement inside the for loop.. 

OivlaSforceOivlaSforce

I just resolved the problem. 

I had problems on test assertions.

However I resolved using the (SeeAllData=true) Annotation.

 

Thanks 

This was selected as the best answer
priyanka.mv26priyanka.mv26

Anyway I suggest you to remove the Select query and DML statement from the for loop for optimized coding.. 

OivlaSforceOivlaSforce

Thanks for your suggestion,

 

I'll remove it...