• FB Admin
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
I am hitting the wall on this test class.  The Trigger and code are below.  Any suggestions are welcome.  It's my first try at a test class.  When running the test, my query does not seam to fire.  However, when I run it in the query editor, it pulls the correct account.  Also, none of my system.debugs show in logs when filtering for "Debug Only"

In the logs I get: "FATAL_ERROR System.QueryException: List has no rows for assignment to SObject."
 
trigger UpdateDisReg on Account (after update) {

        Account a = Trigger.New[0];
        String alias = 'a.center__c';
        System.debug(a);
        List<Lead> leadsToUpdate = [select id,CenterDistrict__c,CenterRegion__c from Lead where Owner_Alias__c = 'alias'];

        System.debug(leadsToUpdate);
        List<Lead> leads = new List<Lead>();
        
    for(Lead Leadz : leadsToUpdate) {
         leadz.CenterDistrict__c = a.District__c;
         leads.add(leadz);
         {
       
       update leads;
}
}
}
Test Class:
 
@isTest
private class UpdateDisRegTest {
        private static testMethod void UpdateDisReg() {
        
        Account a = [SELECT Id, District__c, Region__c FROM Account WHERE NAME IN ('Center 000001')];
        insert a;
        System.Debug(a);
            
            
        Lead l = [SELECT Id, CenterDistrict__c, CenterRegion__c FROM Lead WHERE Owner_Alias__c = '000001' Limit 1];
        insert l;
    	System.Debug(l);
            
        Test.startTest();
        
        a.District__c = 55;
        a.Region__c = 66;
            
        update a;
       
		System.assertEquals(55, l.CenterDistrict__C);  
        System.assertEquals(66, l.CenterDistrict__C);
            
        Test.stopTest();
  
   }
  
}


 
Newbie here.  Trying to update multiple records when the user record of the owner is updated.  It is only updating the first record and not properly looping through/updating all as I would expect.  Any advise appreciated, been googling for hours.

trigger UpdateDistrictRegion on User (after update) {
        List<Lead> leadsToUpdate = [select id,CenterDistrict__c,CenterRegion__c from Lead where OwnerID IN :Trigger.New];
        System.debug(leadsToUpdate);
        List<Lead> leads = new List<Lead>();
        User u = Trigger.New[0];
    for(Lead Leadz : leadsToUpdate) {
         leadz.CenterDistrict__c = u.District__c;
         leads.add(leadz);
         {
       
       update leads;
}
}
}
I am hitting the wall on this test class.  The Trigger and code are below.  Any suggestions are welcome.  It's my first try at a test class.  When running the test, my query does not seam to fire.  However, when I run it in the query editor, it pulls the correct account.  Also, none of my system.debugs show in logs when filtering for "Debug Only"

In the logs I get: "FATAL_ERROR System.QueryException: List has no rows for assignment to SObject."
 
trigger UpdateDisReg on Account (after update) {

        Account a = Trigger.New[0];
        String alias = 'a.center__c';
        System.debug(a);
        List<Lead> leadsToUpdate = [select id,CenterDistrict__c,CenterRegion__c from Lead where Owner_Alias__c = 'alias'];

        System.debug(leadsToUpdate);
        List<Lead> leads = new List<Lead>();
        
    for(Lead Leadz : leadsToUpdate) {
         leadz.CenterDistrict__c = a.District__c;
         leads.add(leadz);
         {
       
       update leads;
}
}
}
Test Class:
 
@isTest
private class UpdateDisRegTest {
        private static testMethod void UpdateDisReg() {
        
        Account a = [SELECT Id, District__c, Region__c FROM Account WHERE NAME IN ('Center 000001')];
        insert a;
        System.Debug(a);
            
            
        Lead l = [SELECT Id, CenterDistrict__c, CenterRegion__c FROM Lead WHERE Owner_Alias__c = '000001' Limit 1];
        insert l;
    	System.Debug(l);
            
        Test.startTest();
        
        a.District__c = 55;
        a.Region__c = 66;
            
        update a;
       
		System.assertEquals(55, l.CenterDistrict__C);  
        System.assertEquals(66, l.CenterDistrict__C);
            
        Test.stopTest();
  
   }
  
}


 
Newbie here.  Trying to update multiple records when the user record of the owner is updated.  It is only updating the first record and not properly looping through/updating all as I would expect.  Any advise appreciated, been googling for hours.

trigger UpdateDistrictRegion on User (after update) {
        List<Lead> leadsToUpdate = [select id,CenterDistrict__c,CenterRegion__c from Lead where OwnerID IN :Trigger.New];
        System.debug(leadsToUpdate);
        List<Lead> leads = new List<Lead>();
        User u = Trigger.New[0];
    for(Lead Leadz : leadsToUpdate) {
         leadz.CenterDistrict__c = u.District__c;
         leads.add(leadz);
         {
       
       update leads;
}
}
}