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
PritsPrits 

I am getting error in apex class for contact role count

What is wrong in my apex test class code. i am getting error


public class test_updatecontactrolecount
{
 public static testMethod void testcreateopptywithconditionandrole()
{
//Insert Opportunities 
try
{
    // insert Account
    Account[] Acct = new Account[]
    {
        new Account(name = 'testAcct1')
    };
    insert Acct;
    
    Opportunity Oppty = new Opportunity(Name='Oppty_test1',  StageName='Qualified target', Initial_Interest__c ='Needs Updating', CloseDate= System.Today() );
    insert Oppty;
    
    // insert contact
    Contact[] cont = new Contact[]
    {
        new Contact(LastName = 'testcontact1'),
        new Contact(LastName = 'testcontact2')
    };    
    insert cont;    
    // insert contact role     
    OpportunityContactRole [] ocr = new OpportunityContactRole[]
    {
    new OpportunityContactRole(Role ='PD Contact',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = True),
    new OpportunityContactRole(Role ='Upload Contact',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = False)
    };
    insert ocr;    
    Oppty.StageName = 'Proposal in Funnel';    
    //Update opportunity
    
    Test.StartTest();
    update Oppty;
    Test.StopTest();
 
           
    Oppty =[SELECT Number_of_Contacts_Roles_Assigned__c,Primary_Contact_Assigned__c FROM Opportunity WHERE Id = :Oppty.Id];
    system.assert (Oppty.Number_of_Contacts_Roles_Assigned__c == 2);
    system.assert (Oppty.Primary_Contact_Assigned__c == True);
}
catch (System.DmlException e)
{
    System.assert(false);
}        

}
Gaurish Gopal GoelGaurish Gopal Goel
What is the error?
PritsPrits
Apex Test Result Detail 
Time Started3/23/2018 1:12 PM
Classtest_updatecontactrolecount
Method Nametestcreateopptywithconditionandrole
Pass/FailFail
Error MessageSystem.Exception: Assertion Failed
Stack TraceClass.test_updatecontactrolecount.testcreateopptywithconditionandrole: line 38, column 1
Gaurish Gopal GoelGaurish Gopal Goel
Hi Prits,

I guess this is a test class for a trigger. Since your assertion is not getting passed, so you should first perform a manual test before running your test class and see it the trigger logic is working fine or not. Thanks.