• Tanyril
  • NEWBIE
  • 100 Points
  • Member since 2012

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 15
    Replies

Here is the test class:

@isTest
public static void testBatch() {

Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 

User u2 = new User(Alias = 'standt', Email='standarduser@testorg.com', 
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
      LocaleSidKey='en_US', ProfileId = p.Id, 
      TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
    insert u2;

 
 Account a = new Account(Name = 'Test Account', ShippingPostalCode = '00000', BillingCountry = 'US', OwnerID= u2.Id, Inflows__c = 100, Outflows__c= 100, navmfv2__AUM_as_of__c = Date.today());
    insert a;

    Test.StartTest();
    FlowstoUser BatchClass = new FlowstoUser();
    Database.executeBatch(BatchClass, 1);
    Test.StopTest();
  }

 Here's the error from test execution logs:

 

13:43:38.595 (2595524000)|CODE_UNIT_STARTED|[EXTERNAL]|01pZ00000005mN5|FlowstoUser
13:43:38.604 (2604439000)|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|Select Id, Inflow_of_Owned_Accounts__c, Outflow_of_Owned_Accounts__c  from User
13:43:38.641 (2641706000)|SOQL_EXECUTE_END|[13]|Rows:18
13:43:38.643 (2643968000)|EXCEPTION_THROWN|[EXTERNAL]|System.UnexpectedException: No more than one executeBatch can be called from within a testmethod.  Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.

 

As you can see, it's returning all of the users in the system PLUS the test user instead of just the test user. Any help would be greatly appreciated.

Here's the trigger:

trigger HistoricalAUM on Account (after insert, before update) {

List<Historical_AUM__c> TransferAUM = new List <Historical_AUM__c> {};

 Account[] accts;
    if (Trigger.isDelete) 
        accts = Trigger.old;
    else
        accts = Trigger.new;

for (account a : accts) {

TransferAUM.add( new Historical_AUM__c(Year_Revenue__c = a.Revenue__c, Revenue__c = a.Month_Revenue__c));

}
try {
upsert TransferAUM UpsertID__c;
}
catch (Exception Ex)
{
system.debug(Ex);
}
}

 

Here's the problem, but ONLY in production:

06:59:09.181 (181633000)|EXCEPTION_THROWN|[17]|System.DmlException: Upsert failed. First exception on row 0; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001d000000CluwJ) is currently in trigger HistoricalAUM, therefore it cannot recursively update itself: []

Test data works as expected in the sandbox, and had worked up until sometime in the last few weeks in production.

I'm having some trouble with my code and I can't figure out what's wrong. I've used identical syntax in other classes but for some reason this one isn't working.

 

The objective of this class is to read the valuation date, determine if it's less than 30 days old, then act based on that result (changing the value of a field to 1 if it is < 30 days old or set to 0 if > 30)

 

global with sharing class CAB_ThisMonthBoolean implements Database.Batchable<sObject>{
   global final String Query;

   global CAB_ThisMonthBoolean() {
        this.Query = 'Select cab.navmfv2__Valuation_Date__c, cab.Id, cab.ThisMonthBoolean__c, cab.ThisMonth__C from navmfv2__Client_Account_Balance__c cab ';
   }
   
   global Database.QueryLocator start(Database.BatchableContext BC) {
      return Database.getQueryLocator(Query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope) {


    List<navmfv2__Client_Account_Balance__c> ClientAccountbalTrans = (List<navmfv2__Client_Account_Balance__c>) scope;
    List<navmfv2__Client_Account_Balance__c> updateClientAccountbal = new List<navmfv2__Client_Account_Balance__c>();
    
    for (navmfv2__Client_Account_Balance__c ClientAccountbalTran : ClientAccountbalTrans) {
        
        date currentDate = Date.today();
        date val = ClientAccountbalTran.navmfv2__Valuation_Date__c;
	    If(val.daysBetween(currentDate) < 30) {
			ClientAccountbalTran.ThisMonthBoolean__c = 1;
	    }
		else { ClientAccountbalTran.ThisMonthBoolean__c = 0; }
		updateClientAccountbal.add(ClientAccountbalTran);
        }
    update updateClientAccountbal;

    
}
    

   global void finish(Database.BatchableContext BC){

   }
   
 
public static testMethod void testBatch() {

 Account a = new Account(Name = 'Test Account', ShippingPostalCode = '00000', BillingCountry = 'US');
    insert a;

Contact con = new Contact(LastName = 'BatchTestContact');  
 insert con;

navmfv2__Fund__c Fund = new navmfv2__Fund__c(Name = 'Fake Fund', navmfv2__Fund_Short_Name__c = 'Fake Fund', navmfv2__CUSIP__c = '12345');
insert Fund;

navmfv2__Client_Account__c tstCA = new navmfv2__Client_Account__c (navmfv2__Client_Account_Number__c = '123TestCANum123', navmfv2__Sales_Rep_Name__c = con.id);
        insert tstCA;

Date thedate = Date.newInstance(2010,5,23);
navmfv2__Client_Account_Balance__c tstCAB = new navmfv2__Client_Account_Balance__c (navmfv2__Client_Account_Id__c = tstCA.Id, navmfv2__Valuation_Date__c = thedate, ThisMonthBoolean__c = 1);
        insert tstCAB;
       

    Test.StartTest();
    CAB_ThisMonthBoolean BatchClass = new CAB_ThisMonthBoolean();
    Database.executeBatch(BatchClass, 1);
    Test.StopTest();
  }
}

 

The code works in my sandbox (IE- It does what it's supposed to)- however I can't run it's test. 

I'm having some trouble with a class I'm creating. The purpose of this class is to essentially work around the Analytical Snapshot limit by batching the job- which is all fine but i'm getting the error in the title. Here's the code

 

global with sharing class AUMSnapshot implements Database.Batchable<sObject> {
   global final String Query;

   global AUMSnapshot() {
        this.Query = 'Select a.Id, a.navmfv2__Latest_AUM__c, a.navmfv2__AUM_as_of__c, a.Value__c, a.Research__c, a.Balanced__c, a.Government_MM__c, a.Hickory__c, a.NE_Tax_Free__c, a.Partners_Value__c, a.PIII__c, a.Short_Intermediate_Classes_combined__c  From Account a';
   }
   
   global AUMSnapshot(String query) {
        this.Query = query;
   }

   global Database.QueryLocator start(Database.BatchableContext BC) {
      return Database.getQueryLocator(Query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope) {
    
    List<Account> AccountAssets = (List<Account>) scope;
    
    List<Account> updateAccount = new List<Account>();
    
    for (Account AccountAsset : AccountAssets) {
	Historical_AUM__c haum = new Historical_AUM__c( Account__c = AccountAsset.Id, AUM__c = AccountAsset.navmfv2__Latest_AUM__c, Value__c = AccountAsset.Value__c, Research__c = AccountAsset.Research__c, Record_Date__c = AccountAsset.navmfv2__AUM_as_of__c, Balanced__c = AccountAsset.Balanced__c, Government_MM__c = ACcountAsset.Government_MM__c, NE_Tax_Free__c = AccountAsset.NE_Tax_Free__c, Hickory__c = AccountAsset.Hickory__c, Partners_Value__c = AccountAsset.Partners_Value__c, PIII__c = AccountAsset.PIII__c, Short_Intermediate__c = AccountAsset.Short_Intermediate_Classes_combined__c, UpsertID__c = AccountAssets.Id & AccountAsset.navmfv2__AUM_as_of__c);
	upsert haum UpsertID__c; 
	
    }
    
    update updateAccount;
    
   }

   global void finish(Database.BatchableContext BC){

   }
   
   public static testMethod void testBatch() {
    
    Account a = new Account(Name = 'Test Account', ShippingPostalCode = '00000', BillingCountry = 'US', navmfv2__AUM_as_of__c = Date.today());
    insert a;
    
	Historical_AUM__c b = new Historical_AUM__c( Account__c = a.Id, AUM__c = a.navmfv2__Latest_AUM__c, Value__c = a.Value__c, Research__c = a.Research__c, Record_Date__c = a.navmfv2__AUM_as_of__c, Balanced__c = a.Balanced__c, Government_MM__c = a.Government_MM__c, NE_Tax_Free__c = a.NE_Tax_Free__c, Hickory__c = a.Hickory__c, Partners_Value__c = a.Partners_Value__c, PIII__c = a.PIII__c, Short_Intermediate__c = a.Short_Intermediate_Classes_combined__c, UpsertID__c = a.Id & a.navmfv2__AUM_as_of__c);
	upsert b;

    Test.StartTest();
    AUMSnapshot BatchClass = new AUMSnapshot();
    Database.executeBatch(BatchClass, 1);
    //BatchClass.execute(null, new List<sObject>{zipper});
    Test.StopTest();
   }
}

 

 

 The part where I declare haum is the offending line of code. I would appreciate any help.

System.QueryException: List has no rows for assignment to SObjectClass.ClientTransBatch.testBatch: line 132, column 1

Presumeably the only part of this code that matters is the test class at the very bottom.

That's the error I'm getting from the test in this class:

 (Code removed)

 

I'm obviously doing something wrong with this test class but I can't figure out what. Can anyone help me?

I've put together a trigger to roll up some asset amounts from contacts to our accounts, however, I can't figure out for the life of me how I would write a test class in this situation, can anyone help me? I'm no apex pro.

 

Also- the fields being summed and sent to the account object are actually rollup fields from a child object of contact. When these fields are updated will they cause the trigger to fire? There's one of these triggers for each of our different asset amounts (8 in total).

 

Thanks for your help!

 

trigger SumBalanced on Contact (after insert,after update,after delete)
{
    Set<Id> accountIdset = new Set<Id>();
   
    for (Contact con:trigger.new)
    {
       accountIdset.add(con.AccountId);
    }
    Map<Id,Account> AccountMap = new Map<Id,Account>([Select Id,Balanced__c from Account where Id in :accountIdset]);
    for(AggregateResult res : [SELECT AccountId, SUM(Balanced__c) cnt FROM Contact where AccountId in : accountIdset GROUP BY ROLLUP(AccountId)]){
        if(res.get('AccountId') <> null){
            AccountMap.get((ID)res.get('AccountId')).Balanced__c = (Decimal)res.get('cnt');
        }
    }
    update AccountMap.values();
	}

 

Here is the test class:

@isTest
public static void testBatch() {

Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 

User u2 = new User(Alias = 'standt', Email='standarduser@testorg.com', 
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
      LocaleSidKey='en_US', ProfileId = p.Id, 
      TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
    insert u2;

 
 Account a = new Account(Name = 'Test Account', ShippingPostalCode = '00000', BillingCountry = 'US', OwnerID= u2.Id, Inflows__c = 100, Outflows__c= 100, navmfv2__AUM_as_of__c = Date.today());
    insert a;

    Test.StartTest();
    FlowstoUser BatchClass = new FlowstoUser();
    Database.executeBatch(BatchClass, 1);
    Test.StopTest();
  }

 Here's the error from test execution logs:

 

13:43:38.595 (2595524000)|CODE_UNIT_STARTED|[EXTERNAL]|01pZ00000005mN5|FlowstoUser
13:43:38.604 (2604439000)|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|Select Id, Inflow_of_Owned_Accounts__c, Outflow_of_Owned_Accounts__c  from User
13:43:38.641 (2641706000)|SOQL_EXECUTE_END|[13]|Rows:18
13:43:38.643 (2643968000)|EXCEPTION_THROWN|[EXTERNAL]|System.UnexpectedException: No more than one executeBatch can be called from within a testmethod.  Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.

 

As you can see, it's returning all of the users in the system PLUS the test user instead of just the test user. Any help would be greatly appreciated.

Hi all,

 

Still new to Apex and am having trouble with this test class:

 

@isTest

public class emailHandlerTest {

static testMethod void emailTest() {

//Create fake records
RecordType rt = [SELECT Id FROM RecordType WHERE SobjectType = 'Account' AND isActive = true AND DeveloperName like '%Person_Account%' LIMIT 1];
Account a = new Account();
a.RecordTypeId = rt.Id;
a.LastName = 'test';
insert a;

Property__c prop = new Property__c();
prop.Address_Line_1__c = '123 Street';
prop.Name = '123 Street';
insert prop;

rt = [SELECT Id FROM RecordType WHERE SobjectType = 'Opportunity' AND isActive = true AND Name like '%Rental%' LIMIT 1];
Opportunity opp = new Opportunity();
opp.AccountId = a.Id;
opp.Name = 'test';
opp.StageName = 'test';
opp.CloseDate = system.today();
opp.RecordTypeId = rt.Id;
opp.Property__c = prop.Id;
insert opp;

rt = [SELECT Id FROM RecordType WHERE SobjectType = 'Applicants__c' AND isActive = true AND Name like '%Primary_Applicant%' LIMIT 1];
Applicants__c app = new Applicants__c();
app.RecordTypeId = rt.Id;
app.Opportunity_Name__c = opp.Id;
app.Property__c = prop.Id;
app.Applicant_Email__c = 'test@test.com';

//Initiate Test One - Will the first email field fill in after an applicant record is inserted?
Test.startTest();

insert app;

Test.stopTest();

system.assert(opp.Additional_Applicant_1__c == 'test@test.com'); //This is Line 43
}
}

 

Actual Trigger being tested is here:

 

trigger emailHandler on Applicants__c (after insert) {

Set<ID> opportunityIds = new Set<ID>();

for (Applicants__c a: trigger.new) {

opportunityIds.add(a.Opportunity_Name__c);
}

List<Applicants__c> applicantEmail = [Select id, Applicant_Email__c From Applicants__c Where id in: Trigger.new];

List<Opportunity> emailFields = [Select id, Additional_Applicant_1__c, Additional_Applicant_2__c,Additional_Applicant_3__c,Additional_Applicant_4__c
From Opportunity
Where id in: opportunityIds];

for (Opportunity o: emailFields) {

for (Applicants__c a: applicantEmail) {

String email = a.Applicant_Email__c;

if (o.Additional_Applicant_1__c == null) {

o.Additional_Applicant_1__c = email;

}Else if (o.Additional_Applicant_1__c <> null && o.Additional_Applicant_2__c == null) {

o.Additional_Applicant_2__c = email;

}Else if (o.Additional_Applicant_1__c <> null && o.Additional_Applicant_2__c <> null && o.Additional_Applicant_3__c == null) {

o.Additional_Applicant_3__c = email;

}Else if (o.Additional_Applicant_1__c <> null && o.Additional_Applicant_2__c <> null && o.Additional_Applicant_3__c <> null && o.Additional_Applicant_4__c == null) {

o.Additional_Applicant_4__c = email;
}
}
}

update emailFields;
}

 

As you can see I'm creating fake records so that I can fulfill the required fields on my Applicant__c object.  I have to have an account to create the property, a property to create the opportunity, etc.  

 

The trigger I'm testing is "after insert" so that's why I'm putting the "insert app" line in within the test; because I want to see what happens to the opportunity after an applicant record is inserted.  What should happen is that "test@test.com" gets put in an opportunity field called "Additional_Applicant_1__c".

 

I'm using the Developer Console and there are no errors to solve.  I run the test and get "Assertion Failed" at line 43, which I take to mean that "test@test.com" is NOT present on that field.

 

The trouble is that an actual test of this code works perfectly (meaning if I physically create the applicant record instead of using the test class).

 

Bottom Line: I know the code works, but I can't get the test class to prove it.  Please help!

 

Here's the trigger:

trigger HistoricalAUM on Account (after insert, before update) {

List<Historical_AUM__c> TransferAUM = new List <Historical_AUM__c> {};

 Account[] accts;
    if (Trigger.isDelete) 
        accts = Trigger.old;
    else
        accts = Trigger.new;

for (account a : accts) {

TransferAUM.add( new Historical_AUM__c(Year_Revenue__c = a.Revenue__c, Revenue__c = a.Month_Revenue__c));

}
try {
upsert TransferAUM UpsertID__c;
}
catch (Exception Ex)
{
system.debug(Ex);
}
}

 

Here's the problem, but ONLY in production:

06:59:09.181 (181633000)|EXCEPTION_THROWN|[17]|System.DmlException: Upsert failed. First exception on row 0; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001d000000CluwJ) is currently in trigger HistoricalAUM, therefore it cannot recursively update itself: []

Test data works as expected in the sandbox, and had worked up until sometime in the last few weeks in production.

I'm brand new to Apex and need to test triggers to deploy to production.

I became reading some topics and I tried a lot do this test class for my trigger, but none doesn't work.

 

Anyone could help me with this test class?

 

Code:

 

trigger EmailTarefa on Task (after update) {
  static final String SUBJECT = 'Tarefa Concluída';
  static final String BODY = 'Atribuido Para: {0}\nRelativo a: {1}\nStatus: {2}\nAssunto: {3}\nComentário Enviado: {4}\nComentário de Conclusão: {5}';

  List<Id> creatorIds = new List<Id>();
  List<Id> ownerIds = new List<Id>();
  for (Task task : Trigger.new) {
    if (task.Status == 'Concluído') {
      creatorIds.add(task.CreatedById);
      ownerIds.add(task.OwnerId);  
    }
  } 

  List<User> creators = [Select Id, Email from User Where Id in :creatorIds];
  Map<Id,String> creatorIdsToEmails = new Map<Id,String>();
  for (User creator : creators) {
    creatorIdsToEmails.put(creator.Id,creator.Email);
  }
  
  List<User> owners = [Select Id, FirstName, LastName From User Where Id in :ownerIds];
  Map<Id,String> ownerIdsToNames = new Map<Id,String>();
  for (User owner : owners) {
    ownerIdsToNames.put(owner.Id,owner.FirstName + ' ' + owner.LastName);
  }
  
  for (Task task : Trigger.new) {
    if (task.Status == 'Concluído') {
      try {

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[] {creatorIdsToEmails.get(task.CreatedById)});
        mail.setSubject(SUBJECT);
        
        String url = System.URL.getSalesforceBaseUrl().toExternalForm() + '/' + task.WhatId;
        
        mail.setPlainTextBody(String.format(BODY,new String[]{
          ownerIdsToNames.get(task.OwnerId), url, task.Status,
          task.Subject, task.Description, task.Coment_rio_de_conclus_o_de_tarefa__c
        }));     
        
        Messaging.SendEmailResult[] result = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
        
        if (!result[0].isSuccess()) {
          System.debug(LoggingLevel.ERROR, 'Failed to send email'+result[0].getErrors()[0].getMessage());
        }
      
      } catch (System.EmailException ex) {
        System.debug(LoggingLevel.ERROR, 'Encountered EmailException');
      }
    }
  }
}

 

Any help in this will be realy apreciated.

 

Thanks!

I'm having some trouble with my code and I can't figure out what's wrong. I've used identical syntax in other classes but for some reason this one isn't working.

 

The objective of this class is to read the valuation date, determine if it's less than 30 days old, then act based on that result (changing the value of a field to 1 if it is < 30 days old or set to 0 if > 30)

 

global with sharing class CAB_ThisMonthBoolean implements Database.Batchable<sObject>{
   global final String Query;

   global CAB_ThisMonthBoolean() {
        this.Query = 'Select cab.navmfv2__Valuation_Date__c, cab.Id, cab.ThisMonthBoolean__c, cab.ThisMonth__C from navmfv2__Client_Account_Balance__c cab ';
   }
   
   global Database.QueryLocator start(Database.BatchableContext BC) {
      return Database.getQueryLocator(Query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope) {


    List<navmfv2__Client_Account_Balance__c> ClientAccountbalTrans = (List<navmfv2__Client_Account_Balance__c>) scope;
    List<navmfv2__Client_Account_Balance__c> updateClientAccountbal = new List<navmfv2__Client_Account_Balance__c>();
    
    for (navmfv2__Client_Account_Balance__c ClientAccountbalTran : ClientAccountbalTrans) {
        
        date currentDate = Date.today();
        date val = ClientAccountbalTran.navmfv2__Valuation_Date__c;
	    If(val.daysBetween(currentDate) < 30) {
			ClientAccountbalTran.ThisMonthBoolean__c = 1;
	    }
		else { ClientAccountbalTran.ThisMonthBoolean__c = 0; }
		updateClientAccountbal.add(ClientAccountbalTran);
        }
    update updateClientAccountbal;

    
}
    

   global void finish(Database.BatchableContext BC){

   }
   
 
public static testMethod void testBatch() {

 Account a = new Account(Name = 'Test Account', ShippingPostalCode = '00000', BillingCountry = 'US');
    insert a;

Contact con = new Contact(LastName = 'BatchTestContact');  
 insert con;

navmfv2__Fund__c Fund = new navmfv2__Fund__c(Name = 'Fake Fund', navmfv2__Fund_Short_Name__c = 'Fake Fund', navmfv2__CUSIP__c = '12345');
insert Fund;

navmfv2__Client_Account__c tstCA = new navmfv2__Client_Account__c (navmfv2__Client_Account_Number__c = '123TestCANum123', navmfv2__Sales_Rep_Name__c = con.id);
        insert tstCA;

Date thedate = Date.newInstance(2010,5,23);
navmfv2__Client_Account_Balance__c tstCAB = new navmfv2__Client_Account_Balance__c (navmfv2__Client_Account_Id__c = tstCA.Id, navmfv2__Valuation_Date__c = thedate, ThisMonthBoolean__c = 1);
        insert tstCAB;
       

    Test.StartTest();
    CAB_ThisMonthBoolean BatchClass = new CAB_ThisMonthBoolean();
    Database.executeBatch(BatchClass, 1);
    Test.StopTest();
  }
}

 

The code works in my sandbox (IE- It does what it's supposed to)- however I can't run it's test. 

I'm having some trouble with a class I'm creating. The purpose of this class is to essentially work around the Analytical Snapshot limit by batching the job- which is all fine but i'm getting the error in the title. Here's the code

 

global with sharing class AUMSnapshot implements Database.Batchable<sObject> {
   global final String Query;

   global AUMSnapshot() {
        this.Query = 'Select a.Id, a.navmfv2__Latest_AUM__c, a.navmfv2__AUM_as_of__c, a.Value__c, a.Research__c, a.Balanced__c, a.Government_MM__c, a.Hickory__c, a.NE_Tax_Free__c, a.Partners_Value__c, a.PIII__c, a.Short_Intermediate_Classes_combined__c  From Account a';
   }
   
   global AUMSnapshot(String query) {
        this.Query = query;
   }

   global Database.QueryLocator start(Database.BatchableContext BC) {
      return Database.getQueryLocator(Query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope) {
    
    List<Account> AccountAssets = (List<Account>) scope;
    
    List<Account> updateAccount = new List<Account>();
    
    for (Account AccountAsset : AccountAssets) {
	Historical_AUM__c haum = new Historical_AUM__c( Account__c = AccountAsset.Id, AUM__c = AccountAsset.navmfv2__Latest_AUM__c, Value__c = AccountAsset.Value__c, Research__c = AccountAsset.Research__c, Record_Date__c = AccountAsset.navmfv2__AUM_as_of__c, Balanced__c = AccountAsset.Balanced__c, Government_MM__c = ACcountAsset.Government_MM__c, NE_Tax_Free__c = AccountAsset.NE_Tax_Free__c, Hickory__c = AccountAsset.Hickory__c, Partners_Value__c = AccountAsset.Partners_Value__c, PIII__c = AccountAsset.PIII__c, Short_Intermediate__c = AccountAsset.Short_Intermediate_Classes_combined__c, UpsertID__c = AccountAssets.Id & AccountAsset.navmfv2__AUM_as_of__c);
	upsert haum UpsertID__c; 
	
    }
    
    update updateAccount;
    
   }

   global void finish(Database.BatchableContext BC){

   }
   
   public static testMethod void testBatch() {
    
    Account a = new Account(Name = 'Test Account', ShippingPostalCode = '00000', BillingCountry = 'US', navmfv2__AUM_as_of__c = Date.today());
    insert a;
    
	Historical_AUM__c b = new Historical_AUM__c( Account__c = a.Id, AUM__c = a.navmfv2__Latest_AUM__c, Value__c = a.Value__c, Research__c = a.Research__c, Record_Date__c = a.navmfv2__AUM_as_of__c, Balanced__c = a.Balanced__c, Government_MM__c = a.Government_MM__c, NE_Tax_Free__c = a.NE_Tax_Free__c, Hickory__c = a.Hickory__c, Partners_Value__c = a.Partners_Value__c, PIII__c = a.PIII__c, Short_Intermediate__c = a.Short_Intermediate_Classes_combined__c, UpsertID__c = a.Id & a.navmfv2__AUM_as_of__c);
	upsert b;

    Test.StartTest();
    AUMSnapshot BatchClass = new AUMSnapshot();
    Database.executeBatch(BatchClass, 1);
    //BatchClass.execute(null, new List<sObject>{zipper});
    Test.StopTest();
   }
}

 

 

 The part where I declare haum is the offending line of code. I would appreciate any help.

System.QueryException: List has no rows for assignment to SObjectClass.ClientTransBatch.testBatch: line 132, column 1

Presumeably the only part of this code that matters is the test class at the very bottom.

That's the error I'm getting from the test in this class:

 (Code removed)

 

I'm obviously doing something wrong with this test class but I can't figure out what. Can anyone help me?

I've put together a trigger to roll up some asset amounts from contacts to our accounts, however, I can't figure out for the life of me how I would write a test class in this situation, can anyone help me? I'm no apex pro.

 

Also- the fields being summed and sent to the account object are actually rollup fields from a child object of contact. When these fields are updated will they cause the trigger to fire? There's one of these triggers for each of our different asset amounts (8 in total).

 

Thanks for your help!

 

trigger SumBalanced on Contact (after insert,after update,after delete)
{
    Set<Id> accountIdset = new Set<Id>();
   
    for (Contact con:trigger.new)
    {
       accountIdset.add(con.AccountId);
    }
    Map<Id,Account> AccountMap = new Map<Id,Account>([Select Id,Balanced__c from Account where Id in :accountIdset]);
    for(AggregateResult res : [SELECT AccountId, SUM(Balanced__c) cnt FROM Contact where AccountId in : accountIdset GROUP BY ROLLUP(AccountId)]){
        if(res.get('AccountId') <> null){
            AccountMap.get((ID)res.get('AccountId')).Balanced__c = (Decimal)res.get('cnt');
        }
    }
    update AccountMap.values();
	}