my Test_Unit class passes @ 65% only, I'm not sure why is that?

Error message is:

BranchController_Test testBranchMethods System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.TestData.CreateLead: line 122, column 1 Class.BranchController_Test.testBranchMethods: line 30, column 1

private class BranchController_Test {

    static testMethod void testBranchMethods() {

        set<string> sZips = new set<string>();
        set<id> sBranch = new set<id>();

        //bBEGIN: S-444338 When wee run this test class we are getting Mixed DML Operations error, to avoid this we need modify this TEST Apex class
        User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        //Branch__c b = TestData.CreateBranch(1, '99999');

        Branch__c b = new Branch__c(name = 'Neil Test Branch');
        insert b;

        ZipCode__c z = TestData.CreateZips('10001', b.Id);
        insert z;

        User u = TestData.CreateUser(1);
        insert u;

        IAASettings__c iaa = TestData.CreateSetting('DefaultOwnerId', u.Id);
        insert iaa;

        Account acct = TestData.CreateAccount(1, '10001');
        insert acct;

        Lead ld = TestData.CreateLead(1, '10001');
        insert ld;

        list<ZipCode__c> zipcodes = BranchController.LookupBranchByZip(sZips);
        list<Branch__c> branches = BranchController.LookupOwnerByBranch(sBranch); 

        string branchAdd = BranchController.BranchAddress(b);
        string acctAdd = BranchController.AccountAddress(acct);
        string leadAdd = BranchController.LeadAddress(ld);

        string nullString1 = BranchController.CheckForNull(acctAdd);
        string nullStrin2 = BranchController.CheckForNull('null');

        //BranchController.CalculateAccountDistance(b.Id, acct.Id);

Also i'm trying to fix the error in the Apex class,this method is the main reason of the errors. any help would help. thanks. enter image description here

  • Maybe help us by providing the exact error message? Also your test class is not testing anything. It is just running code
    – Eric
    Mar 2, 2017 at 20:01

1 Answer 1


It seems that your Test_Unit Class never call your method CalculateDistance.

That can be for many reason, you can execute CalculateDistance in your test class, if it has sense.

Otherwise you can check if your data and actions in test class are able to trigger the execution of CalculateDistance.

I'd need more details for a comprehensive answer.

  • since the CalculateDistance is a @future method and i'm not calling it in the Unit_Test. if I use System.Start() and System.End() would fix it? f.y.i. never used start() and end() would you provide an example? thanks
    – Templar
    Mar 2, 2017 at 20:11
  • Yes, try add Test.startTest(); // code that trigger your method // Test.stopTest(); I didn't notice you don't do that
    – Viviana
    Mar 2, 2017 at 20:17
  • classes/BranchController_Test.cls: Variable does not exist: leadsFR (Line: 51, Column: 20)
    – Templar
    Mar 2, 2017 at 20:23
  • I can't find leadsFR in your code, but Line: 51 of your test class cause this error. I don't know which is line 51 because your code changed. sorry for not more detail
    – Viviana
    Mar 2, 2017 at 20:29
  • Method does not exist or incorrect signature: User.get(User) (Line: 51, Test.startTest(); System.runAs(User.get(u)) { insert ld; system.debug('testing' + ld); } Test.stopTest();
    – Templar
    Mar 2, 2017 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.