• Angel Rey
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
Hello,

I'm learnig apex and trying with a code I have found but I get an error I can solve.

This original code (api version 17) works fine (run test is passed):

public class test_updatecontactrolecount
{
public static testMethod void testcreateopptywithconditionandrole()
{
//Insert Opportunities
try
{
    Opportunity Oppty = new Opportunity(Name='Oppty_test1',StageName='Stage 1 - Unqualified Prospect',Type ='New Business', 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 ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = True),
    new OpportunityContactRole(Role ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = False)
    };
    insert ocr;   
    Oppty.StageName = 'Stage 3 - Eval Request';   
    //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);
}       
}
}


I'm trying to adapt to api version 30 test classes with the code below but when I run the test I get this error:

Error Message System.AssertException: Assertion Failed
Stack Trace Class.TestUpdateNumContactRoles.testcreateopptywithconditionandrole: line 32, column 1

What is wrong and why works with the old api version?


@isTest
private class TestUpdateNumContactRoles {
     static testMethod void testcreateopptywithconditionandrole() {
     final Double numContactRoles= 2;
     final boolean PrimaryContact = true;

    //Insert Opportunities
    try {
        Opportunity Oppty = new Opportunity(Name='Oppty_test1',StageName='Stage 1 - Unqualified Prospect',Type ='New Business', 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 ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = True),
        new OpportunityContactRole(Role ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = False)
        };
        insert ocr;   
        Oppty.StageName = 'Stage 3 - Eval Request';   
        //Update opportunity
       
       Test.StartTest();
        update Oppty;
       Test.StopTest();
       
        Oppty =[SELECT NumContactRoles__c,PrimaryContact__c FROM Opportunity WHERE Id = :Oppty.Id];
        system.assert (Oppty.NumContactRoles__c == 2);
        system.assert (Oppty.PrimaryContact__c == True);
    }
        catch (System.DmlException e) {
            System.assert(false);
        }       
    }
}


Thanks a lot
Hello,

I'm learnig apex and trying with a code I have found but I get an error I can solve.

This original code (api version 17) works fine (run test is passed):

public class test_updatecontactrolecount
{
public static testMethod void testcreateopptywithconditionandrole()
{
//Insert Opportunities
try
{
    Opportunity Oppty = new Opportunity(Name='Oppty_test1',StageName='Stage 1 - Unqualified Prospect',Type ='New Business', 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 ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = True),
    new OpportunityContactRole(Role ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = False)
    };
    insert ocr;   
    Oppty.StageName = 'Stage 3 - Eval Request';   
    //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);
}       
}
}


I'm trying to adapt to api version 30 test classes with the code below but when I run the test I get this error:

Error Message System.AssertException: Assertion Failed
Stack Trace Class.TestUpdateNumContactRoles.testcreateopptywithconditionandrole: line 32, column 1

What is wrong and why works with the old api version?


@isTest
private class TestUpdateNumContactRoles {
     static testMethod void testcreateopptywithconditionandrole() {
     final Double numContactRoles= 2;
     final boolean PrimaryContact = true;

    //Insert Opportunities
    try {
        Opportunity Oppty = new Opportunity(Name='Oppty_test1',StageName='Stage 1 - Unqualified Prospect',Type ='New Business', 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 ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = True),
        new OpportunityContactRole(Role ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = False)
        };
        insert ocr;   
        Oppty.StageName = 'Stage 3 - Eval Request';   
        //Update opportunity
       
       Test.StartTest();
        update Oppty;
       Test.StopTest();
       
        Oppty =[SELECT NumContactRoles__c,PrimaryContact__c FROM Opportunity WHERE Id = :Oppty.Id];
        system.assert (Oppty.NumContactRoles__c == 2);
        system.assert (Oppty.PrimaryContact__c == True);
    }
        catch (System.DmlException e) {
            System.assert(false);
        }       
    }
}


Thanks a lot

I've searched for this on the boards and found some previous posts that describe almost the same exact problem but unfortunately they didn't have replies or solutions to them.

 

We have a two-step approval process set up on an Opportunity record.  The first step routes to a specific user.  The second step routes to Manager.  The problem happens when the first step approver approves the record the second step routes the approval step to their User Manager when it should go to the User Manager for the Opportunity Record Owner who originally started the approval process. 

 

Next Automated Approver Determined By is set to Manager.  Use Approver Field of Opportunity Owner is checked.

 

Is this  a known bug?  Has anyone found a workaround?