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
Topher ReynoldsTopher Reynolds 

Using the class below, I can't seem to get the DB updated. There are no errors being thrown, but update is not updating the deal from the unit test. Is there something wrong with this code?

public class Set45DayDeadlineFor1031Deal {
    // This method is called by the Set45DayDeadline process
    @InvocableMethod
    public static void SetDeadline(List<Id> X1031_DealsIds)
    {
        List<X1031_Deals__c> deals = new List<X1031_Deals__c>();
            for(Id dealId : X1031_DealsIds){
                // Query down to the children records (Property) filtered by Property Type = relinquished.  
                // Out of remaining properties grab the_ +*_earliest_*+ *_“Relinquish Final Close of Escrow” date._*
                // This date will then have 45 days added to it and will be placed in the 1031 Deal Object’s *45 Day Deadline*
                List<Property__c> properties = [SELECT Id, Name, Relinquish_Final_Close_of_Escrow__c, X1031_Deal__c
                    FROM Property__c WHERE X1031_Deal__c = :dealId AND Property_Type__c = 'Relinquished'];

                X1031_Deals__c deal = [SELECT Id, Name, X45_Day_Deadline__c, X1031_Client__c 
                    FROM X1031_Deals__c WHERE Id = :dealId][0];

                if(properties.size() > 0){
                    // A default date to change
                    Date deadline = Date.newInstance(2099, 1, 1);

                    for(Property__c prop : properties){
                        Date propDate = prop.Relinquish_Final_Close_of_Escrow__c;
                        if(propDate < deadLine){
                            deadline = propDate;
                        }
                    }
                    
                    deals.add(new X1031_Deals__c(Name='tested', X1031_Client__c=deal.X1031_Client__c));

                    deal.Id = dealId;
                    deal.X45_Day_Deadline__c = deadline.addDays(45);
                    deals.add(deal);

                    System.debug(deal.X45_Day_Deadline__c);
                    System.debug('Deals size is: ' + deals.size());
                }
            }

        if(deals.size() > 0){
            List<Database.SaveResult> results = Database.update(deals, false);
            for(Database.SaveResult result : results){
                if(!result.isSuccess()){
                    for(Database.Error err : result.getErrors()){
                        System.debug('Error: ' + err.getStatusCode() + ' ' + err.getMessage());
                    }
                }
            }
        }
    }
}

 
Herish SurendranHerish Surendran
Once the Unit test is completed, all changes (DML statements) made by unit tests are rolled back.