• Ajosh John
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Hello,

Need help with this this test class code coverage.

Apex Class:
public class sendAccountOwnerChangeRequest
{
    public Id referredAccountReqId;
    public Account st;
    public String approvalComments{get;set;}
    public sendAccountOwnerChangeRequest(ApexPages.StandardController controller)
    {
        list<Account> colld;
        referredAccountReqId=controller.getId();
        if(referredAccountReqId!= null){
        colld=[select recordtype.name, Name,In_Approval_Queue__c,BillingState,BillingCountry,Request_Record__c, 
        Area_Code__c,Owner.Email,OwnerId,Locked_to_Owner__c from Account where Id=:referredAccountReqId];
        
        }
         if(colld != null && !colld.isEmpty()){
          st=colld[0];
        }
    }
    
    public Pagereference doCancel()
    {
        Pagereference pgref=new Pagereference('https://cambridgefx.lightning.force.com/lightning/page/home');
        pgref.setRedirect(true);
        return pgref;
    }
    
    public Pagereference updateowner()
    {
        Integer userProspects = [ SELECT COUNT()FROM Account WHERE (RecordType.Name = 'Prospect' or RecordType.Name = 'Prospect Read Only') AND Account.OwnerId = : Userinfo.getUserId()];
        system.debug('User Prospect is --->'+userProspects);
        User u=[select Prospect_Maximum__c from user where Id=: Userinfo.getUserId() Limit 1];
        system.debug('User Prospect Max is --->'+u.Prospect_Maximum__c);
        if(st.Request_Record__c.containsIgnoreCase('TAKE')){
            
            if(st.recordtype.name!='Prospect'){
            
            
            if(userProspects > u.Prospect_Maximum__c){
    st.addError('ApxCl:002 - Prospect Max -- The User has reached their limit of Prospects. ' + 'Prospects owned - ' + userProspects + ', Limit - ' + u.Prospect_Maximum__c +'.');

    }
            AccountTeamMember objAccountTeamMember= new AccountTeamMember();
            objAccountTeamMember.AccountId=referredAccountReqId;
            objAccountTeamMember.UserId=Userinfo.getUserId();
            insert objAccountTeamMember;
            }
            
            else if(st.recordtype.name =='Prospect' && userProspects > u.Prospect_Maximum__c){
    st.addError('ApxCl:002 - Prospect Max -- The User has reached their limit of Prospects. ' + 'Prospects owned - ' + userProspects + ', Limit - ' + u.Prospect_Maximum__c +'.');

    return null;
    }
    
            else {
             st.OwnerId=Userinfo.getUserId();

            }
            update st;
            PageReference acctPage = new PageReference('/'+referredAccountReqId);
            return acctPage;
            }
        else{
            return null;
        }
    }

Test Class:

@isTest
private class TestAccountOwnerChangeRequest {

    static testMethod void myUnitTest() {
        ID profileId=[select Id from profile where Name like'%Administrator%' Limit 1].Id;
        ID role_Id=[select Id from UserRole where Name like'%Administration%' Limit 1].Id;
        
        User u1 = new User();
        u1.Username = 'unit_test1@cambridgefx.com.test1';
        u1.Email = 'unit_test1@cambridgefx.com.uat';
        u1.ProfileId=profileId;
        u1.UserRoleId=role_Id;
        u1.LastName='Test';
        u1.Alias='test';
        u1.Country='USA';
        u1.City='New York';
        u1.Prospect_Maximum__c=100;
        insert u1;
        
        User u2 = new User();
        u2.Username = 'unit_test2@cambridgefx.com.test2';
        u2.Email = 'unit_test2@cambridgefx.com.uat';
        u2.ProfileId=profileId;
        u2.UserRoleId=role_Id;
        u2.LastName='Test';
        u2.Alias='test';
        u2.Country='USA';
        u2.City='New York';
        u1.Prospect_Maximum__c=100;
        insert u2;
        
        System.runAs(u2) {
        Account acc=new Account();
        acc.BillingCity='Test Vegas';
        acc.BillingState='ON';
        acc.BillingCountry='CAN';
        acc.Name='Unit Test Account';
        acc.OwnerId=u1.Id;
        acc.RecordType.Name='Prospect';
        insert acc;  
        
        Task tsk=new Task();
        tsk.Subject='Call';
        tsk.OwnerId=u1.Id;
        tsk.WhatId=acc.Id;
        tsk.ActivityDate=system.today()-180;
        tsk.Status='Completed';
        insert tsk;
        
        Test.startTest();
        PageReference pageRef= Page.SendAccountOwnerShipChangeRequest;
        Test.setCurrentPage(pageRef);
        sendAccountOwnerChangeRequest acontroller = new sendAccountOwnerChangeRequest(new ApexPages.StandardController(acc));
        PageReference pageRef1=acontroller.updateowner();
        
        pageRef1=acontroller.doCancel();
        acontroller.updateowner();

        PageReference pageRef2= Page.SearchCompanies;
        Test.setCurrentPage(pageRef2);
        ControllerSearchCompanies acontroller1 = new ControllerSearchCompanies();
        acontroller1.matchAll =false;
        acontroller1.matchAny =true;
        acontroller1.errorMessageText='test';
        acontroller1.conditionText='test';
        acontroller1.companynameText='test';
        acontroller1.phoneText='test';
        acontroller1.websiteText='test';
        acontroller1.stateText='test';
        acontroller1.countryText='test';
        acontroller1.nameText='test';
        acontroller1.domainText='test';
        acontroller1.streetText='test';
        acontroller1.companynameCheck=true;
        acontroller1.phoneCheck=true;
        acontroller1.websiteCheck=true;
        acontroller1.stateCheck=true;
        acontroller1.countryCheck=true;
        acontroller1.domainCheck=true;
        acontroller1.nameCheck=true;
        acontroller1.streetCheck=true;
        acontroller1.doSearch();

    Test.stopTest();
        }
    }

}
Hi there. I have an VF page which is refernced to an apex class which basically references another VF page. Need help with a test class for this.

Visual Force Page where Apex Class is referenced:
<apex:page sidebar="false" lightningStylesheets="true">
<apex:form id="theForm">
 <div align="center">
  <apex:page controller="T_Dashboards">
<b><apex:commandbutton action="{!tradersummary}" value="Trader Summary"></apex:commandbutton></b>
<b><apex:commandbutton action="{!traderbook}" value="Trader Book"></apex:commandbutton></b>
<b><apex:commandbutton action="{!creditutilizationtrader}" value="Credit Utilization - Trader"></apex:commandbutton></b>
</apex:page>

Apex Class:
public class T_Dashboards {
public PageReference tradersummary() {

        PageReference pgref = new PageReference('/apex/TraderSummary');
        pgref.setRedirect(true);
        return pgref;
    }

public PageReference traderbook() {
        PageReference pgref = new PageReference('/apex/TraderBook');
        pgref.setRedirect(true);
        return pgref;
    }

public PageReference creditutilizationtrader() {
        PageReference pgref = new PageReference('/apex/CreditUtilizationTrader');
        pgref.setRedirect(true);
        return pgref;
    }
}

Test Class:
@isTest 
public class TestTDashboards{
public static testmethod void myunitTest(){    
Test.startTest();    
PageReference pageRef = Page.T_Dashboards;  
Test.setCurrentPage(pageRef);
T_Dashboards acontroller = new T_Dashboards();
PageReference pageRef1=acontroller.tradersummary();
Test.stopTest(); 
}
}
Hello everyone,

Need help with this.

I need a trigger on Event object which populates two custom fields(event) with the Billing City and Billing Country from related Account object.

Any help on this is appreciated.

AJ
Morning,

I have been receiving this email stating the trigger i wrote on Accounts has to be indexed.

I have no idea on what is causing this issue.

Any help on this is apprecaited. Below is the snipet of the code and the error.

execution of BeforeUpdate
 
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

 if(MapAccount != null && MapAccount.keySet() != null){
        list<Account> colAccounts = [select id,Client_Code__c,First_Trade__c,Reactivation_Date__c,Client_FTT__c from Account where Client_Code__c != null and Client_Code__c in : MapAccount.keySet()];
        if(!colAccounts.isEmpty()){
            for(Account objAccount : colAccounts){
                if(objAccount.Client_Code__c != null){
                    MapAccountOpt.put(objAccount.Client_Code__c,objAccount);
Hi there. I have an VF page which is refernced to an apex class which basically references another VF page. Need help with a test class for this.

Visual Force Page where Apex Class is referenced:
<apex:page sidebar="false" lightningStylesheets="true">
<apex:form id="theForm">
 <div align="center">
  <apex:page controller="T_Dashboards">
<b><apex:commandbutton action="{!tradersummary}" value="Trader Summary"></apex:commandbutton></b>
<b><apex:commandbutton action="{!traderbook}" value="Trader Book"></apex:commandbutton></b>
<b><apex:commandbutton action="{!creditutilizationtrader}" value="Credit Utilization - Trader"></apex:commandbutton></b>
</apex:page>

Apex Class:
public class T_Dashboards {
public PageReference tradersummary() {

        PageReference pgref = new PageReference('/apex/TraderSummary');
        pgref.setRedirect(true);
        return pgref;
    }

public PageReference traderbook() {
        PageReference pgref = new PageReference('/apex/TraderBook');
        pgref.setRedirect(true);
        return pgref;
    }

public PageReference creditutilizationtrader() {
        PageReference pgref = new PageReference('/apex/CreditUtilizationTrader');
        pgref.setRedirect(true);
        return pgref;
    }
}

Test Class:
@isTest 
public class TestTDashboards{
public static testmethod void myunitTest(){    
Test.startTest();    
PageReference pageRef = Page.T_Dashboards;  
Test.setCurrentPage(pageRef);
T_Dashboards acontroller = new T_Dashboards();
PageReference pageRef1=acontroller.tradersummary();
Test.stopTest(); 
}
}
Hello everyone,

Need help with this.

I need a trigger on Event object which populates two custom fields(event) with the Billing City and Billing Country from related Account object.

Any help on this is appreciated.

AJ
Morning,

I have been receiving this email stating the trigger i wrote on Accounts has to be indexed.

I have no idea on what is causing this issue.

Any help on this is apprecaited. Below is the snipet of the code and the error.

execution of BeforeUpdate
 
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

 if(MapAccount != null && MapAccount.keySet() != null){
        list<Account> colAccounts = [select id,Client_Code__c,First_Trade__c,Reactivation_Date__c,Client_FTT__c from Account where Client_Code__c != null and Client_Code__c in : MapAccount.keySet()];
        if(!colAccounts.isEmpty()){
            for(Account objAccount : colAccounts){
                if(objAccount.Client_Code__c != null){
                    MapAccountOpt.put(objAccount.Client_Code__c,objAccount);