+ Start a Discussion
Patrick DixonPatrick Dixon 

Deployment failure

I get the following errors when tring to deploy my first website from sandbox to production

MyProfilePageController.testSave()Class7835Failure Message: "System.QueryException: List has no rows for assignment to SObject", Failure Stack Trace: "Class.MyProfilePageController.testSave: line 78, column 35 External entry point"
Deploy Error


Average test coverage across all Apex Classes and Triggers is 46%, at least 75% test coverage is required

 

 

However, MyProfilePageController is not my code and is not included in the change set anyway!  So what on earth is this all about?

    

 

 

 

    
Cory CowgillCory Cowgill

The first problem here is your test method MyProfilePageController.testSave().

 

You are getting this exception "List has no rows for Assignment". 9 times out of 10 this is due to your test data not being created during your test.

 

For example, this Query you are executing at line 78, are you creating this test data at the beginning of the test method? If not, you need to. It might be working in Sandbox because the data already exists there, but when you deploy your code to production it runs the tests against your production environment where the data might not exist.

 

Best practice is to always create all the testdata that your test method needs at the beginning of your test method. This ensures that whenever you deploy from one environment to the next, it will always work becuase the data is created at the time the test is ran.

 

Second error is your Test Coverage. Your tests are only covering 46%. Because Salesforce (and Force.com) run in a multitenant environment, they enforce code standards to prevent erratic code from being deployed which may impact other tenants on the system. Therefore, they impose their Governor Limits and Test Code Coverage limits. You need to have at least 75% of your code tested in Unit Tests for it to be able to be deployed into production.

 

Fix the first data issue in your testSave method, and you test coverage will probably increase.

Patrick DixonPatrick Dixon
It's a very simple site with no triggers or rules.  This is my Controller code:


public class NewsController {

public PageReference handleNewItemClick() {
 PageReference pageRef= new PageReference('/apex/newsedit');
 pageRef.setredirect(true);
 return pageRef;
}

public News_Item__c[] getHeadlines() {
 return [select Name, id, CreatedDate, CreatedBy.Name, Item__c from News_Item__c order by LastModifiedDate desc limit 3];
 }

public News_Item__c[] getItems() {
 return [select Name, id, CreatedDate, CreatedBy.Name, Item__c from News_Item__c];
 }

public News_Item__c getNewsEntry() {
 id id = ApexPages.currentPage().getParameters().get('id');
 if (id == null)
  return [select Name, id, CreatedDate, CreatedBy.Name, Item__c from News_Item__c order by CreatedDate desc limit 1];
 else
  return [select Name, id, CreatedDate, CreatedBy.Name, Item__c from News_Item__c where id = :ApexPages.currentPage().getParameters().get('id')];
  }
}

 

And this is the test code which runs successfully and claims 100% coverage.

 

@isTest
private class TestNewsController {
    static testMethod void testNewsDisplay() {
        
        News_Item__c[] items = new News_Item__c[] {
            new News_Item__c(Name = 'Headline 1', Item__c = 'News item 1 test text'),
            new News_Item__c(Name = 'Headline 2', Item__c = 'News item 2 test text'),
            new News_Item__c(Name = 'Headline 3', Item__c = 'News item 3 test text'),
            new News_Item__c(Name = 'Headline 4', Item__c = 'News item 3 test text')
        };
        

        insert items;
        
        Test.startTest();
        update items;
        Test.stopTest();
        

    }
}

 

 

But I still get a validate failure when I attempt to deploy it.

 

TBH, I don't really understand what I'm testing for here, as the site all works fine in the sandbox and there isn't any business logic or triggers to test.

 

PS Sorry about the dodgy formatting above - this is a horrible bbs to use!!

Patrick DixonPatrick Dixon

Just to re-itterate, MyProfilePageController.testSave() is not my code, I didn't write it, it's not part of the deployment and I have no idea what it does!!!!

 

Can anyone help please, I'm completely stuck here.

Cory CowgillCory Cowgill

This is an automatically generated class.

 

You can delete the Visualforce Page "MyProfilePage" and then you can delete this controller "MyProfilePageController" if you are not using them.

 

It is a known defect in Winter 11' that the automatically generated test case doesn't always work.

 

http://geekswithblogs.net/sathya/archive/2010/12/02/an-annoying-bug-in-salesforce-winter-11-release-and-how.aspx

Patrick DixonPatrick Dixon

Thanks for the help.

 

Unfortunately I'm a complete newbie and I don't have an IDE account just a free force.com site with a sandbox that I'm trying to get to do something.

 

There's no option to delete "MyProfilePageController" in the 'production site, and I'm not including it in the deployed set from the sandbox so how do I proceed?

 

Cory CowgillCory Cowgill

No problem, this is what this forum is for, newbies. :)

 

You can use the IDE with your regular salesforce account, it is free. You don't need another license or anything like that.

 

1. Download the Force.com IDE (http://wiki.developerforce.com/index.php/Tools)

2. Create a new Force.com Project using your existing login credentials.

3. Follow the previous instructions to delete / deploy.

 

 

Patrick DixonPatrick Dixon

I appreciate the help but is there anyway I can move forward without installing another piece of software that I don't understand?  I don't understand how the IDE will or will not work with what I've done so far, and I'm drowning here already.

Pradeep_NavatarPradeep_Navatar

A Test Class covers more than one Apex Controller so as this error message shows -  "List has no rows for assignment to SObject" it means this test class is trying to cover MyProfilePageController in your current package and in save method it is not getting proper record to execute the method so you need to create proper records that are needed in save method.

Patrick DixonPatrick Dixon

The problem is that MyProfilePageController and its test code is Salesforce's code and is not editable by me.  This is a Salesforce bug in the current offering that has been present for over 2 mths and nobody is doing anything about it!

nathanxlanenathanxlane

I'm having the same problem. No lines of code with ANY reference to MyProfilePageController, simply deleting the MyProfilePageController page did nothing. My site code (both the controller AND the site) are very, very simple and shouldn't have any deployment issues related to this. Very frustrating.

 

 

Patrick DixonPatrick Dixon

There seems no way round this issue - with free force sites I couldn't even delete MyProfilePageController.

 

What I've reluctantly done, is to register for developer sites, install the IDE (I installed Eclipse and then the force plugin because I couldn't get salesforce's IDE to install/run on Windows XP), and then re-create your site from there.  The developer sites have different limitations to the free force sites (I'm still working out what these are), but MyProfilePageController doesn't exist in developer sites and there doesn't seem to be the same insistence on testing that there is in free force sites anyway.

 

This thread gives more help and background with the MyProfilePageController bug:-

http://boards.developerforce.com/t5/Force-com-Sites/Bug-in-SFDC-provided-test-method-for-MyProfilePageController-cls/td-p/209169

but it doesn't seem to be workroundable without the IDE.

 

This seems a steep learning curve, but I've just got a copy of SaleforceHandbook' by Jeff Douglas and Wes Nolte, so hopefully it will provide all the answers I need.

nathanxlanenathanxlane

This is pretty crazy, thanks for the reply.

 

I tried the IDE road, however it won't log into my production platform. I'm left trying to find ways to delete the MyProfile... page/controller some other route. Sadly I wish deleting these two things were easier.

Patrick DixonPatrick Dixon

Yeah, I've had that problem too:-

http://boards.developerforce.com/t5/New-to-Cloud-Development/IDE-won-t-install-on-Win-XP/td-p/236677

 

Make sure you have the password and security token in the login.