• Cornelia Winn 3
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello,

I'd like to convert this trigger to an APEX class so I can call it via the process builder. Any suggestions?


trigger SFDCALC on Service_to_Claim__c (before insert, before update) {
    
    for(Service_to_Claim__c sc : Trigger.new) {
        
        List<Service_to_Claim__c> service_to_claim = [SELECT 
                                                      CPL_Amount__c, 
                                                      CPL_Letter_Receipt_Date__c, 
                                                      Date_CPL_Issued__c, 
                                                      CPN_Amount__c, 
                                                      CPN_Letter_Receipt_Date__c, 
                                                      Date_CPN_Issued__c, 
                                                      Final_Demand_Amount__c, 
                                                      Final_Demand_Received__c,
                                                      Date_Final_Demand_Issued__c,
                                                      Final_Demand_Dispute_Amt__c,
                                                      Final_Demand_Dispute_Received__c,
                                                      Final_Demand_Dispute_Issued__c,
                                                      Refreshed_CP_Amount__c,
                                                      Refreshed_CP_Date__c,
                                                      CPL_CPN_Dispute_Adjusted_Amount__c,
                                                      CPL_CPN_Dispute_Response_Date__c,
                                                      CPL_CPN_Dispute_Issued__c,                                                        
                                                      CPL_Rec_d_w_Claim_Amt__c,
                                                      CPL_Rec_d_w_Claim_Date__c
                                                      FROM Service_to_Claim__c 
                                                      WHERE Claim__c=:sc.Claim__c
                                                      AND id != :sc.Id];        

                                                      
        List<Decimal> amount = new List<Decimal>();
        List<Date> dt = new List<Date>();
        /****Start of adding old records of servcie to claim******/
        for(Service_to_Claim__c stc : service_to_claim){
            amount.add(stc.Final_Demand_Amount__c);

                dt.add(stc.Date_Final_Demand_Issued__c);
            
            
            amount.add(stc.Final_Demand_Dispute_Amt__c);
                dt.add(stc.Final_Demand_Dispute_Issued__c);
            

        }
        /****End of adding old records of servcie to claim******/
        /********Strat adding the current service to claim record value*******/
        
        amount.add(sc.Final_Demand_Amount__c);
             dt.add(sc.Date_Final_Demand_Issued__c);
        
        
        amount.add(sc.Final_Demand_Dispute_Amt__c);
            dt.add(sc.Final_Demand_Dispute_Issued__c);
        
        

        /********End of adding the current record of service to claim**********/
        
        integer index;
        Decimal FinalDemandAmount_AcuityCIC  = amount.get(0);
        Date FDA_Acuity_CIC_Date = dt.get(0);
        system.debug('::index::'+index);
        system.debug('::FinalDemandAmount_AcuityCIC::'+FinalDemandAmount_AcuityCIC);
        system.debug('::FDA_Acuity_CIC_Date::'+FDA_Acuity_CIC_Date);
        for(index = 0; index<amount.size(); index++){
            /****check if there is null value in FDA_Acuity_CIC_Date ***/
            if(dt[index]!=null && FDA_Acuity_CIC_Date == null){
                FDA_Acuity_CIC_Date = dt[index];
                FinalDemandAmount_AcuityCIC = amount[index];
            }
            
            /****compare the recent capture date calculation****/
            if(dt[index] >= FDA_Acuity_CIC_Date){
                if(dt[index] > FDA_Acuity_CIC_Date){
                    FinalDemandAmount_AcuityCIC = amount[index];
                } else {
                    if(amount[index] != null){
                        if(FinalDemandAmount_AcuityCIC == null || FinalDemandAmount_AcuityCIC > amount[index]){
                            FinalDemandAmount_AcuityCIC = amount[index];   
                        }  
                    }
                    
                } 
                FDA_Acuity_CIC_Date = dt[index]; 
            } 
            
            system.debug('::index::'+index);
            system.debug('::FinalDemandAmount_AcuityCIC::'+FinalDemandAmount_AcuityCIC);
            system.debug('::FDA_Acuity_CIC_Date::'+FDA_Acuity_CIC_Date);
        }
        
        update new Claim__c(
            id = sc.Claim__c,
            FDA_Acuity_CIC_Date__c = FDA_Acuity_CIC_Date,
            FinalDemandAmount_AcuityCIC__c = FinalDemandAmount_AcuityCIC
        );
        
        
    }
}
Hello!

I have a Process which starts only when a record is created. Example of process: http://www.screencast.com/t/5okrck1Or
Time-dependent action is configured, which is sending out an email before object overdue date. Everything works fine, except of: scheduled action is executed in spite of conditions are met or not. E.g. criteria for Executing Actions is set to Object Status Equal to "Not Paid". If object status is changed to e.g. "Paid" before scheduled actions, it is still sending out an email. 

Process configuration seems to be fine...or should I start the process when a record is created or edited + "Do you want to execute the actions only when specified changes are made to the record?" set to YES ? 

From documentation:
"Time-dependent actions remain in the workflow queue only as long as the workflow rule criteria are still valid. If a record no longer matches the rule criteria, Salesforce removes the time-dependent actions queued for that record.
For example, an opportunity workflow rule can specify:A criteria set to “Opportunity: Status not equals to Closed Won, Closed Lost”
An associated time-dependent action with a time trigger set to 7 days before the opportunity close date
If a record that matches the criteria is created on July 1 and the Close Date is set to July 30, the time-dependent action is scheduled for July 23. However, if the opportunity is set to “Closed Won” or “Closed Lost” before July 23, the time-dependent action is removed from the queue."

Thanks a lot in advance.