• vinothk balasubramanian
  • NEWBIE
  • 0 Points
  • Member since 2015

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

   I don't have much experience in writing the test class as i have written the below code. Can you please write the test class for the below code.
public without sharing class CaseFrecuencyIncidenceCLS {

    public static Id RTMX_REDLTH_CONSUMER_CALL  = null;
    public static Id RTREJC_SERVICE = null;
    private String vDueDay;
    private String vDueTime;
    private double vDueTimeDoub;
    private String vDueTimeDoubl;
    
     private String Classification;
    private map<String,list<Account>> mpCoverDC; //index by Colony
    
       //-----------------------------$$ future method for final case record update : -------
   @future
    public static void updateCaseStatusToAssigned(id caseRecId) {
    system.debug('@@caseRecId@@'+caseRecId);
    Case caseRec = [SELECT id, status, Service_Center__c,Declined_Reason__c, Confirmed_Declined_by__c
                    FROM case
                    WHERE id=: caseRecId];
                    
    if(caseRec.Service_Center__c != null){
    caseRec.status= 'Assigned';
    caseRec.Declined_Reason__c='';
    caseRec.Confirmed_Declined_by__c='';
    
    update caseRec;
    }
    }
    //----------------------------------------------------------------------   
    public void rt(){
        RTMX_REDLTH_CONSUMER_CALL  = getRecordTypeId('Case','MX RedLTH Consumer Call');
        RTREJC_SERVICE = getRecordTypeId('Case','Rejected Service');
    }//rt()
    //----------------------------------------------------------------------
    //Used to get record Type Id
    public Id getRecordTypeId(String objType, String name) {        
        Id RecordTypeId = null;        
        Schema.SObjectType targetType = Schema.getGlobalDescribe().get(objType);
        if (targetType != null) {
            SObject obj = targetType.newSObject();
            Schema.DescribeSObjectResult d = obj.getSObjectType().getDescribe();
            if (d != null) {
                Map<String,Schema.RecordTypeInfo> rtMap = d.getRecordTypeInfosByName();
                if (rtMap != null) {
                    Schema.RecordTypeInfo rtInfo = rtMap.get(name);
                    if (rtInfo != null) {
                        RecordTypeId = rtInfo.getRecordTypeId();
                    }//if
                }//if
            }//if
        }//if
        return RecordTypeId;
    }//getRecordTypeId
    //----------------------------------------------------------------------
    public void updateRelatedContact(list<Case> cases){
        list<Id> lsIDCITY = new list<Id>();
        list<Id> lsIDCOLO = new list<Id>();
        list<Id> lsIDCONT = new list<Id>();
        for(Case c: cases){
            lsIDCITY.add(c.City__c);
            lsIDCOLO.add(c.Colony__c);
            lsIDCONT.add(c.ContactId);
        }//for
        
        map<Id,City__c> mpCITY = new map<Id,City__c>([SELECT Id,Name From City__c where id=:lsIDCITY]);
        map<Id,Colony__c> mpCOLONY = new map<Id,Colony__c>([SELECT Id,Name From Colony__c where id=:lsIDCOLO]);
        map<Id,Contact> mpCONTACT = new map<Id,Contact>([SELECT Id,Name From Contact where id=:lsIDCONT AND MailingCity=null AND MailingState=null]);
        
        for(Case Issue: cases){
            if(mpCONTACT.containsKey(Issue.ContactId)){
                Contact cont = mpCONTACT.get(Issue.ContactId);
                cont.MailingCountry= (Issue.Country__c == null)?'':Issue.Country__c;
                cont.MailingStreet= ((Issue.Street__c == null)?'':Issue.Street__c) + ' ' + ((Issue.Street_number__c == null)?'':Issue.Street_number__c);
                cont.MailingCity= (Issue.City__c == null || !mpCITY.containsKey(Issue.City__c))?'':mpCITY.get(Issue.City__c).Name;
                cont.MailingState= (Issue.State__c == null)?'':Issue.State__c;
                cont.MailingPostalCode= (Issue.Zip_Code__c == null)?'':Issue.Zip_Code__c;
                cont.Colony__c= (Issue.Colony__c == null || !mpCOLONY.containsKey(Issue.Colony__c))?'':mpCOLONY.get(Issue.Colony__c).Name;
                cont.Between_Streets__c= (Issue.Between_Streets__c == null)?'':Issue.Between_Streets__c;
                cont.Reference__c= (Issue.References__c == null)?'':Issue.References__c;
                cont.Place__c= (Issue.Place__c == null)?'':Issue.Place__c;
            }//if
            }//for
        
        if(!mpCONTACT.isEmpty())
            update mpCONTACT.values();
    }//updateRelatedContact
    //----------------------------------------------------------------------      
 
    public void updateFrecuencyIncidence(list<Case> cases){
        searchServiceCenter(cases);
        for(Case c: cases){
            Account center = assignServiceCenter(c.Colony__c);
            if(center.Id != null) {
                c.Service_Center__c=center.Id;
                c.Service_center_email__c=center.E_mail__c;
                c.Status = 'Assigned';
                // Changed value from 'center.AccountID' to 'c.Contact.AccountId' #(Task: , Story:S-266263)
                c.AccountID = c.Contact.AccountId;
                System.debug(' Case Center Id :' + center.Id);
                 System.debug(' Case Service Center :' + c.Service_Center__c);
                  System.debug('Case Service Center email :' + c.Service_center_email__c);
                   System.debug('Case Status :' + c.Status);
               //------Added by Vinoth-----------    
               
                
                //--------------------------------
                
            }
            else {
                c.addError('No existe un Centro de Servicio registrado con cobertura para esta colonia. There is no Service Center Coverage for this Neighborhood');
            }//if
        }//for
    }
    //----------------------------------------------------------------------
    public void searchServiceCenter(list<Case> cases){
        list<Id> lsColony = new list<Id>();
      
        for(Case c: cases){
            lsColony.add(c.Colony__c);
            //lsCity.add(c.City__c);             
            vDueDay = c.Due_Day__c;
            vDueTimeDoub = c.Due_Time__c;
            Classification = c.Classification__c;
            System.debug('vDueTimeDoub :' + vDueTimeDoub);
        }//for
        
        // Get all the 'Service Centers Ids' for this colony that provides 'Home Delivery'
        list<Service_Center_Coverage__c >lsCover = new list<Service_Center_Coverage__c >([Select id,Colony__c,Service_Center__c FROM Service_Center_Coverage__c Where Colony__c=: lsColony
        AND Service_Center__r.RecordType.Name = 'LTH Service Center' and Service_Center__r.Service_Center_Type__c = 'Red LTH SC' and Service_Center__r.Home_delivery_service__c = true]);        
        
        list<Id> lsACC = new list<Id>();
        for(Service_Center_Coverage__c csc :lsCover){
            lsACC.add(csc.Service_Center__c);
            System.debug('* 2. SC Coverage  : '+ csc.id);
        }//for

        
        mpCoverDC = new map<String,list<Account>>();      
        //map<Id,Account> mpAccount ;
        map<Id,Account> mpAccount = new map<Id,Account>();
        // Query for all the Account that provides 'Home Delivery' in this colony

        
        if (vDueDay == 'Saturday' && Classification== 'Home Service - Scheduled')
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Saturday__c <> 'Closed'
              AND Closing_Hours_Saturday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Saturday_Int__c <= :vDueTimeDoub                            
              order by Frecuency__c, Incidence__c]);
        }//vDueDay == 'Saturday'
        else if (vDueDay == 'Sunday' && Classification== 'Home Service - Scheduled')
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Sunday__c <> 'Closed'   
              AND Closing_Hours_Sunday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Sunday_Int__c <= :vDueTimeDoub                            
              order by Frecuency__c, Incidence__c]);            
        }//vDueDay == 'Sunday'
        else if ((vDueDay == 'Monday'
                 || vDueDay == 'Tuesday'
                 || vDueDay == 'Wednesday'  
                 || vDueDay == 'Thursday'
                 || vDueDay == 'Friday') && Classification == 'Home Service - Scheduled' )
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Monday_to_Friday__c <> 'Closed'            
              AND Closing_Hours_Monday_to_Friday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Monday_to_Friday_Int__c <= :vDueTimeDoub                                                                                    
              order by Frecuency__c, Incidence__c]);            
        }//vDueDay == Weekdays
        
         else if (vDueDay == 'Saturday' && Classification == 'Home Service')
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Sunday__c <> 'Closed'   
              AND Closing_Hours_Sunday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Sunday_Int__c <= :vDueTimeDoub                            
              order by Frecuency__c, Incidence__c]);            
        }
        
        else if (vDueDay == 'Sunday' && Classification == 'Home Service')
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Sunday__c <> 'Closed'   
              AND Closing_Hours_Sunday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Sunday_Int__c <= :vDueTimeDoub                            
              order by Frecuency__c, Incidence__c]);            
        }
        
        else if ((vDueDay == 'Monday'
                 || vDueDay == 'Tuesday'
                 || vDueDay == 'Wednesday'  
                 || vDueDay == 'Thursday'
                 || vDueDay == 'Friday') && Classification == 'Home Service' )
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Monday_to_Friday__c <> 'Closed'            
              AND Closing_Hours_Monday_to_Friday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Monday_to_Friday_Int__c <= :vDueTimeDoub                                                                                   
              order by Frecuency__c, Incidence__c]);            
        }
        system.debug('* Service Centers found : ' + mpAccount.keySet());
        
        calculateFrequencyNIncidents(mpAccount.values());

        for(Case c: cases){
            String COLONY = c.Colony__c;
            list<Account> lsTMP = new list<Account>();
            for(Service_Center_Coverage__c csc:lsCover){
                if(csc.Colony__c==COLONY && mpAccount.containsKey(csc.Service_Center__c))
                    lsTMP.add(mpAccount.get(csc.Service_Center__c));
            }//for
            system.debug('lsTMP '+lsTMP);
      
            mpCoverDC.put(COLONY,lsTMP);
        }
    }//searchServiceCenter
    //----------------------------------------------------------------------
    
 
    public map<String,list<Account>> searchServiceCentersforrejected(list<Case> cases){   //$$ method return type changed
        system.debug('##entry into searchServiceCenter ##');
        list<Id> lsColony = new list<Id>();
        list<Id> lsACC = new list<Id>();  //$$
        list<Id> lsAlredyAssignedACC = new list<Id>();  //$$ to hold the already assigned srvc centre ids
        Set<Id> allCaseId = new Set<Id>();
        list<Service_Center_Case_Status__c> allRelatedSrvcCntrCaseStatus = new list<Service_Center_Case_Status__c>(); //$$-----
        Set<Id> allRelatedServiceCenterIds = new Set<Id>();  //$$---------------
      
        for(Case c: cases){
            lsColony.add(c.Colony__c);
            allCaseId.add(c.id);  //$$------------
            //lsCity.add(c.City__c);             
            vDueDay = c.Due_Day__c;
            vDueTimeDoub = c.Due_Time__c;
            //vDueTimeDouble = c.DueTime__c;
            Classification = c.Classification__c;
            System.debug('vDueTimeDoub :' + vDueTimeDoub);
        }//for
        //$$---------------------------------
        system.debug('##allCaseId##'+allCaseId);
        allRelatedSrvcCntrCaseStatus = [SELECT Service_Center__c,Case_Number__c
                                      FROM Service_Center_Case_Status__c
                                      WHERE Case_Number__c in: allCaseId];
        system.debug('##allRelatedSrvcCntrCaseStatus ##'+allRelatedSrvcCntrCaseStatus );
        if(allRelatedSrvcCntrCaseStatus.size()>0)
        {
            for(Service_Center_Case_Status__c sCCSVar: allRelatedSrvcCntrCaseStatus)
            {
                allRelatedServiceCenterIds.add(sCCSVar.Service_Center__c);
             }
         }
         system.debug('##allRelatedServiceCenterIds##'+allRelatedServiceCenterIds);
         //$$----------------------
        // Get all the 'Service Centers Ids' for this colony that provides 'Home Delivery'  //$$-------------
        list<Service_Center_Coverage__c >lsCover = new list<Service_Center_Coverage__c >([Select id,Colony__c,Service_Center__c
                                                                                            FROM Service_Center_Coverage__c
                                                                                            Where Colony__c=: lsColony
                                                                                            AND Service_Center__r.RecordType.Name = 'LTH Service Center'
                                                                                            and Service_Center__r.Service_Center_Type__c = 'Red LTH SC'
                                                                                            and Service_Center__r.Home_delivery_service__c = true
                                                                                            AND Service_Center__r.Id NOT in: allRelatedServiceCenterIds]);        
         system.debug('##lsCover ##'+lsCover );
        if(lsCover.size() > 0)
        {
        lsACC = new list<Id>();
            for(Service_Center_Coverage__c csc :lsCover){
                lsACC.add(csc.Service_Center__c);
                System.debug('## SC Coverage option ##: '+ csc.id);
            }//for
        }// end of if
        else{
          system.debug('## NO SERVICE CENTER AVAILABLE');  
        }
        system.debug('##lsACC ##'+lsACC);
        mpCoverDC = new map<String,list<Account>>();      
        //map<Id,Account> mpAccount ;
        map<Id,Account> mpAccount = new map<Id,Account>();
        // Query for all the Account that provides 'Home Delivery' in this colony

        
        if (vDueDay == 'Saturday' && Classification== 'Home Service - Scheduled')
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Saturday__c <> 'Closed'
              AND Closing_Hours_Saturday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Saturday_Int__c <= :vDueTimeDoub                            
              order by Frecuency__c, Incidence__c]);
        }//vDueDay == 'Saturday'
        else if (vDueDay == 'Sunday' && Classification== 'Home Service - Scheduled')
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Sunday__c <> 'Closed'   
              AND Closing_Hours_Sunday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Sunday_Int__c <= :vDueTimeDoub                            
              order by Frecuency__c, Incidence__c]);            
        }//vDueDay == 'Sunday'
        else if ((vDueDay == 'Monday'
                 || vDueDay == 'Tuesday'
                 || vDueDay == 'Wednesday'  
                 || vDueDay == 'Thursday'
                 || vDueDay == 'Friday') && Classification == 'Home Service - Scheduled' )
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Monday_to_Friday__c <> 'Closed'            
              AND Closing_Hours_Monday_to_Friday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Monday_to_Friday_Int__c <= :vDueTimeDoub                                                                                    
              order by Frecuency__c, Incidence__c]);            
        }//vDueDay == Weekdays
        
         else if (vDueDay == 'Saturday' && Classification == 'Home Service')
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Sunday__c <> 'Closed'   
              AND Closing_Hours_Sunday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Sunday_Int__c <= :vDueTimeDoub                            
              order by Frecuency__c, Incidence__c]);            
        }
        
        else if (vDueDay == 'Sunday' && Classification == 'Home Service')
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Sunday__c <> 'Closed'   
              AND Closing_Hours_Sunday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Sunday_Int__c <= :vDueTimeDoub                            
              order by Frecuency__c, Incidence__c]);            
        }
        
        else if ((vDueDay == 'Monday'
                 || vDueDay == 'Tuesday'
                 || vDueDay == 'Wednesday'  
                 || vDueDay == 'Thursday'
                 || vDueDay == 'Friday') && Classification == 'Home Service' )
        {
            mpAccount
            = new map<id,Account>
            ([Select id, Name, E_mail__c,Frecuency__c, Incidence__c,
              Closing_Hours_Monday_to_Friday__c,Closing_Hours_Saturday__c,Closing_Hours_Sunday__c,
              Opening_Hours_Saturday_Int__c,Opening_Hours_Sunday_Int__c,Opening_Hours_Monday_to_Friday_Int__c
              FROM Account
              Where
              Id =: lsACC
              AND Closing_Hours_Monday_to_Friday__c <> 'Closed'            
              AND Closing_Hours_Monday_to_Friday_Int__c >= :(vDueTimeDoub + 1)
              AND Opening_Hours_Monday_to_Friday_Int__c <= :vDueTimeDoub                                                                                   
              order by Frecuency__c, Incidence__c]);            
        }
        system.debug('* Service Centers found : ' + mpAccount.keySet());
        
        calculateFrequencyNIncidents(mpAccount.values());

        for(Case c: cases){
            String COLONY = c.Colony__c;
            list<Account> lsTMP = new list<Account>();
            for(Service_Center_Coverage__c csc:lsCover){
                if(csc.Colony__c==COLONY && mpAccount.containsKey(csc.Service_Center__c))
                    lsTMP.add(mpAccount.get(csc.Service_Center__c));
            }//for
            system.debug('##lsTMP ##'+lsTMP); //$$------------
           
            system.debug('##lsTMP@@'+lsTMP);  //$$-------------
            mpCoverDC.put(COLONY,lsTMP);
        }
        return mpCoverDC;
    }//searchServiceCentersforrejected
   
 
    //----------------------------------------------------------------------------------------------------------
    private void calculateFrequencyNIncidents(list<Account> Accs){
        Service_Center_Selector__c scs = Service_Center_Selector__c.getInstance(UserInfo.getProfileId()); //Custom Hierarchy settings
        double Incid = (scs==null || scs.Incidents_Range_Days__c ==null )?1:scs.Incidents_Range_Days__c;
        Date d= system.today().addDays(Incid.intValue()*-1);
        System.debug('****Incidence Date****:' +d);
        
       // Changed the RecordType from "Rejected Service" to 'MX RedLTH Consumer Call' and added the Status "Declined" by Vinoth
        AggregateResult[] grpINC = [Select Count(id) TOT,Service_Center__c FROM Case Where Service_Center__c in : Accs and RecordType.Name = 'MX RedLTH Consumer Call' and Status='Declined' and CreatedDate >=: d GROUP BY Service_Center__c];
        map<Id,Integer> mpINCIDENCES = new map<Id,Integer>();
        for(AggregateResult AR: grpINC)
            mpINCIDENCES.put(Id.valueOf(String.valueOf(AR.get('Service_Center__c'))),Integer.valueOf(AR.get('TOT')));
        //FREQUENCY
        double Frec = (scs==null || scs.Frequency_Range_Days__c ==null )?1:scs.Frequency_Range_Days__c;
        d= system.today().addDays(Frec.intValue()*-1);
        System.debug('***Frequency Date****:' +d);
        // Changed the record type from 'Home service' to 'MX RedLTH Consumer Call' #(T-325212)
        AggregateResult[] grpFRC = [Select Count(id) TOT,Service_Center__c FROM Case Where Service_Center__c in : Accs and RecordType.Name = 'MX RedLTH Consumer Call' and Status='Assigned' and CreatedDate >=: d GROUP BY Service_Center__c];
        map<Id,Integer> mpFREQUENCY = new map<Id,Integer>();
        for(AggregateResult AR: grpFRC)
            mpFREQUENCY.put(Id.valueOf(String.valueOf(AR.get('Service_Center__c'))),Integer.valueOf(AR.get('TOT')));
        for(Account A:Accs){
            A.Frecuency__c = (mpFREQUENCY.containsKey(A.Id))?mpFREQUENCY.get(A.Id):0;
            System.debug('****Frequency****:' +A.Frecuency__c );
            A.Incidence__c = (mpINCIDENCES.containsKey(A.Id))?mpINCIDENCES.get(A.Id):0;
            System.debug('****Incidence****:' + A.Incidence__c );
        }//for
    }//calculateFrequencyNIncidents
    //----------------------------------------------------------------------
    public Account assignServiceCenter(String Colony){
        Account center = new Account();
        Boolean assignment = false;
        if(mpCoverDC.containsKey(Colony)){
            list<Account> lsAccount = mpCoverDC.get(Colony);
            for(Account acc : lsAccount){
                if(assignment==false || (acc.Frecuency__c==center.Frecuency__c && acc.Incidence__c<center.Incidence__c) || (acc.Frecuency__c<center.Frecuency__c)){
                   center.Id=acc.Id;
                   center.E_mail__c=acc.E_mail__c;
                   center.Frecuency__c=acc.Frecuency__c;
                   center.Incidence__c=acc.Incidence__c;
                   assignment=true;
                   System.debug('****CenterId****:' + center.Id );
                   System.debug('****CenterEmail****:' + center.E_mail__c );
                   System.debug('****CenterFrequency****:' + center.Frecuency__c );
                   System.debug('****CenterIncidence****:' + center.Incidence__c );
                }//if
            }//for
        }
        //This method is added to update the account record (Task: T-325212)
        if(center != null) {
        updateAccountRecord(center);
        }//if
        return center;
    }//assignServiceCenter  
    
  private void updateAccountRecord(Account cen) {
   
        List<Account> acc =                          
                    [SELECT
                    Id, Frecuency__c, Incidence__c,
                    Opening_Hours_Monday_to_Friday__c,
                    Closing_Hours_Monday_to_Friday__c,
                    Opening_Hours_Saturday__c,
                    Closing_Hours_Saturday__c,
                    Opening_Hours_Sunday__c,
                    Closing_Hours_Sunday__c                 
                    FROM
                    Account
                    WHERE Id =:cen.Id LIMIT 1];
                If (acc.size()>0)
                {
                        if(acc[0].Frecuency__c != null) {
                        acc[0].Frecuency__c++;
                }//if
                else {
                    acc[0].Frecuency__c = 1;
                    
                }
            update acc;
        
                }//If (acc.size()>0)
        
    }//updateAccountRecord
    }

 
Hi All,

Can you please help me in moving unmanaged package and its associated components (object,tab,classes, VF pages) together from one sandbox to another sandbox. Should we use Force.com IDE or ANT for this as i am not able to find package option in change set
Hi All,

    We have the data coming from external application to salesforce where the dates are stored in Julian format in 6 digits in external party application. . Can you please help me to convert this to salesforce date format through formula or workflow rule or Apex code

For ex : Julian date 115054 need to convert to salesforce date format 2/23/2011
Hi,

 I have a requirement to show the 1st Followup due date (which is 3 business days from the service Due date), 2nd Followup date (Which is 6 business days from the Service Due date) and 3rd Followup due date which is 10 business days from the service Due date and the service due date which is set when the Followup status is set to "Received by Service"

  So i created formula field for the service Due date and workflow rules for 1st,2nd and 3rd Followup date and everything is working fine

  Now the latest requirement is they don't want the below days to count against the calculation of 1st,2nd and 3rd Followup due dates. Here is a list of this years:

February 16,May 25,July 3,September 7,November 26,November 27,December 25

Can you please help me how we should not count the above days for the below calculation

Giving the calculation of 1st Followup due date for your reference

CASE(
MOD( DATEVALUE(Service_Due_bye__c) - DATE( 1900, 1, 7 ), 7 ),
3, DATEVALUE(Service_Due_bye__c) + 5,
4, DATEVALUE(Service_Due_bye__c) + 5,
5, DATEVALUE(Service_Due_bye__c) + 5,
6, DATEVALUE(Service_Due_bye__c) + 4,
0, DATEVALUE(Service_Due_bye__c) + 3,
1, DATEVALUE(Service_Due_bye__c) + 3,
2, DATEVALUE(Service_Due_bye__c) + 3,
null
)


 
I have an workflow on Opportunity that needs to trigger everytime its created.
The criteria is based on a formula field(Account.name) -- Formula_field__c contains 'TEXT', trigger the workflow.
This Workflow does bunch of field updates

The problem is, the workflow is not triggerring some times eventhough it meets the criteria.
Note: I am creating the Opportunity using lead conversion.

I got issues with Data integrity because of the Issue
  • December 29, 2015
  • Like
  • 0