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
SK R.ax1448SK R.ax1448 

Urgent help : Test code coverage

Hi,

 

I'm unable to deploy my trigger, getting below errors as lack of test code coverage.

Failure Message: "line -1, column -1: Previous load of class failed: create_spr_controllertest", Failure Stack Trace: "null"

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

 

Below in red color is uncovered code. Its urgent , any help must be highly appreciated.

 

Here is the my code

 

Trigger:

 

trigger UpdateAccountID on Account(before update) {

Set<String> enteredValues = New Set<String>();
Set<String> accountids = New Set<String>();

    for(Account acc : trigger.new)
    {
         
       if(acc.AccountHold__c  != null && acc.AccountHold__c != acc.AccountID__c)
       {
          enteredValues.add(acc.AccountHold__c);
       }
    }

    if(!enteredValues.isEmpty())
    {
       UpdateAccountIDController uda = New UpdateAccountIDController();
       accountids = uda.checkUniqueness(enteredValues);
    }

    for(Account a : trigger.new)
    {
        if(!accountids.isEmpty())
        {
            if(!accountids.contains(a.AccountHold__c))
                a.AccountID__c = a.AccountHold__c;
        }
        else
        {
            if(a.AccountHold__c != null)
                a.AccountID__c = a.AccountHold__c;
        }
   
    }
}

 

Controller Class:

 


public class UpdateAccountIDController{

    public Set<String> checkUniqueness(Set<String> enteredValues)
    {
        List<Account> accountRecs = New List<Account>();
        Set<String> accountIds= New Set<String>();
        accountRecs = [SELECT
                        AccountID__c
                FROM
                        Account
                WHERE
                         AccountID__c in : enteredValues];

        for(Account a : accountRecs)
        {
            accountIds.add(a.AccountID__c);
        }
        return accountIds;   
    }
    
    
    static testMethod void testUpdateAccountIDController(){
    
        Set<String> AccIdHold = new Set <String>{'ACCID01','ACCID02', 'ACCID03', 'ACCID04'};
        Set<String> AccountIds = new Set <String>();
        Account acc = new Account(Name='Test Account',AccountID__c = 'DellACCID02');
        insert acc;
        List <Account> accList = [Select AccountID__c from Account where AccountID__c in : AccIdHold];
        for(Account a: accList){
            AccountIds.add(a.AccountID__c);
        }
        UpdateAccountIDController uda = new UpdateAccountIDController();
        uda.checkUniqueness(AccIdHold);
     }   
        
    
}

 

Test Class:

 


@ isTest
private class UpdateAccountIDTriggerTest{
    
  static testMethod void testUpdateAccountIDTrigger(){
 
     Set<String> changedIds = new Set<String>();
     Set<String> accountids = New Set<String>();
     
      Account acc = new Account(Name = 'Test Account',AccountHold__c = 'ACCID02',AccountID__c='ACCID01');
      insert acc;
      acc.AccountHold__c = 'ACCID03';
      update acc;
      changedIds.add(acc.AccountHold__c);
      UpdateAccountIDController uda = New UpdateAccountIDController();
      accountids = uda.checkUniqueness(changedIds);
    }
}

 

Thanks a lot in advance !

 

Regards,

SK

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Class "create_spr_controllertest" failed to load, probably because a function or class it depends on was changed or deleted. Try editing the class and fixing any errors there.

All Answers

sfdcfoxsfdcfox

Class "create_spr_controllertest" failed to load, probably because a function or class it depends on was changed or deleted. Try editing the class and fixing any errors there.

This was selected as the best answer
SK R.ax1448SK R.ax1448

It worked. Thanks a lot.

 

Regards,

SK