• Andrew Fisher 28
  • NEWBIE
  • 20 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
Can anyone help me with a Test class for this code please ?

Apex Class
public class OpptyCloseTimerCntrl {
    
    @AuraEnabled
    public static Date fetchOpptyCloseDate(String recId){
        Opportunity opp = [select End_of_Quarter__c from Opportunity where id =: recId];
        system.debug('Close Date: ' +opp.End_of_Quarter__c);
        
        return opp.End_of_Quarter__c;
    }
}
Hi I can only get 66% coverage for this apex class, could someone kindly help me get above 75% please?

Apex Class
public class OpptyCloseTimerCntrl {
    
    @AuraEnabled
    public static Date fetchOpptyCloseDate(String recId){
        Opportunity opp = [select End_of_Quarter__c from Opportunity where id =: recId];
        system.debug('Close Date: ' +opp.End_of_Quarter__c);
        
        return opp.End_of_Quarter__c;
    }
}

test class I have:
@isTest
private class OpptyCloseTimerCntrl_Test{
  @testSetup
  static void setupTestData(){
    test.startTest();
    Opportunity opportunity_Obj = new Opportunity(IsPrivate = false, Name = 'Name749', StageName = '1. Selection', CloseDate = Date.today(), X1_MIFIS_Pipeline__c = false, X2_VDF_Persona__c = false, X3_VDF_Workshop_Doc__c = false, X4_ICETEA__c = false, X5_Forecast__c = false, Named_Account__c = false, Strategic__c = false, DVM_Volume_Sale__c = false, DSCORGPKG__Converted_from_Discoverorg_Data__c = false, Exclusion__c = false, Acronis_Referral__c = false, Existing_ARR__c = false, REVGRD__CreatedBySCC__c = false, Professional_Services_Project__c = false, Future_Q__c = false, Cloud_Strategy_Populated__c = false, Company_Vision_Strategy_Populated__c = false, Competition_Populated__c = false, Custom_Dev__c = false, Decision_Makers_Populated__c = false, Decision_Making_Criteria_Populated__c = false, Decision_Making_Process_Populated__c = false, MDF__c = false, Non_Standard_Billing_Terms__c = false, Non_Standard_Discount__c = false, Non_Standard_Pricing_Terms__c = false, Non_Standard_Taxation_Terms__c = false, Optimal_Future_State_Populated__c = false, Organizational_Pain_Impact_Populated__c = false, Pain_We_Address_Populated__c = false, Payment_Terms_60_Days__c = false, Scope_of_Work__c = false, Solution_Needs_Populated__c = false, Specific_Invoice_Terms__c = false, Technical_Description_Populated__c = false, MQL_Lead_Origin__c = false, X2021_MQL__c = false, LID__Is_Influenced__c = false, Confirm_Customer_Support_Set_up_Complete__c = false, Production_VHI_License_Provided__c = false, MQL_exclude__c = false, Customer_needs_KA_access__c = false, Customer_needs_KA_hierarchy__c = false, Do_not_send_onboarding_email__c = false, Is_SO_Signed_agreement_attached__c = false, customer_needs_community_accounts__c = false, Contact_Role_Added__c = false);
    Insert opportunity_Obj; 
    test.stopTest();
  }
  static testMethod void test_fetchOpptyCloseDate_UseCase1(){
    List<Opportunity> opportunity_Obj  =  [SELECT End_of_Quarter__c from Opportunity];
    System.assertEquals(true,opportunity_Obj.size()>0);
    OpptyCloseTimerCntrl obj01 = new OpptyCloseTimerCntrl();
    OpptyCloseTimerCntrl.fetchOpptyCloseDate('test data');
  }
}

Any help would be highly appreciated
 
Hi wonderful Community

I need help with a test class for a trigger, only at 47% !!

Here is the Trigger

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Trigger CreatingAutoRecords on Opportunity (After Insert, After Update)
{
    
    List<MRR__c> MRRRecordsFinalListToInsert = New List<MRR__c>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate)
    {
        For(Opportunity opp : Trigger.New)
        {
            If(Opportunity.Contract_Period_Months__c != null)
            {
                List<MRR__c> fetchingAlreadyExixtsedRecords = [Select Id FROM MRR__c WHERE Opportunity__c =:opp.Id];
                
                If(fetchingAlreadyExixtsedRecords.IsEmpty())
                {
                    // We are only creating a records when there is no MRR__c records exixts.
                    For(Integer I = 1; I <= opp.Contract_Period_Months__c;I++)
                    
                        {
                        MRR__c crd = New MRR__c();
                        
                        crd.Opportunity__c = opp.Id;
                        crd.Name       = 'Month' + I;
                        crd.MRR_Amount__c = opp.MRR_Amount__c;
                        crd.MRR_Date__c = opp.Contract_Start_Date__c.addMonths(I);
                        
                        MRRRecordsFinalListToInsert.add(crd);
                    }
                }
                
            }
            
            try{
                If(!MRRRecordsFinalListToInsert.IsEmpty()){
                    insert MRRRecordsFinalListToInsert;
                }
            }
            Catch(Exception e){
                System.debug('The thrown exception for CreatingAutoRecords is:: ' + e.getMessage());
            }
        }
    }
    
    
}

And this is the Test Class

@isTest
private with sharing class CreatingAutoRecordsTest {

static testMethod void MyTestCreatingAutoRecords()
{
test.starttest(); 

    
    List<MRR__c> MRRRecordsFinalListToInsert = New List<MRR__c>();
    
    
    
    
      
   MRR__c crd = New MRR__c();
    crd.Opportunity__c =  '0062C00000AVFEwQAP';
    crd.Name = 'Testing';
    
    crd.MRR_Amount__c = 110;   
    
      MRRRecordsFinalListToInsert.add(crd);
                        
                        
     insert MRRRecordsFinalListToInsert;
    
    
    
    
    
     Database.SaveResult str = database.insert(crd , False);

        System.assertEquals(True, str.isSuccess());
     
   test.stoptest();  
    

}
}


Any help would he highly appreciated to get it to pass at least

 
Hi
Would someone be able to help me please?
i have a trigger which inserts child records when a field is populated, it works fine but have 2 issues 

1. The Month field (crd.name) is starting from 0 ideally would like it to start from 1
2. I want to add a month to each record (crd.mrr date__c) 

Idea is it would create 10 records if Opp.Contract_period_months__c) = 10

Here is my code

Trigger CreatingAutoRecords on Opportunity (After Insert, After Update)
{
    
    List<MRR__c> MRRRecordsFinalListToInsert = New List<MRR__c>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate)
    {
        For(Opportunity opp : Trigger.New)
        {
            If(Opportunity.Contract_Period_Months__c != null)
            {
                List<MRR__c> fetchingAlreadyExixtsedRecords = [Select Id FROM MRR__c WHERE Opportunity__c =:opp.Id];
                
                If(fetchingAlreadyExixtsedRecords.IsEmpty())
                {
                    // We are only creating a records when there is no MRR__c records exixts.
                    For(Integer I = 0; I < opp.Contract_Period_Months__c;I++)
                    
                        {
                        MRR__c crd = New MRR__c();
                        
                        crd.Opportunity__c = opp.Id;
                        crd.Name       = 'Month' + I;
                        crd.MRR_Amount__c = opp.MRR_Amount__c;
                        crd.MRR_Date__c = opp.Contract_Start_Date__c ;
                        
                        MRRRecordsFinalListToInsert.add(crd);
                    }
                }
                
            }
            
            try{
                If(!MRRRecordsFinalListToInsert.IsEmpty()){
                    insert MRRRecordsFinalListToInsert;
                }
            }
            Catch(Exception e){
                System.debug('The thrown exception for CreatingAutoRecords is:: ' + e.getMessage());
            }
        }
    }
    
    
}

Any help would be highly appreciated
 
Can anyone help me with a Test class for this code please ?

Apex Class
public class OpptyCloseTimerCntrl {
    
    @AuraEnabled
    public static Date fetchOpptyCloseDate(String recId){
        Opportunity opp = [select End_of_Quarter__c from Opportunity where id =: recId];
        system.debug('Close Date: ' +opp.End_of_Quarter__c);
        
        return opp.End_of_Quarter__c;
    }
}
Hi wonderful Community

I need help with a test class for a trigger, only at 47% !!

Here is the Trigger

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Trigger CreatingAutoRecords on Opportunity (After Insert, After Update)
{
    
    List<MRR__c> MRRRecordsFinalListToInsert = New List<MRR__c>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate)
    {
        For(Opportunity opp : Trigger.New)
        {
            If(Opportunity.Contract_Period_Months__c != null)
            {
                List<MRR__c> fetchingAlreadyExixtsedRecords = [Select Id FROM MRR__c WHERE Opportunity__c =:opp.Id];
                
                If(fetchingAlreadyExixtsedRecords.IsEmpty())
                {
                    // We are only creating a records when there is no MRR__c records exixts.
                    For(Integer I = 1; I <= opp.Contract_Period_Months__c;I++)
                    
                        {
                        MRR__c crd = New MRR__c();
                        
                        crd.Opportunity__c = opp.Id;
                        crd.Name       = 'Month' + I;
                        crd.MRR_Amount__c = opp.MRR_Amount__c;
                        crd.MRR_Date__c = opp.Contract_Start_Date__c.addMonths(I);
                        
                        MRRRecordsFinalListToInsert.add(crd);
                    }
                }
                
            }
            
            try{
                If(!MRRRecordsFinalListToInsert.IsEmpty()){
                    insert MRRRecordsFinalListToInsert;
                }
            }
            Catch(Exception e){
                System.debug('The thrown exception for CreatingAutoRecords is:: ' + e.getMessage());
            }
        }
    }
    
    
}

And this is the Test Class

@isTest
private with sharing class CreatingAutoRecordsTest {

static testMethod void MyTestCreatingAutoRecords()
{
test.starttest(); 

    
    List<MRR__c> MRRRecordsFinalListToInsert = New List<MRR__c>();
    
    
    
    
      
   MRR__c crd = New MRR__c();
    crd.Opportunity__c =  '0062C00000AVFEwQAP';
    crd.Name = 'Testing';
    
    crd.MRR_Amount__c = 110;   
    
      MRRRecordsFinalListToInsert.add(crd);
                        
                        
     insert MRRRecordsFinalListToInsert;
    
    
    
    
    
     Database.SaveResult str = database.insert(crd , False);

        System.assertEquals(True, str.isSuccess());
     
   test.stoptest();  
    

}
}


Any help would he highly appreciated to get it to pass at least

 
Hi
Would someone be able to help me please?
i have a trigger which inserts child records when a field is populated, it works fine but have 2 issues 

1. The Month field (crd.name) is starting from 0 ideally would like it to start from 1
2. I want to add a month to each record (crd.mrr date__c) 

Idea is it would create 10 records if Opp.Contract_period_months__c) = 10

Here is my code

Trigger CreatingAutoRecords on Opportunity (After Insert, After Update)
{
    
    List<MRR__c> MRRRecordsFinalListToInsert = New List<MRR__c>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate)
    {
        For(Opportunity opp : Trigger.New)
        {
            If(Opportunity.Contract_Period_Months__c != null)
            {
                List<MRR__c> fetchingAlreadyExixtsedRecords = [Select Id FROM MRR__c WHERE Opportunity__c =:opp.Id];
                
                If(fetchingAlreadyExixtsedRecords.IsEmpty())
                {
                    // We are only creating a records when there is no MRR__c records exixts.
                    For(Integer I = 0; I < opp.Contract_Period_Months__c;I++)
                    
                        {
                        MRR__c crd = New MRR__c();
                        
                        crd.Opportunity__c = opp.Id;
                        crd.Name       = 'Month' + I;
                        crd.MRR_Amount__c = opp.MRR_Amount__c;
                        crd.MRR_Date__c = opp.Contract_Start_Date__c ;
                        
                        MRRRecordsFinalListToInsert.add(crd);
                    }
                }
                
            }
            
            try{
                If(!MRRRecordsFinalListToInsert.IsEmpty()){
                    insert MRRRecordsFinalListToInsert;
                }
            }
            Catch(Exception e){
                System.debug('The thrown exception for CreatingAutoRecords is:: ' + e.getMessage());
            }
        }
    }
    
    
}

Any help would be highly appreciated