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
Vipin  PulinholyVipin Pulinholy 

Task Trigger- Deployment Failure-Please Help

Hi,

 

I have this trigger on task.

 

 

trigger PIMAccountOwnerUpdate on Task (before update,before insert) { for (Task h : Trigger.new){ Opportunity [] opid= [Select o.OwnerId,o.Owner.Alias from Opportunity o where id=:h.WhatId ]; Contact [] contid = [Select c.OwnerId, c.Owner.Alias from Contact c where id=:h.WhoId ]; if (opid .size()> 0) h.PIM_Account_Owner__c = opid[0].Owner.Alias ; else h.PIM_Account_Owner__c = '' ; if (contid .size() > 0) h.Contact_Owner_Alias__c = contid [0].Owner.Alias ; else h.Contact_Owner_Alias__c = '' ; } }

And following Test Class.

 

@istest private class PIMAccountOwnerUpdate { static testMethod void passTest() { test.starttest(); Date futureDate = date.newInstance(2010, 6, 6); Account account = new Account(name='testAccount'); insert account; account = [select name from Account where name=:account.name]; Opportunity opp = new Opportunity(name='testOpp', accountID=account.ID, StageName='Prospect 3', CloseDate = futureDate); insert opp; opp = [select ID, name from Opportunity where ID=:opp.ID]; Contact contact = new Contact(lastname='testContact', accountID=account.ID); insert contact; contact = [select name from Contact where LastName=:contact.lastname]; Task h = new Task ( OwnerId='005300000017Z6B', Status='In Progress',Subject='Compile a Mailing',WhatId=opp.Id ); try { insert h; System.assert(true); System.debug('Updated '); } catch (DmlException e) { System.debug('Query Issue: ' + e); } Task h1 = new Task ( OwnerId='005300000017Z6B', Status='In Progress',Subject='Compile a Mailing',WhoId=contact.Id ); try { insert h1; System.assert(true); System.debug('Updated1 '); } catch (DmlException e) { System.debug('Query Issue: ' + e); } Opportunity [] opid= [Select o.OwnerId,o.Owner.Alias from Opportunity o where id=:opp.Id ]; Contact [] contid = [Select c.OwnerId, c.Owner.Alias from Contact c where id='00330000002kPEq' ]; if (opid.size() > 0) { System.debug( 'Inside For Loop'); } test.stoptest(); } }

This is what the trigger does:

I have two custom fields created on Task (Activity) object (PIM_Account_Owner & Contact_Owner_Alias). When ever user update/creates any task I wanted to update these custom fields (PIMM_Account_Owner & Contact_Owner_Alias) with the value of Opportunity Owner Alias and Contact Owner Alias respectively.

 

When I run test on this test class I get 100% converge. 

But when I try to deploy this trigger Production I get 0% coverage results.

Deployment Result

Deployment Result 

I have this owner id (005300000017Z6B) present in the Sandbox and Prod.

 I am using Eclipse Force IDE. 

Could any one please help me on this?

 

 
Message Edited by das on 09-16-2009 10:58 AM
JonSimmonsJonSimmons

 

It might be helpfull to see the logs, and any debug output that you have.

 

Most likely there is something different about your Production environment vs. your Sandbox.  Quite possibly either the OwnerId or the Contact id specified in the code.

 

 

Vipin  PulinholyVipin Pulinholy

Thanks much for your reply. I modified the code (remomed Owner ID and COntact Id). But still I get the Failiure.

 

@istest private class PIMAccountOwnerUpdate { static testMethod void passTest1() { test.starttest(); Date futureDate = date.newInstance(2010, 6, 6); Account account = new Account(name='testAccount'); insert account; account = [select name from Account where name=:account.name]; Opportunity opp = new Opportunity(name='testOpp', accountID=account.ID, StageName='Prospect 3', CloseDate = futureDate); insert opp; opp = [select ID, name from Opportunity where ID=:opp.ID]; Contact contact = new Contact(lastname='testContact', accountID=account.ID); insert contact; contact = [select name from Contact where LastName=:contact.lastname]; User user; user = [Select Id from User where Alias='CONVPP']; Task h = new Task ( OwnerId=user.Id, Status='In Progress',Subject='Compile a Mailing',WhatId=opp.Id ); try { insert h; System.assert(true); System.debug('Updated '); } catch (DmlException e) { System.debug('Query Issue: ' + e); } Task h1 = new Task ( OwnerId=user.Id, Status='In Progress',Subject='Compile a Mailing',WhoId=contact.Id ); try { insert h1; System.assert(true); System.debug('Updated1 '); } catch (DmlException e) { System.debug('Query Issue: ' + e); } Opportunity [] opid= [Select o.OwnerId,o.Owner.Alias from Opportunity o where id=:opp.Id ]; Contact [] contid = [Select c.OwnerId, c.Owner.Alias from Contact c where id=:contact.Id ]; if (opid.size() > 0) { System.debug( 'Inside For Loop'); } test.stoptest(); } }

 

Deployment Result

 In the log I see this message:

 

# Test Results:
  PIMAccountOwnerUpdate Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
  Average test coverage across all Apex Classes and Triggers is 11%, at least 75% test coverage is required

 

In the Deplyment log I don't see any info related to this trigger. There are info about other triggers. Here is the log

 

 

 

*** Beginning Test 1: HouseholdMemberDuplicate.static testMethod void passTest() 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 7, column 1: Insert: SOBJECT:Household__c 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 7, column 1: Changing testing limit context based on DML operation of size: 1 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 7, column 1: DML Operation executed in 76 ms 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 10, column 28: SOQL query with 1 row finished in 25 ms 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 13, column 1: Insert: SOBJECT:Contact 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 13, column 1: DML Operation executed in 84 ms 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 17, column 29: SOQL query with 1 row finished in 31 ms 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 18, column 22: SOQL query with 1 row finished in 37 ms 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 23, column 1: Insert: SOBJECT:Household_Member__c *** Beginning HouseholdMemberDuplicateTrigger on Household_Member trigger event BeforeInsert for null 20090916192448.414:Trigger.HouseholdMemberDuplicateTrigger: line 2, column 4: SelectLoop:LIST:SOBJECT:Household_Member__c 20090916192448.414:Trigger.HouseholdMemberDuplicateTrigger: line 4, column 39: SOQL query with 0 rows finished in 10 ms Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 0 out of 100 Number of query rows: 0 out of 500 Number of SOSL queries: 0 out of 20 Number of DML statements: 1 out of 100 Number of DML rows: 1 out of 500 Number of script statements: 3 out of 200000 Maximum heap size: 0 out of 1000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 Testing resources: Resource usage for namespace: (default) Number of SOQL queries: 4 out of 20 Number of query rows: 3 out of 1000 Number of SOSL queries: 0 out of 0 Number of DML statements: 2 out of 20 Number of DML rows: 2 out of 100 Number of script statements: 9 out of 10200 Maximum heap size: 0 out of 200000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 0 Number of System.runAs() invocations: 0 out of 0 Total email recipients queued to be sent : 0 *** Ending HouseholdMemberDuplicateTrigger on Household_Member trigger event BeforeInsert for null 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 23, column 1: DML Operation executed in 108 ms 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 31, column 1: Insert: SOBJECT:Household_Member__c *** Beginning HouseholdMemberDuplicateTrigger on Household_Member trigger event BeforeInsert for null 20090916192448.518:Trigger.HouseholdMemberDuplicateTrigger: line 2, column 4: SelectLoop:LIST:SOBJECT:Household_Member__c 20090916192448.518:Trigger.HouseholdMemberDuplicateTrigger: line 4, column 39: SOQL query with 1 row finished in 8 ms Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 0 out of 100 Number of query rows: 0 out of 500 Number of SOSL queries: 0 out of 20 Number of DML statements: 1 out of 100 Number of DML rows: 1 out of 500 Number of script statements: 3 out of 200000 Maximum heap size: 0 out of 1000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 Testing resources: Resource usage for namespace: (default) Number of SOQL queries: 5 out of 20 Number of query rows: 4 out of 1000 Number of SOSL queries: 0 out of 0 Number of DML statements: 3 out of 20 Number of DML rows: 3 out of 100 Number of script statements: 13 out of 10200 Maximum heap size: 0 out of 200000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 0 Number of System.runAs() invocations: 0 out of 0 Total email recipients queued to be sent : 0 *** Ending HouseholdMemberDuplicateTrigger on Household_Member trigger event BeforeInsert for null 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 31, column 1: DML Operation executed in 19 ms 20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 36, column 1: Query Issue: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Member already exists in this Household: [Name] 20090916192448.144:Class.HouseholdMemberDuplicate: line 3, column 24: returning from end of method static testMethod void passTest() in 392 ms Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 0 out of 100 Number of query rows: 0 out of 500 Number of SOSL queries: 0 out of 20 Number of DML statements: 1 out of 100 Number of DML rows: 1 out of 500 Number of script statements: 3 out of 200000 Maximum heap size: 0 out of 1000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 Testing resources: Resource usage for namespace: (default) Number of SOQL queries: 4 out of 20 Number of query rows: 3 out of 1000 Number of SOSL queries: 0 out of 0 Number of DML statements: 3 out of 20 Number of DML rows: 3 out of 100 Number of script statements: 13 out of 10200 Maximum heap size: 0 out of 200000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 0 Number of System.runAs() invocations: 0 out of 0 Total email recipients queued to be sent : 0 *** Ending Test HouseholdMemberDuplicate.static testMethod void passTest() Cumulative profiling information: No profiling information for SOQL operations. No profiling information for SOSL operations. No profiling information for DML operations. No profiling information for method invocations.

 

 

 

JonSimmonsJonSimmons

Hi,

 

It looks like inserting  your test contact causes a couple of other triggers to fire, one of which fails.

 

20090916192448.144:Class.HouseholdMemberDuplicate.passTest: line 36, column 1: Query Issue: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Member already exists in this Household: [Name]

 

This failure causes execution to stop which means the trigger that you are testing fails.  It probably doesn't fail in your sandbox because either the related triggers don't exist, or the duplicate contact doesn't exist, thus the 100% coverage in sandbox but not production.

 

 

btw, in this section below, you shouldn't need to select the account after you insert it, the result of the insert should be that the account now contains the id of that account, so there is no need to select anything because you already have it all.  (The same goes for your opportunity and contact)

 

 

Account account = new Account(name='testAccount'); insert account; account = [select name from Account where name=:account.name];

 

 

 

 

 Jon