• Shobana Ravichandran
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hi,

my requirement is to create a payment reminder to customer when their credit term is 30, they should be notified 5th of the month and if credit term is 35, they should be notified 10th of the month. how can i acheive.
please help me on this.
 
global with sharing class DebtCollection implements Schedulable 
{
    /
    global void execute(SchedulableContext sc)
    {
        createDebtCollectionCases();
        updateAccounts();
        updateCasesToDemand();
        //sendReminderEmails(AccountsRequiringReminder());
    }
    private static void createDebtCollectionCases(){
        try{
           insert casesToCreate(AccountsRequiringDebtCase());
        }catch(Exception e){
            
        }
    }
    
   private static void updateAccounts()
    {
        List<Account> accsToUpdate = AccountsRequiringDebtCase();
        for(Account acc : accsToUpdate){
            acc.Has_Open_Debt_Case__c = TRUE;
        }
        try {
            update accsToUpdate;
        }catch(Exception e){
            
        }
    }
      
    private static void updateCasesToDemand()
    {
        try {
            update casesToUpdate(CasesRequiringDemand());
        }catch(Exception e){
            
        }
    }
    
    
    public static List<Account> AccountsRequiringDebtCase()
    {   
        //Accounts with credit term of 30 have their 60 day balance checked on the 2nd of each month
        Integer creditTermDate30 = 2;
        //Accounts with credit term of 35 have their 60 day balance checked on the 7th of each month
        Integer creditTermDate35 = 7;
        //Accounts with credit term of 45 have their 60 day balance checked on the 17th of each month
        Integer creditTermDate45 = 17;
        List<Account> accList = new List<Account>();
        if(Date.today().Day()==creditTermDate30){
            accList.add([
                select Id, Has_Open_Debt_Case__c, Most_Recent_Statement_Date__c 
                from Account where
                Has_Open_Debt_Case__c = FALSE and
                Day_60_Balance__c > 0 and Credit_Terms__c = 30
                ]);  
            system.debug('accList' +accList);
        }
        if(Date.today().Day()==creditTermDate35){
            accList.add([
                select Id, Has_Open_Debt_Case__c, Most_Recent_Statement_Date__c 
                from Account where
                Has_Open_Debt_Case__c = FALSE and
                Day_60_Balance__c > 0 and Credit_Terms__c = 35
            ]);  
        }
        if(Date.today().Day()==creditTermDate45){
            accList.add([
                select Id, Has_Open_Debt_Case__c, Most_Recent_Statement_Date__c 
                from Account where
                Has_Open_Debt_Case__c = FALSE and
                Day_60_Balance__c > 0 and Credit_Terms__c = 45
             ]);  
        }
         accList.add([
            select Id, Has_Open_Debt_Case__c, Most_Recent_Statement_Date__c 
            from Account where
            Has_Open_Debt_Case__c = FALSE and
            credit_hold_date__c != null and (Day_60_Balance__c >0 OR Day_90_Balance__c>0)
                
       ]); 
        
        

     return  accList;
        
    }
    
    
    public static List<Case> CasesRequiringDemand()
    {   
        
        Date demandDay = Date.today().addDays(-30);
        Id DebtRecordType = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Debt Collection').getRecordTypeId();
        
        List<Case> caseList = [
            select Id, Status 
            from Case where
            Status != 'Closed' AND recordTypeId = :DebtRecordType AND createddate  = :demandDay
         ];
        
        return  caseList;
        
    }
    
    
    private static List<Case> casesToCreate(list<Account> accounts)
   {
         List<Case> returnList = new list<Case>();
         Id devRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Debt Collection').getRecordTypeId();
         List<Group> queueId = [select Id from Group where Name = 'Finance Queue' and Type = 'Queue'  ];
        
        
        
         if(!accounts.isEmpty())
         {
             for(Account acc: accounts)
             {
                 Case newCase = new Case();
                 newCase.AccountId = acc.id;
                 newCase.RecordTypeId = devRecordTypeId;
                 newCase.ownerId = queueId[0].id;
                 returnList.add(newCase);
             }
         }
        
         return returnList;
    }
    
    
   private static List<Case> casesToUpdate(list<Case> cases)
    {
        if(!cases.isEmpty())
        {
            for(Case c: cases)
            {
                c.Status = 'Demand';
            }
       }
        
        return cases;
    }
i am getting List has more than 1 row for assignment to SObject error when schduling the job.

please some one help me on this.
Hi,

my requirement is to create a payment reminder to customer when their credit term is 30, they should be notified 5th of the month and if credit term is 35, they should be notified 10th of the month. how can i acheive.
please help me on this.
 
global with sharing class DebtCollection implements Schedulable 
{
    /
    global void execute(SchedulableContext sc)
    {
        createDebtCollectionCases();
        updateAccounts();
        updateCasesToDemand();
        //sendReminderEmails(AccountsRequiringReminder());
    }
    private static void createDebtCollectionCases(){
        try{
           insert casesToCreate(AccountsRequiringDebtCase());
        }catch(Exception e){
            
        }
    }
    
   private static void updateAccounts()
    {
        List<Account> accsToUpdate = AccountsRequiringDebtCase();
        for(Account acc : accsToUpdate){
            acc.Has_Open_Debt_Case__c = TRUE;
        }
        try {
            update accsToUpdate;
        }catch(Exception e){
            
        }
    }
      
    private static void updateCasesToDemand()
    {
        try {
            update casesToUpdate(CasesRequiringDemand());
        }catch(Exception e){
            
        }
    }
    
    
    public static List<Account> AccountsRequiringDebtCase()
    {   
        //Accounts with credit term of 30 have their 60 day balance checked on the 2nd of each month
        Integer creditTermDate30 = 2;
        //Accounts with credit term of 35 have their 60 day balance checked on the 7th of each month
        Integer creditTermDate35 = 7;
        //Accounts with credit term of 45 have their 60 day balance checked on the 17th of each month
        Integer creditTermDate45 = 17;
        List<Account> accList = new List<Account>();
        if(Date.today().Day()==creditTermDate30){
            accList.add([
                select Id, Has_Open_Debt_Case__c, Most_Recent_Statement_Date__c 
                from Account where
                Has_Open_Debt_Case__c = FALSE and
                Day_60_Balance__c > 0 and Credit_Terms__c = 30
                ]);  
            system.debug('accList' +accList);
        }
        if(Date.today().Day()==creditTermDate35){
            accList.add([
                select Id, Has_Open_Debt_Case__c, Most_Recent_Statement_Date__c 
                from Account where
                Has_Open_Debt_Case__c = FALSE and
                Day_60_Balance__c > 0 and Credit_Terms__c = 35
            ]);  
        }
        if(Date.today().Day()==creditTermDate45){
            accList.add([
                select Id, Has_Open_Debt_Case__c, Most_Recent_Statement_Date__c 
                from Account where
                Has_Open_Debt_Case__c = FALSE and
                Day_60_Balance__c > 0 and Credit_Terms__c = 45
             ]);  
        }
         accList.add([
            select Id, Has_Open_Debt_Case__c, Most_Recent_Statement_Date__c 
            from Account where
            Has_Open_Debt_Case__c = FALSE and
            credit_hold_date__c != null and (Day_60_Balance__c >0 OR Day_90_Balance__c>0)
                
       ]); 
        
        

     return  accList;
        
    }
    
    
    public static List<Case> CasesRequiringDemand()
    {   
        
        Date demandDay = Date.today().addDays(-30);
        Id DebtRecordType = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Debt Collection').getRecordTypeId();
        
        List<Case> caseList = [
            select Id, Status 
            from Case where
            Status != 'Closed' AND recordTypeId = :DebtRecordType AND createddate  = :demandDay
         ];
        
        return  caseList;
        
    }
    
    
    private static List<Case> casesToCreate(list<Account> accounts)
   {
         List<Case> returnList = new list<Case>();
         Id devRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Debt Collection').getRecordTypeId();
         List<Group> queueId = [select Id from Group where Name = 'Finance Queue' and Type = 'Queue'  ];
        
        
        
         if(!accounts.isEmpty())
         {
             for(Account acc: accounts)
             {
                 Case newCase = new Case();
                 newCase.AccountId = acc.id;
                 newCase.RecordTypeId = devRecordTypeId;
                 newCase.ownerId = queueId[0].id;
                 returnList.add(newCase);
             }
         }
        
         return returnList;
    }
    
    
   private static List<Case> casesToUpdate(list<Case> cases)
    {
        if(!cases.isEmpty())
        {
            for(Case c: cases)
            {
                c.Status = 'Demand';
            }
       }
        
        return cases;
    }
i am getting List has more than 1 row for assignment to SObject error when schduling the job.

please some one help me on this.