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

New Apex Class won't deploy to production

Hi All,


I am creating a new apex class in sandbox for use with a site.  I created an extension of the lead controller so that the web-to-lead form redirects to a thank you page instead of the default SF page.  My apex code is:



public class myWeb2LeadExtension {

    private final Lead weblead;

    public myWeb2LeadExtension(ApexPages.StandardController stdController) {
       weblead = (Lead)stdController.getRecord();
     public PageReference saveLead() {
       try {
       catch(System.DMLException e) {
           return null;
       PageReference p = Page.ThankYou;
       return p;



I am getting the following error when I go to deploy it to production.


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


Thanks in advance for your help!


Cory CowgillCory Cowgill

This error is seen most often when you are doing a SOQL query and putting the result into an SObject and there are no results.


For example, if I query for Account like this:


Account testAccount = [Select Id, Name from Account where Name = 'NotFound' limit 1];


And there is no Account named 'NotFound', it will throw this error:


System.QueryException: List has no rows for assignment to SObject


Since this is occuring in production deployment, you should review your UnitTest Method to ensure you are setting up your test data appropriately. Most likely your test method is relying on data already existing in your Org. Your test methods should always setup all the test data you need and not rely on existing test data in the org.


Have you enabled Sites for your org?


I think this may be a bug with the MyProfilePageController class that is deployed when you enable Sites. 




Prafulla PatilPrafulla Patil

check this to avoid error like this Link