• Damon Long
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hey all, 

I am having an issue with my test class I have created. I am only getting 44% code coverage with my test class and I am not sure why. Any help would be greatly appreciated.

Apex Class:
public class AssignedAdvisorController {
    @AuraEnabled
    public static User getAssignedAdvisor(Id recordId){
       Account account = [select Assigned_Adviser__c from Account where Id=: recordId];
        User user = [select Name, Phone from User where Id=: account.Assigned_Adviser__c];
        return User; 
       }  
    
    @AuraEnabled
    public static String getAdvisorPhone(Id recordId){
        Account account = [select Assigned_Adviser__c from Account where Id=: recordId];
        User user = [select Phone from User where Id=: account.Assigned_Adviser__c];
        String advisorPhone = user.Phone;
        return advisorPhone;
        
       }
}

Test Class:
@isTest
private class AssignedAdvisorControllerTest{
  @testSetup
  static void setupTestData(){
    test.startTest();
    User user_Obj = new User(FirstName = 'Test', LastName = 'User');
    Account account_Obj = new Account(Name = 'Test User', Assigned_Adviser__c = user_Obj.id);
    Insert account_Obj; 
    test.stopTest();
  }
  static testMethod void test_getAssignedAdvisor(){
     test.startTest();
    List<Account> account_Obj  =  [SELECT Id,Name,Assigned_Adviser__c from Account];
    System.assertEquals(true,account_Obj.size()>0);
    AssignedAdvisorController obj01 = new AssignedAdvisorController();
    AssignedAdvisorController.getAssignedAdvisor('01p90000006uk2w');
      test.stopTest();
  }
  static testMethod void test_getAdvisorPhone(){
      test.startTest();
    List<Account> account_Obj  =  [SELECT Id,Name,Assigned_Adviser__c from Account];
    System.assertEquals(true,account_Obj.size()>0);
    AssignedAdvisorController obj01 = new AssignedAdvisorController();
    AssignedAdvisorController.getAdvisorPhone('01p90000006uk2w');
      test.stopTest();
  }
}



 
Hey everyone,
I need some help converting my Apex trigger into a class. I am just unsure about the syntax differences between the trigger and class and I'm aware that I can't use trigger.new in the class. Do I need to create a new list to be able to use trigger.new? Any help or direction would be greatly appreciated!

Trigger:
trigger TotalAumUpdate on Account (after update) {
    for(Account acc : Trigger.new){
        Account oldAcc = Trigger.oldMap.get(acc.Id);
        if(oldAcc.Total_AUM__c != acc.Total_AUM__c){
            List<Opportunity> opps = [SELECT Id, AccountId, Current_Balance__c from Opportunity where AccountId = :acc.Id];                              
            List<Opportunity> newids = new List <Opportunity>();
            	for(Opportunity opp: opps){
                    if(opp.Current_Balance__c != acc.Total_AUM__c){
                        opp.Current_Balance__c = acc.Total_AUM__c;
                        newids.add(opp);
                    }
            }
            if(newids.isEmpty()== false){
                update newids;
            }
        }
    }

}

 
Hey all, 

I am having an issue with my test class I have created. I am only getting 44% code coverage with my test class and I am not sure why. Any help would be greatly appreciated.

Apex Class:
public class AssignedAdvisorController {
    @AuraEnabled
    public static User getAssignedAdvisor(Id recordId){
       Account account = [select Assigned_Adviser__c from Account where Id=: recordId];
        User user = [select Name, Phone from User where Id=: account.Assigned_Adviser__c];
        return User; 
       }  
    
    @AuraEnabled
    public static String getAdvisorPhone(Id recordId){
        Account account = [select Assigned_Adviser__c from Account where Id=: recordId];
        User user = [select Phone from User where Id=: account.Assigned_Adviser__c];
        String advisorPhone = user.Phone;
        return advisorPhone;
        
       }
}

Test Class:
@isTest
private class AssignedAdvisorControllerTest{
  @testSetup
  static void setupTestData(){
    test.startTest();
    User user_Obj = new User(FirstName = 'Test', LastName = 'User');
    Account account_Obj = new Account(Name = 'Test User', Assigned_Adviser__c = user_Obj.id);
    Insert account_Obj; 
    test.stopTest();
  }
  static testMethod void test_getAssignedAdvisor(){
     test.startTest();
    List<Account> account_Obj  =  [SELECT Id,Name,Assigned_Adviser__c from Account];
    System.assertEquals(true,account_Obj.size()>0);
    AssignedAdvisorController obj01 = new AssignedAdvisorController();
    AssignedAdvisorController.getAssignedAdvisor('01p90000006uk2w');
      test.stopTest();
  }
  static testMethod void test_getAdvisorPhone(){
      test.startTest();
    List<Account> account_Obj  =  [SELECT Id,Name,Assigned_Adviser__c from Account];
    System.assertEquals(true,account_Obj.size()>0);
    AssignedAdvisorController obj01 = new AssignedAdvisorController();
    AssignedAdvisorController.getAdvisorPhone('01p90000006uk2w');
      test.stopTest();
  }
}



 
Hey everyone,
I need some help converting my Apex trigger into a class. I am just unsure about the syntax differences between the trigger and class and I'm aware that I can't use trigger.new in the class. Do I need to create a new list to be able to use trigger.new? Any help or direction would be greatly appreciated!

Trigger:
trigger TotalAumUpdate on Account (after update) {
    for(Account acc : Trigger.new){
        Account oldAcc = Trigger.oldMap.get(acc.Id);
        if(oldAcc.Total_AUM__c != acc.Total_AUM__c){
            List<Opportunity> opps = [SELECT Id, AccountId, Current_Balance__c from Opportunity where AccountId = :acc.Id];                              
            List<Opportunity> newids = new List <Opportunity>();
            	for(Opportunity opp: opps){
                    if(opp.Current_Balance__c != acc.Total_AUM__c){
                        opp.Current_Balance__c = acc.Total_AUM__c;
                        newids.add(opp);
                    }
            }
            if(newids.isEmpty()== false){
                update newids;
            }
        }
    }

}