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
Justin St GermainJustin St Germain 

Problem deploying through Deploy tool in Salesforce

I keep getting the following error, and am not sure why. The Apex class I created works in Sadbox and uploads for deployment without an issue, but it fails when I go to "Inbound Change Sents" and try to deploy the new class...

ERROR:
Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Student_Master.ApplicationMasterTrigger: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject (Student_Master): []", Failure Stack Trace: "Class.App...


Best Answer chosen by Justin St Germain
Saurabh DhobleSaurabh Dhoble
Right, so it looks like the test case AppTrackerTestSuite is the problem. I'd suggest you throw this at the guy who originally wrote this class, don't try to troubleshoot it yourself. If this is part of a package, consider uninstalling the package so that you can deploy your stuff.

All Answers

Justin St GermainJustin St Germain
Below is a screen shot of the error log, if it is any help...

User-added image
Saurabh DhobleSaurabh Dhoble
This is a programming bug. It looks like you are creating a trigger (or a class being used in a trigger), and your Student_Master list does not have any data.
Go through your code again, there's definitely a bug there. Also would help if you clearly state what is going in as part of the change set.
Justin St GermainJustin St Germain
Saurabh,
I am not sure what that means exactly. I created an Apex controller class and a page, but was only trying to deploy the class cause I can create the page in production and I didnt see a way to roll it into the deploy... here is the code for the controller...

// AutoCompleteController.cls
public with sharing class AutoCompleteController {
    
    // Instance fields
    public String searchTerm {get; set;}
    public String selectedSchool {get; set;}
    
    // JS Remoting action called when searching for a school name
    @RemoteAction
    public static List<Account> searchSchool(String searchTerm) {
        System.debug('School Name is: '+searchTerm );
        List<Account> schools = Database.query('SELECT Name, BillingCity, BillingState FROM Account WHERE Name LIKE \'%' + String.escapeSingleQuotes(searchTerm) + '%\'');
        return schools;
    }
    
}

So, I dont know how I would be calling anything to do with Student_Master. Below is the Apex page I created that uses the controller...

<apex:page controller="AutoCompleteController" >
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" />
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js" />
    <apex:styleSheet value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" />
    
    <style>
        .displayNone { 
            display:none; 
        }
        .displayBlock {
            display:block;
        }
        .ui-autocomplete-loading { 
            background: white url(/img/loading32.gif) right center no-repeat;
            background-size:15px 15px; 
        }
        .placeHolder {
            font-style: italic;
        }
    </style>
    
    <apex:form id="autoCompleteForm" >
        
        <apex:pageBlock id="searchBlock" >
            <apex:pageBlockSection id="searchSection" title="Locate my high school" columns="1" >
                 <apex:outputLabel value="School Name" for="schoolBox" />
                 <apex:outputPanel >
                     <apex:inputText id="schoolTextBox" value="{!searchTerm}" styleClass="placeHolder"/>
                     <apex:inputHidden id="searchSchoolId" value="{!selectedSchool}" />
                 </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlock>
        
    </apex:form>
    
    <script type="text/javascript">
        var PLACEHOLDER = 'Enter School Name Here'; 
        var schoolObjects;
        var queryTerm;
        
        $('[id$=schoolTextBox]').autocomplete({
            minLength: 2,
            source: function(request, response) {
                        queryTerm = request.term;
                        AutoCompleteController.searchSchool(request.term, function(result, event){
                            if(event.type == 'exception') {
                                  alert(event.message);
                            } else {
                                 schoolObjects = result;
                                 response(schoolObjects);
                            }
                        });
                   },
            focus: function( event, ui ) {
                    $('[id$=schoolTextBox]').val( ui.item.Name );
                    return false;
                    },
            select: function( event, ui ) {
                        $('[id$=schoolTextBox]').val( ui.item.Name );
                        $('[id$=searchSchoolId]').val( ui.item.Id );
                        return false;
                    },
         })
         .data( "autocomplete" )._renderItem = function( ul, item ) {
            var entry = "<a>" + item.Name;
           
            entry = entry + "</a>";
            entry = entry.replace(queryTerm, "<b>" + queryTerm + "</b>");
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( entry )
                .appendTo( ul );
        };
            
        // Add or remove placeholder values
        $('[id$=schoolTextBox]').val(PLACEHOLDER);
        $('[id$=schoolTextBox]').on("focus",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === PLACEHOLDER ){
                $tgt.val('');
                $tgt.removeClass('placeHolder');
            }
        });
        $('[id$=schoolTextBox]').on( "blur",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === '' ){
                $tgt.val(PLACEHOLDER);
                $tgt.addClass('placeHolder');
            }
        });
    </script>

</apex:page>

Thanks for your help, I hope you are able to help more.
Saurabh DhobleSaurabh Dhoble
There are multiple things here -
A. You cannot create the visualforce page in production (only in sandboxes).
B. You should be able to add the VF page to the changeset - just select type "Visualforce Page" from the drop down when creating the changeset.

The cause for your misery seems to be coming from the tests - when you deploy changesets with code to production, Salesforce runs all the test cases in your org. Looks like one of you test cases is bombing - it would help if you could paste the entire stack trace of the error.
Justin St GermainJustin St Germain
I am unsure why you say I cant create a page in production. I have development turned on, and i can go to http://salesforceinstance.com/apex/PageName and create a page, and the error doesnt mention needing the page to deploy the controller. I however couldnt create the controller class in production, and is why I did it in Sandbox. But, still new to salesforce, so a bit confused to how this all works. (I am a PHP/MySQL guy and also do front end dev) If you could tell me how to get you the entire stack, I would be happy to post it to see if that will help.
Justin St GermainJustin St Germain
any other suggestions?
Saurabh DhobleSaurabh Dhoble
Sorry, tied up with stuff, will look at it tomorrow.
Justin St GermainJustin St Germain
no worries. thanks for your help. i really appreciate it.
Justin St GermainJustin St Germain
I tried to re-submit the deployment again this morning after sending the errors to the other dev team that has created all the other custom stuff for the site hoping they would have fixed the issues, no success, same errors occuring. If anyone has a moment to tell me how I can get the stack trace, it would be greatly appreciated. That way I may be able to pinpoint the issue so that I can let them know what needs to be fixed. Thanks in advance.
Saurabh DhobleSaurabh Dhoble
a. In Salesforce, go to Setup --> Develop --> Apex Test Execution
b. Click the "Select Tests" button - select all the classes in the window that comes up.
c. Hit "Run"

This will run all your tests. Wait for completion and check if any of the classes have failed.

Also, what else are you trying to deploy as part of your deployment. Any custom objects, or other classes etc. ?
Justin St GermainJustin St Germain
Below is a screen shot of the tests.

The only thing I myself am trying to deplow is the Apex class that I posted above for the Auto Complete.

User-added image
Saurabh DhobleSaurabh Dhoble
When you try to deploy a class to Salesforce production, Salesforce will always run *all* the test cases in your production environment. If any of the test cases fail, it will abort and rollback the entire deployment.
In your case, this is what seems to be happening. The AppTrackerTestSuite test case is failing, which is preventing you from deploying your class (even though the two are unrelated).

Click on "View" next to AppTrackerTestSuite, and check the stack trace. If this is what is causing deployment to fail, you should be able to find the error you are getting in it's stack trace.

Let me know.
Justin St GermainJustin St Germain
For the 4 errors that get thrown when I try to deploy, they are all related to the same call. Below is an image of the errors, and when I look at the source, it is for "insert app;" (no quotes)

User-added image
Justin St GermainJustin St Germain
more details...

// Create Application
        TargetX_SRMb__Application__c app = new TargetX_SRMb__Application__c(TargetX_SRMb__Contact__c = con.id);
        insert app;

that is the same code for each error
Saurabh DhobleSaurabh Dhoble
Right, so it looks like the test case AppTrackerTestSuite is the problem. I'd suggest you throw this at the guy who originally wrote this class, don't try to troubleshoot it yourself. If this is part of a package, consider uninstalling the package so that you can deploy your stuff.
This was selected as the best answer
Saurabh DhobleSaurabh Dhoble
Another thing that I can recommend, if you have access to the test class that is failing - comment out the entire test method that is failing and deploy the AppTrackerTestSuite class. Once the failing code is commented out and the test is succeeding, you can then deploy your stuff.
Justin St GermainJustin St Germain
I think I will let this problem rest on their shoulders for now, but I may have to do that if they dont do something soon.

A question you may have an answer for...
If salesforce runs test cases EACH time that someone deploys, how would it have been deployed prior to me having issues? Does using Eclipse or something other than the salesforce deploy tool bypass the testing?
Saurabh DhobleSaurabh Dhoble
Salesforce runs the test cases each time someone deploys any code (classes, triggers, visualforce). However, it does not run tests when you make configuration changes. So what ends up happening is that someone puts a new validation rule on an object, or adds a new formula field, or changes the data type on an existing field without running the tests, and all that goes through fine. THEN, on production release date, when you try to deploy your class, boom, the test cases fail and you have to scramble to fix them.

I know it's frustrating, but that's part of the Salesforce development cycle.
Justin St GermainJustin St Germain
haha, makes sence. had things like that happen when I used to do Java. Thanks. Appreciate the help. I will send over the erros again to the other dev team and go from there. You have been very helpful.
Saurabh DhobleSaurabh Dhoble
Cool. Keep posting.
BTW, if this has answered your question, please mark this as answer so I can earn some points :) TC.