function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shriya BhalchandranShriya Bhalchandran 

I would like to know reason for not covering the class?

<b>Apex Class</b>

public class RenewOppEndate
{
     public static final string CRenewOppEndate = 'RenewOppEndate';
     public static final string UPDATEENDATE = 'updateEndate';
    
    public static void updateEndate(List<Opportunity> oppNewList)
    {
        try
        {
            set<Id> accIdSet = new set<Id>();
            Date TempEffDate = NULL;
            
            for(Opportunity opp: oppNewList)
            {
                if(opp.AccountId != NULL && opp.Type == Label.Renewal)
                {
                    accIdSet.add(opp.AccountId);
                }
            }
            Map<ID,Account> accMap = new Map<ID,Account>([select Id,(select Id,Effective_Date__c from Opportunities Order By Effective_Date__c DESC LIMIT 1) 
                                     from Account where ID IN:accIdSet LIMIT 50000]);
            
            for(Opportunity opp : oppNewList)
            {
                if(String.isNotBlank(opp.AccountId) && opp.Type == Label.Renewal){
                    Account accObj = accMap.get(opp.AccountId);
                    List<Opportunity> oldOppList = accObj.opportunities;
                    if(oldOppList != NULL && !oldOppList.isEmpty()){
                        Date tempEffectiveDate = oldOppList[0].Effective_Date__c; 
                        opp.Effective_Date__c = tempEffectiveDate != NULL ? tempEffectiveDate.addYears(1) : tempEffectiveDate ;
                    }
                }               
            }
        }
        catch(exception ex)
        {UTIL_LoggingService.logHandledException(ex);}
    }
    
}


<b>Test Class

</b>
<b>@isTest
public class RenewOppEndate_Test
{
    
    private static testMethod void renewOpptyTest()
    {   
        User testUser = Util02_TestData.createUser();
        
        Account testAccount = Util02_TestData.createAccountData();   
        
        System.runAs(testUser)
        {
           
            Database.insert(testAccount);
            
            Opportunity opp = Util02_TestData.createOpportunity();
            opp.AccountId = testAccount.id;
            opp.stageName = Label.Renewal;
            database.insert(opp);   
        }       
    }
        
}     </b>

 
Best Answer chosen by Shriya Bhalchandran
v varaprasadv varaprasad
Hi Shriya,

Please check once below sample code : 
 
@isTest
public class RenewOppEndate_Test
{
    
    private static testMethod void renewOpptyTest()
    {   
        User testUser = Util02_TestData.createUser();
        
        Account testAccount = Util02_TestData.createAccountData();   
        
        System.runAs(testUser)
        {
           
            Database.insert(testAccount);
            
            Opportunity opp = Util02_TestData.createOpportunity();
            opp.AccountId = testAccount.id;
            opp.type = Label.Renewal;
            database.insert(opp);
			
            List<Opportunity> opList = [slect id,name,account,Type,Effective_Date__c from Opportunity where id =: opp.id];		
			
			RenewOppEndate.CRenewOppEndate = 'RenewOppEndate'; 
			RenewOppEndate.UPDATEENDATE = 'updateEndate';    
            RenewOppEndate.updateEndate(opList);
			
        }       
    }
        
}

Hope this helps you!

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com

 

All Answers

v varaprasadv varaprasad
Hi Shriya,

Please check once below sample code : 
 
@isTest
public class RenewOppEndate_Test
{
    
    private static testMethod void renewOpptyTest()
    {   
        User testUser = Util02_TestData.createUser();
        
        Account testAccount = Util02_TestData.createAccountData();   
        
        System.runAs(testUser)
        {
           
            Database.insert(testAccount);
            
            Opportunity opp = Util02_TestData.createOpportunity();
            opp.AccountId = testAccount.id;
            opp.type = Label.Renewal;
            database.insert(opp);
			
            List<Opportunity> opList = [slect id,name,account,Type,Effective_Date__c from Opportunity where id =: opp.id];		
			
			RenewOppEndate.CRenewOppEndate = 'RenewOppEndate'; 
			RenewOppEndate.UPDATEENDATE = 'updateEndate';    
            RenewOppEndate.updateEndate(opList);
			
        }       
    }
        
}

Hope this helps you!

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com

 
This was selected as the best answer
Shriya BhalchandranShriya Bhalchandran

Hi,
it is showing error:


Final members can only be assigned in their declaration, init blocks, or constructors: RenewOppEndate

Shriya BhalchandranShriya Bhalchandran
Hey It worked, I just removed Final memeber and it worked, Thank you!