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
Andrew NorthAndrew North 

Errors when publishing Apex Class from Sandbox to Prduction

Hi Guys, I really hope you can help

I'm attampting to push a change (2 apex classes) from my 'Config' sandbox to the production environment.

However, when i push my change I get 2 errors, as I'm not a Salesforce developer I'm having a hard time resolving these issues.

The Code is as follows

1)
@isTest
private class BW_RevenueScheduleBatchTest{
        static testMethod void testBW_RevenueScheduleBatch(){
                Profile p;
                User u;
                Account parentAcc;

                Account acc;
                Opportunity opp;
                Profit_Centre_Split__c secondaryPcs;
                Framework__c fw;
                Sector_Head_Mappings__c sectorHeadCS;
                p = TestData.createProfile();

                u = TestData.createTestUser(p);
                                TestData.u=u;
                parentAcc=TestData.createAccount();
                sectorHeadCS = TestData.createSectorCustomSetting(u);

                acc = TestData.createAccount(parentAcc);
                fw =  TestData.createFrameWork(acc);
                opp = TestData.createOpportunity(acc.id,fw.id);
                opp.Legacy_Source_System__c='Capsule';
                update opp;
                secondaryPcs = TestData.createSecondaryProfitCentre(opp);

                    database.executeBatch(new BW_RevenueScheduleBatch());
        }
}

 



2)
@isTest (seeAllData = true) 
public class HomePageReportControllerTest{ 

static testMethod void testHomePageReportcontroller(){         
TestData.createAll();          

System.runAs(TestData.u){  
//create an opp closing in the future...
Opportunity o = TestData.createOpportunity(TestData.acc.Id, TestData.fw.Id);            o.closeDate = system.today().addDays(5);
o.Contract_start_date__c = System.today().addDays(5);            o.Latest_status_and_next_steps__c = 'updated date';
update o;       

 PageReference pageRef = Page.MyRecentDashboard;           Test.setCurrentPage(pageRef);           
HomePageReportController hprc = new HomePageReportcontroller();           system.assert(hprc.pipelineReportId != null);           system.assert(hprc.revenueReportId != null);           system.assert(hprc.winlossReportId != null);                   
 }             
 } 
}



The errors I receive are below

1) System.DmlException: Upsert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityTrigger: execution of AfterUpdate caused by: System.AsyncException: Future method cannot be called from a future or batch method: SubscriberHelper.evaluateOpptyRulesFuture(Set<Id>) Trigger.OpportunityTrigger: line 29, column 1: []
Stack Trace: Class.BW_RevenueScheduleBatch.execute: line 44, column 1

2) System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.HomePageReportController.getReportId: line 18, column 1 Class.HomePageReportController.<init>: line 10, column 1 Class.HomePageReportControllerTest.testHomePageReportcontroller: line 17, column 1

If anyone could kindly advise or point me in the right direction of how this can be resolved I would be extremely grateful.

Thank you
AnudeepAnudeep (Salesforce Developers) 
Hi Andrew,
  1. I don't have visibility to your trigger so I can't comment on what exactly is happening. However, you will see such errors when attempting to call a Future method from a future or batch method. As per this documentation "You cannot call a method annotated with future from a method that also has the future annotation. Nor can you call a trigger from an annotated method that calls another annotated method"
  2. The error "List has no rows for assignment to SObject" occurs when your query doesn't return any rows. I recommend doing a list size check/null check in your HomePageReportController.getReportId method. See Apex error 'List has no rows for assignment to SObject' to learn more
Anudeep
Agustin BAgustin B
Hi Andrew, you will need a SF developer for this.
1) You cant call a future from another future as this generates a loop and that is no good. You should have a SF developer checking the batch and the trigger to make the changes needed to avoid this.
2) Make sure you have records for all the objects you are querying on that test. I see you are using seeAllData= true, that is not the best practice, the ideal would be to make that false and create all your test data in that test class (If you can get a SF developer for point 1, make him see this as well).If you want to solve it then make sure your production environment has the records created needed for this test.

if it helps please like and mark as correct, as it may help others.
Good luck.