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
Sharon WardSharon Ward 

Changeset Apex Test Failure

Hi,

I have an inbound Changeset that has failed with the following message:

Apex Test Failures 
Class Name: TestTriggerUtility
Method Name: testContactTrigger
Error Message: System.AssertException: Assertion Failed: Expected: 005D0000008twq8IAA, Actual: 005D0000001gINxIAM 
Stack Trace: Class.TestTriggerUtility.testContactTrigger: line 40, column 1

I have tried googling this but nothing is very specific.  I have no idea what the Trigger Utility is or how to ignore this.

Any help would be appreciated.  
I inherited this copy of Salesforce and still trying to find out what all the triggers and classes are for!
 
mayuri patil 6mayuri patil 6
Hi Sharon,

The assertion in salesforce is used to test if the expected value is input or not.
Seeing the error, the assetion statement is not getting the value which is expected & thats why the failure.
It will be good if you can post the code.
following link may be similar:
https://success.salesforce.com/answers?id=90630000000ghCDAAY

Regards,
Mayuri
Sharon WardSharon Ward
Hi Mayuri, unfortunately I have no idea which trigger this is referring to.  Is it the Class Name or Method Name I need to check?

Thanks
Sharon
mayuri patil 6mayuri patil 6
Hi Sharon,

pls check the following
Class.TestTriggerUtility.testContactTrigger: line 40, column 1
go to class TestTriggerUtility & line 40.

Regards,
Mayuri
 
Sharon WardSharon Ward
Thanks Mayuri, here is the code: [cid:image001.png@01D3F12A.C89F9B60] Thanks Sharon Sharon Ward Sales Operations Manager M: +44 (0)7988 566900 Email: sward@amplience.com [/Users/sward/Library/Containers/com.microsoft.Outlook/Data/Library/Caches/Signatures/signature_1449370871]
Narender Singh(Nads)Narender Singh(Nads)
Hi Sharon,
We might be able to help you if you can just share the code of the Apex Class with name 'TestTriggerUtility' in your org.

Thanks
Sharon WardSharon Ward
Hi, Thanks for your response – the code is as follows: [cid:image001.png@01D3F131.8D712390] Thanks again Sharon
Narender Singh(Nads)Narender Singh(Nads)
Umm...
There is no code here!
Sharon WardSharon Ward

1./**
2  * This class contains unit tests for validating the behavior of Apex classes
3  * and triggers.
4 *
5 * Unit tests are class methods that verify whether a particular piece
6 * of code is working properly. Unit test methods take no arguments,
7 * commit no data to the database, and are flagged with the testMethod
8 * keyword in the method definition.
9 *
10 * All test methods in an organization are executed whenever Apex code is deployed
11 * to a production organization to confirm correctness, ensure code
12 * coverage, and prevent regressions. All Apex classes are
13 * required to have at least 75% code coverage in order to be deployed
14 * to a production organization. In addition, all triggers must have some code coverage.
15 * 
16 * The @isTest class annotation indicates this class only contains test
17 * methods. Classes defined with the @isTest annotation do not count against
18 * the organization size limit for all Apex scripts.
19 *
20 * See the Apex Language Reference for more information about Testing and Code Coverage.
21  */
22   @isTest
23    private class TestTriggerUtility {
24
25    static testMethod void testContactTrigger () {
26    // Creating test data
27    Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
28    User u = new User(Alias = 'standt', Email='standarduser@testorg.com', 
29   EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
30  LocaleSidKey='en_US', ProfileId = p.Id, 
31    TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@tcla.com');
32    insert u;
33    
34     Account accInstance = new Account (Name= 'Test', Targeted_By_Lookup__c = u.Id);
35     insert  accInstance;
36     
37     Contact conInstance = new Contact (LastName='TestCon', AccountId = accInstance.Id, LeadSource = 'Capture/Ringlead',
38                                      OwnerId = UserInfo.getUserId());
39     insert conInstance;
40    System.assertEquals(u.Id, [SELECT OwnerId FROM Contact WHERE Id =: conInstance.Id].OwnerId);
41   }
42 }
Narender Singh(Nads)Narender Singh(Nads)
Hi Sharon,
Replace line 37 with the following line in your code:
Contact conInstance = new Contact (LastName='TestCon', AccountId = accInstance.Id, LeadSource = 'Capture/Ringlead', OwnerId = U.id);

let me know if it helps.
Thanks!
 
Sharon WardSharon Ward
Hi Narender,

Thank you for your response.  Before I replace the code, please would you be able to tell what this trigger is actually testing and is it needed?  I can't quite work out what it's supposed to be doing and wonder if I need it at all?  I'm actually trying to delete any contact triggers and have deleted one in my sandbox environment and now trying to put the change set in production without the contact.trigger.

Thanks
Sharon
Narender Singh(Nads)Narender Singh(Nads)
Hi Sharon,
I cannot comment on the working of your trigger, since I haven't seen your code of that trigger. But I can tell you what this test class is doing.

This test class is creating some mock data:
A standard user profile, A user with that assigned profile, an account with a custom field asscociated with User ID and a contact associated with the account and owner as the User.
And finally, its doing an assertion that User ID is equal to the Contact owner ID.
 
Sharon WardSharon Ward
Thank you again Narender....  I don't think I need this at all, so would like to delete it.  I have successfully deleted in my sandbox, but don't know how to replicate this in production.  I don't have Force.com IDE, so is there another way to do it without that?
Narender Singh(Nads)Narender Singh(Nads)
Hi Sharon,

You can do this two ways.

1. Using workbench. Refer this link for help : http://www.salesforceben.com/way-to-delete-apex-classes-from-production/
2. If you don't want to go through the hassle of using workbench. In your sandox, you can either comment out the whole trigger code or deactivate the trigger and then push the changes to your production.