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
Jamie JohnsonJamie Johnson 

Inbound Change Sets

I have a failed Deployment in an inbound Change set:

AvoidDuplicateUsageEntry   Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

 

AvoidDuplicateUsageEntry is an Apex Trigger and the Code Coverage is 0%

This apex trigger was part of an RFP package from Salesforce labs that created a Custom Object named Questions. It has not failed before??

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
trigger AvoidDuplicateUsageEntry on Question__c (before insert) 
{
    for (Question__c question: Trigger.new)
    {
        if (question.Override_Warning__c == false)
        {
            try
            {
              Question__c[] q = [SELECT q.CreatedById, q.CreatedDate, q.Question__c from Question__c q where q.Response__c = :question.Response__c and q.RFP__c = :question.RFP__c ORDER BY CreatedDate desc];
              if (q.size() > 0)
              {
                  User u = [SELECT u.Name from User u where id = :q[0].CreatedById];
                  String questionStr = String.escapeSingleQuotes(q[0].Question__c);
                  questionStr = questionStr.replace('\"', '\\\"');
                  String userStr = String.escapeSingleQuotes(u.Name);
                  userStr = userStr.replace('\"', '\\\"');
                  String dateStr = q[0].CreatedDate.format('MM/dd/yyyy hh:mm a');
                  String errorJSON = 'var errorJSON = {timesUsed: ' + q.size() + ', question: \"' + questionStr + '\", user: \"' + userStr + '\", time: \"' + dateStr + '\"};';  
                  question.Response__c.addError(errorJSON);
              } // endif
            }
            catch (QueryException e)
            {
                // This is actually the non-error case.  The Question should not 
                // already exist.  Do nothing.
            }
        } // endif
    } // endfor
}

 

In any case, I can't seem to find out how to fix this failure so I can deploy my inbound change set.

 

I am a beginner and need a little help.

 

thanks!

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Jamie JohnsonJamie Johnson

I wanted to reply to this case to tell you the resolution after everyone was so kind and offered their help.  The trigger "AvoidDuplicateUsageEntry" on the custom Object "Question" was part of RFPforce in the AppExchange. It was downloaded directly from the AppExchange into production after it was tested in sandbox. However the trigger "AvoidDuplicateUsageEntry" has a Code coverage of 0% when downloaded from AppExchange.  Of course, this code can not be changed or tested in Production and was blocking my new code. Salesforce said that this should not happen because you must have coverage to post on AppExchange - and essentially I was on my own.

 

So, over the holiday weekend I dismantled RFPforce in Production - made changes to the Trigger in sandbox - moved the application back over to production piece meal from sandbox, then linked all of my backup data back into the right areas - and uploaded the new code that was blocked by RFPforce.

 

It is now working correctly. Even though this was not suppose to happen, I have learned a lot and will not blindly accept downloads from the AppExchange in the future. Thank you everyone for your kind support!

All Answers

Benji1Benji1

hi, It looks like the error is q.Question__c, the Question_c is custom object name.

 

SELECT q.CreatedById, q.CreatedDate, q.Question__c from Question__c

 

Jamie JohnsonJamie Johnson

Thank you for your reply. I really appreciate it!

However, since this is a Package from SF labs I can't alter the code - Can I?  I can't see a way to do it anyway? If I go thru the object or thru apex triggers - there is no option to edit.

Rahul2505Rahul2505

Hi Jamie,

 

Test Class for this trigger is not available on target org or even not included in your changeset.

 

Once you will include test class for this trigger and provide test coverage more than 75% for this trigger then this issue will be resolved.

 

Thanks...

Jamie JohnsonJamie Johnson

I wanted to reply to this case to tell you the resolution after everyone was so kind and offered their help.  The trigger "AvoidDuplicateUsageEntry" on the custom Object "Question" was part of RFPforce in the AppExchange. It was downloaded directly from the AppExchange into production after it was tested in sandbox. However the trigger "AvoidDuplicateUsageEntry" has a Code coverage of 0% when downloaded from AppExchange.  Of course, this code can not be changed or tested in Production and was blocking my new code. Salesforce said that this should not happen because you must have coverage to post on AppExchange - and essentially I was on my own.

 

So, over the holiday weekend I dismantled RFPforce in Production - made changes to the Trigger in sandbox - moved the application back over to production piece meal from sandbox, then linked all of my backup data back into the right areas - and uploaded the new code that was blocked by RFPforce.

 

It is now working correctly. Even though this was not suppose to happen, I have learned a lot and will not blindly accept downloads from the AppExchange in the future. Thank you everyone for your kind support!

This was selected as the best answer
aaronbedwell.ax1665aaronbedwell.ax1665

How did you modify the trigger? I've got the same trigger and can't figure out how to modify it so it will pass.

aaronbedwell.ax1665aaronbedwell.ax1665

Nevermind, I figured it out. Thanks.

jcavanaughjcavanaugh

how did you fix this?  I am running into the same issue and am new at all of this?

aaronbedwell.ax1665aaronbedwell.ax1665

My memory is a little foggy with this, but I think what I did was find the test class for the trigger. What it was doing was using a test record that existed in the sandbox but not in production. I modified so it worked for the record in production and then deployed it.