Skip to main content
Gaurav Khare が「#Apex」で質問
Hi , My entire application works on Opportunity history data (all batches) , There are cases like opportunites close dates changed in current month or previous month and much like this, evaluating previous one year data. I can create oppoturinity but I need its history in previous periods as well for traversing various of my If and else conditions, This seems next to impossible, I cannot use seeAllData=true, as it is a package and when installed on other system may fail. What can be the hack here?

 

Any help would be appreciated!!!
11 件の回答
  1. 2020年10月26日 17:44
    Please try code like this:

    Opportunity opportunity_Obj = new Opportunity(IsPrivate = false, Name = 'Name144',Account_Record_Type__c = 'Tenant', Property_Name_Text__c = 'ogcp', StageName = 'Exchanging Proposals', CloseDate = Date.today(), Budget_Confirmed__c = false, Discovery_Completed__c = false, ROI_Analysis_Completed__c = false, Additional_Approval_Required__c = false, Deal_Submitted_for_Approval__c = false, Deal_Type__c = 'New Lease', Leasing_Property_Lead__c = user_id, Property__c = propertyObj_Id, Has_Options__c = false, Highest_Active_Deal__c = false);

            Insert opportunity_Obj;

            opportunity opp=[select id,StageName from Opportunity where id=:opportunity_Obj.Id];

            opp.StageName='Fully Executed Lease';

            update opp;

    Test.startTest();

    OpportunityFieldHistory coh = new OpportunityFieldHistory(OpportunityId = opp.id, Field = 'StageName'); 

            insert coh; 

            String Query='SELECT id,OpportunityId,CreatedDate,oldValue,NewValue,Field from OpportunityFieldHistory';            

            ESRT_SendNotificationsOrEmailsBatch obj=new ESRT_SendNotificationsOrEmailsBatch(Query);

            DataBase.executeBatch(obj,100);

    Test.stopTest();

     
0/9000