-3

I installed an app from Salesforce Labs into my production org and later found out that there are errors in the test class. Now these errors are preventing me from deploying a different project, so I need to fix them.

Here's the app listing on the appexchange: https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000E1hf7UAB

Here's a link to the test class code: https://pastebin.pl/view/e08376d9

And here are the errors I'm seeing when I run a test:

Class: CaseStatusChangeTriggerHandlerTest Method Name: testAccessible1 Pass/Fail: Fail Error Message: System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.CaseStatusChangeTriggerHandlerTest.getUser: line 139, column 1 Class.CaseStatusChangeTriggerHandlerTest.testAccessible1: line 66, column 1

Class: CaseStatusChangeTriggerHandlerTest Method Name: testAccessible2 Pass/Fail: Fail Error Message: System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.CaseStatusChangeTriggerHandlerTest.getUser: line 139, column 1 Class.CaseStatusChangeTriggerHandlerTest.testAccessible2: line 82, column 1

Class: CaseStatusChangeTriggerHandlerTest Method Name: testCreatable Pass/Fail: Fail Error Message: System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.CaseStatusChangeTriggerHandlerTest.getUser: line 139, column 1 Class.CaseStatusChangeTriggerHandlerTest.testCreatable: line 97, column 1

Class: CaseStatusChangeTriggerHandlerTest Method Name: testUpdatable Pass/Fail: Fail Error Message: System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.CaseStatusChangeTriggerHandlerTest.getUser: line 139, column 1 Class.CaseStatusChangeTriggerHandlerTest.testUpdatable: line 122, column 1

All of these errors seem to stem from two lines of code:

Lines 66, 82, 97, 122: User u = getUser('String');

Line 139: Profile p = [SELECT Id FROM Profile WHERE Name=:profileName limit 1];

I'm a beginner with Apex coding, so how can I understand and fix these errors?

2
  • 1
    That stack trace does not appear to come from a managed package class. Why do you believe the Labs product is at fault?
    – David Reed
    Oct 20 at 17:32
  • When I install the package into a brand new developer org I get the same errors.
    – NickG
    Oct 20 at 18:06
0

This error means you are trying to execute a SOQL query and return a single record, but you are not actually getting any results from the query.

So in your case, line 139 is your issue. You are passing in the profileName parameter as a condition to retrieve and store the profile object into the Profile p variable. But looking at the functions that are calling getUser(), I'm going to guess that the profileName param you're passing is is not a valid profile name.

To resolve this, you can do one of two things:

  1. Pass in a real profile name into your getUser() method. Profiles are one of few sobjects that use actual org data, so it needs to be one from your org or one that you create during the test setup.
  2. Or, store the SOQL query results as a List<Profile> pList instead. This will allow you to query and store the results, even if they're empty, into a list. Then, in your test code, you can check for pList.isEmpty() as opposed to throwing an error.
2
  • 1
    Thanks for clarifying. I used your explanation and the first option you detailed to resolve this issue.
    – NickG
    Oct 25 at 21:34
  • Not a big deal, but would love if you could mark this as the accepted answer if it worked for you!
    – Maya Tran
    Oct 25 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.