• Laaral
  • NEWBIE
  • 55 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 36
    Questions
  • 48
    Replies
Hi, I have a problem with my formula which should count End Date from Start Date + Contract Term, but the problem is that Contract Term values are not always divisible by 12? For example (37 or 41) .

Here is my formula before I found out that all the values aren't divisible by 12:

DATE(
(YEAR(Service_Contract_Period_Start_Date__c)+VALUE(TEXT(Service_Contract_Term__c ))/12),
MONTH(Service_Contract_Period_Start_Date__c),
DAY(Service_Contract_Period_Start_Date__c)
)

How should I solve this ?
Hi, I need to do a workflow (or validation rule I'm not sure which one to use) and it should do this "Setup status can be saved as "Cancelled" only if prior value has been "In delivery".
But when I do it like this the first Error goes : Extra " , " then when I take it off it says "Extra Pickval" 

AND(ISCHANGED(Setup_Status__c), "Cancelled"),
ISPICKVAL(PRIORVALUE(Setup_Status__c), "In Delivery"))

What would be a better solution for this?
Hi,

I have a problem with my formula, idea is that start date(date field) + contract term (picklist) = End date (date). I don't know how to get this formula right, it says that Error: Field Service_Contract_Term__c is a picklist field. Picklist fields are only supported in certain functions. When I try to change the Contract term to TEXT(Contract Term) it still doesn't work in the formula. Please help! :)
I have a problem which I can't solve how would be easier to do this.
Problems is that when a new case is created the account -field is empty, now I need to create a workflow which updates this fields value to a one precise account. Now when I'm trying to create a workflow it says an error "Error: Field Account does not exist. Check spelling." And I think it's because it is a standard lookup field ? How should I solve this so I can create a rule or something that kind to change this Account-fields value?

  • April 09, 2014
  • Like
  • 0
Hi,

I'm using email to case functionality to create new case from email, but I have a little problem which I don't know how to solve so I would be very happy if someone could assist or push me to the right direction :)

So the problem is how does this email turn to case and how it is done (in which end this is done Outlook Exchange or in SF)? How could I make the email turn into a specific type of Case, for example  Email to a Support Case. Is this all done with workflow rule or is there another way?

Thanks already :)
  • March 17, 2014
  • Like
  • 0
Hi,

I'm tracking a number fields history and now I've created a workflow rule which sends an email alert if this field value is changed (for example the value was first 4 and now it's changed to 6"
Now the updated New Value is only shown in the email and not what the value was before? So how can I make the old value also show in the emal?


  • March 06, 2014
  • Like
  • 1
I need some help with my workflow rule formula. Idea is when this Installation Completion date is once set and if someone changes the date after that I'll get an email alert that this field is updated.

Now I've made the email templates,alerts and started working on my workflow rule and this is what I've come up :

AND(ISCHANGED(Installation_Completion_Date__c))

and evaluation criteria is : Evaluate the rule when a record is created, and every time it’s edited

but I'm not sure how to put this part that alert goes off only when it has a date(old value) and the date changes(new value). Now whenever I put date to the field (even when I set the value for the first time) it sends me the email. 

  • March 04, 2014
  • Like
  • 0
Hi,
I have a soql query problem which I don't know how I should put it to make it work.
I'm trying to fetch all setups and all of them contain one of these contract information and also if the setup has a recurring fee or not. The setup doesn't have to have a recurring fee but I would like it to show all setups those which have recurring fee and those which doesn't have.

Select id, (Select id, name, date_of_invoice__c, setup__c from recurring_fee__c) from Setup__c where contract__c = 'a0oD0000001CdR7',  'a0oD0000001DIvB', 'a0oD0000001DGcw' and cost_center__r.groupid__c = '0012000000Jb5R6'  ORDER BY setup__c desc, date_of_invoice__c desc
  • February 05, 2014
  • Like
  • 1
I'm trying to make a query which fetches the latest(one) data per setup. I've made it this far with the query
So the problem is I should fetch the latest recurring fee data from setup, but can't understand should I use Group by or order by to fetch from every setup the latest recurring fee data.

Select id, name, date_of_invoice__c, setup__c from recurring_fee__c where
setup__c in (select id from Setup__c where RecordType.name IN( 'infra','hardware' )
and cost_center__r.groupid__c = '0012000000AK643' ) ORDER BY setup__c desc
  • January 29, 2014
  • Like
  • 0
I have a problem which concerns exporting/updating data with data loader. I have a custom object Setup which has a Recurring fee related list. Now I'd have to update Date of Invoice and Created date information from Recuirring fee and these changes have to be made only to recuirring fees in certain Setups. I noticed I can't  query from both custom objects setup and recurring fee, so how could I link these two together? In Recurring fee there is a lookup field Setup__c which connects these two, but how can I query right these both objects with data loader?
Also what is right way to put date to data loader, I've selected from Setting European Time so what is the right way to write it ?! I've tried so many different things, but I can't understand what is the right way.  It's stated in SF this way 28.1.2014 12:49
  • January 28, 2014
  • Like
  • 0
I have a SOQL limit problem which I'm not sure how to fix,  it concerns this class but I've tried to make it with lists and maps so the SOQL limit wouldn't exceed. And it's only that underlined part which doesn't work .

public class UpdateMainAccountTechnologyList
{  
    public Boolean UpdateList(Account acc)
    {
        Boolean hasPolycom = false;
        Boolean hasDS = false;
        Boolean hasCisco = false;
        Boolean hasVidyo = false;
       
        List<String> codecdetails = new List<String>();
       
        List<String> polycoms = new List<String>();
        polycoms.add('Polycom');
        polycoms.add('HDX');
        polycoms.add('VSX');
        polycoms.add('QDX');
        polycoms.add('Group');
       
        List<String> vidyos = new List<String>();
        vidyos.add('Vidyo');
        vidyos.add('HD50');
        vidyos.add('HD100');
        vidyos.add('HD200');
       
        List<String> ciscos = new List<String>();
        ciscos.add('Cisco');
        ciscos.add('Cx');
        ciscos.add('Cxx');
        ciscos.add('EXxx');
        ciscos.add('MXxx');
        ciscos.add('SXxx');
        ciscos.add('MXP');
        ciscos.add('Profile');
       
        List<String> signages = new List<String>();
        signages.add('Signage');
       
        List<Asset__c> assets = [select Codec_Model__c, Codec_Details__c from Asset__c where Setup__c in (select Id from Setup__c Where Main_Account__c = :acc.Name and RecordType.Name != 'Infra') and (Codec_Model__c != null or Codec_Details__c != null)];
        for(Asset__c assetti : assets)
        {
            codecdetails.add(assetti.Codec_Model__c + ' : ' + assetti.Codec_Details__c);
        }
           
        List<Setup__c> setupit = [select Platform_Manufacturer__c, Name, RelatedMCU__c from Setup__c where Main_Account__c = :acc.Name];
        List<Setup__c> infrasetupit = [select Id, Platform_Manufacturer__c from Setup__c where Platform_Manufacturer__c != null];
       
         // Mika R 2013-Dec-13: Map the infra setups
        Map<Id, String> infraSetupMap = New Map<Id, String>();
        for (Setup__c s: infrasetupit) if (!infraSetupMap.containsKey(s.Id)) infraSetupMap.put(s.Id, s.Platform_Manufacturer__c);
       
        for(Setup__c setuppi : setupit)
        {
            if(setuppi.Platform_Manufacturer__c != null)
            {
                codecdetails.add(setuppi.Platform_Manufacturer__c);
            }
            //if the account has only virtual meeting rooms, we must find setup that has vmr as related mcu and find in what platform that vmr is
            if(setuppi.RelatedMCU__c != null)
            {
                // Mika R 2013-Dec-13: Fetch infra from map
                if (infraSetupMap.containsKey(setuppi.RelatedMCU__c)) codecdetails.add(infraSetupMap.get(setuppi.RelatedMCU__c));
              
                //Setup__c MCUSetup = [select Platform_Manufacturer__c from Setup__c where Id = :setuppi.RelatedMCU__c];              
                /*
                if(MCUSetup.Platform_Manufacturer__c != null)
                {
                    codecdetails.add(MCUSetup.Platform_Manufacturer__c);
                }
                */
            }
        }

        for(String detail : codecdetails)
        {
             for(String polycom : polycoms)
             {
                 if(detail.contains(polycom))
                 {
                     hasPolycom = true;
                     break;
                 }
             }
               
            for(String vidyo : vidyos)
            {
                if(detail.contains(vidyo))
                {
                    hasVidyo = true;
                    break;
                }
            }
               
            for(String cisco : ciscos)
            {
                if(detail.contains(cisco))
                {
                    hasCisco = true;
                    break;
                }
            }
              
            for(String signage : signages)
            {
                if(detail.contains(signage))
                {
                    hasDS = true;
                    break;
                }
            }         
        }
            
        String accountData = acc.Service_Type_List__c;

        if(hasPolycom)
        {
            if(String.isBlank(accountData))
            {
                accountData = 'Polycom';
            }
            else if(!accountData.contains('Polycom'))
            {
                accountData += ';Polycom';
            }
        }
           
        if(hasVidyo)
        {
            if(String.isBlank(accountData))
            {
                accountData = 'Vidyo';
            }
            else if(!accountData.contains('Vidyo'))
            {
                accountData += ';Vidyo';
            }
        }
               
        if(hasCisco)
        {
            if(String.isBlank(accountData))
            {
                accountData = 'Cisco';
            }
            else if(!accountData.contains('Cisco'))
            {
                accountData += ';Cisco';
            }
        }
        if(hasDS)
        {
            if(String.isBlank(accountData))
            {
                accountData = 'DS';
            }
            else if(!accountData.contains('DS'))
            {
                accountData += ';DS';
            }
        }
           
        acc.Service_Type_List__c = accountData;
        update acc;
        return true;
    }
}
  • January 02, 2014
  • Like
  • 0

Hi , I'm getting this error message : System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SetupChangeTechnologyListCheck: execution of AfterInsert caused by System.QueryException: List has no rows for assignment to SObject: : line 8, column 1

I don't understand why it doesn't find account objects, because there are alot of them in SF ?  Where should I start looking for an answer to this? Many thanks already, if you could somehow help me understand this better.

 

trigger SetupChangeTechnologyListCheck on Setup__c (after insert, after update)
{

    for(Setup__c s : trigger.new)
    {
        
        Account acc = [SELECT Name, Service_Type_List__c FROM Account WHERE RecordType.Name = 'Main Account' AND Name = :s.Main_Account__c];
                
        UpdateMainAccountTechnologyList techList = new UpdateMainAccountTechnologyList();
        techList.UpdateList(acc);
                
    }
}

  • December 13, 2013
  • Like
  • 0

Hi I get this error message while trying to delete a setup from main account which has multiple setups.  Main idea is that this would go through all the main account setups even when one of the setups is deleted. I would appreciate if you could give me some guidance.

 

trigger SetupChangeTechnologyListCheck on Setup__c (after insert, after update, after delete)
{
    for(Setup__c s : trigger.new)
    {
        
        Account acc = [SELECT Name, Service_Type_List__c FROM Account WHERE RecordType.Name = 'Main Account' AND Name = :s.Main_Account__c];
        UpdateMainAccountTechnologyList techList = new UpdateMainAccountTechnologyList();
        techList.UpdateList(acc);
        
    }
}

  • December 11, 2013
  • Like
  • 0

I made this testclass which handles cases + and cases contains account + setup information. Now I'm getting this error :

System.AssertException: Assertion Failed: Same value: null and I don't understand where this is coming from?

@isTest
private class AMobileHandlerTest {
   
    static testMethod void saveCaseTest() {
        // String account = ...;
        String connId = '12345678';
        String buyersID = 'bid';
        String classification = 'P3';
        String subject = 'Unit test subject';
        String description = 'Unit test description';
       
        Account ma = new account();
        ma.Name = 'test account';
        RecordType recordTypeMa = [ select Id, Name from RecordType where SObjectType = 'Account' and Name = 'Main Account' LIMIT 1];
        ma.RecordTypeId = recordTypeMa.Id;
        insert ma;
       
        Account ac = new account();
        ac.ParentId = ma.Id;
        ac.Name = 'test account';
        ac.ShippingCity = 'oulu';
        ac.ShippingCountry = 'finland';
        ac.ShippingPostalCode = '90550';
        ac.ShippingState = 'na';
        ac.ShippingStreet = 'eletie';
        RecordType recordType = [ select Id, Name from RecordType where SObjectType = 'Account' and Name = 'Site' LIMIT 1];
        ac.recordTypeId = recordType.Id;
        insert ac;
        System.assertNotEquals(null, ac.Id);
       
        Setup__c setuppi = new Setup__c();
        setuppi.Name = 'test';
        setuppi.SOC_LL_ID__c = connId;
        setuppi.site__c = ac.Id;
        insert setuppi;
        System.assertNotEquals(null, setuppi.Id);
       
       
        // AMobileHandler hndlr = new AMobileHandler();
        Test.startTest();
        string id = AMobileHandler.saveCase(connId, buyersId, classification, subject, description);
        Test.stopTest();
       
        System.assertNotEquals(null, id);

  • October 23, 2013
  • Like
  • 0

Hi, I have a problem with my test class which I'm moving from another sandbox to a different one with different data. Because I've picked up ID:s from cases, setups, contracts from this old environment the new environment doesn't have those. So I was thinking should I hard code these values to the code? How is it done? ( Id marked red on the code)

 

/**
 *
 */
@isTest
private class ServiceAvailablityForCaseATriggerTest {

    static testMethod void addCaseAndSAObjectTest() {
        Account ma = new account();
        ma.Name = 'test account2';
        RecordType recordTypeMa = [ select Id, Name from RecordType where SObjectType = 'Account' and Name = 'Main Account' LIMIT 1];
        ma.RecordTypeId = recordTypeMa.Id;
        insert ma;
        
        Account ac = new account();
        ac.ParentId = ma.Id;
        ac.Name = 'test account2';
        ac.ShippingCity = 'nevada';
        ac.ShippingCountry = 'russia';
        ac.ShippingPostalCode = '70211';
        ac.ShippingState = 'na';
        ac.ShippingStreet = 'testikatu';
        RecordType recordType = [ select Id, Name from RecordType where SObjectType = 'Account' and Name = 'Cost Center' LIMIT 1];
        ac.recordTypeId = recordType.Id;        
        ac.BillingStreet = 'testroad 4';
        ac.BillingPostalCode = '00070';
        ac.BillingCity = 'testcityi';
        ac.BillingCountry = 'testcountryi';
        ac.Address_for_Email_Invoices__c = 'test@videra.com';
        insert ac;
        
        Contract__c cc = new Contract__c();
        cc.Status__c = 'Active';
        cc.Contract_Agreement__c ='800L00000001R8K';
        cc.Main_Account__c = '001L000000HN8Pb';
        
        insert cc;
        
        Setup__c setup = new Setup__c();         
        setup.Name = 'LauranSetup3';
        setup.contract__c = 'a0oL0000000pBof;
        
        insert setup;
 

        Contract contract = new Contract();
        contract.Name = 'test contract';
        contract.Account = ma;
        contract.Business_Hours__c = '01m20000000Gvg7h';
        contract.CurrencyIsoCode = 'EUR';
        contract.Status = 'Negotiation/review';
        contract.StartDate = Date.newInstance(2013, 5, 23);
        contract.ContractTerm = 36;
        contract.OwnerExpirationNotice = '90';
        contract.AccountId = ma.Id;
        
        insert contract;
        
        Case ca = new Case();        
        RecordType recordType2 = [ select Id, Name from RecordType where SObjectType = 'Case' and Name = 'Support' LIMIT 1];
        ca.RecordTypeId = recordType2.Id;
        ca.Related_Setup__c = setup.Id;
        ca.Status = 'New';
        ca.priority = 'Low';
        ca.subject = 'subject1';
        ca.description = 'desc2';
        ca.Satisfaction_Survey_Language__c = 'English';
        
        ca.Fault_Classification__c =  'Major';
        //c.Last_Status_Change__c = System.Now();
        
        
        
       Test.StartTest();
          insert ca;
       Test.StopTest();
        
        List<Service_Availability__c> caseSAs = [select Name, Status__c, Status_explanation__c, Duration__c, Start_DateTime__c from Service_Availability__c
                                                //where Setup__c =: updatedCase.Related_Setup__c
                                                //and Case__c =: updatedCase.Id
                                                where Case__c =: ca.Id
                                                order by Name desc];  
        System.debug('ADD CASE: CASE SA count: ' + caseSAs.Size());        
        
        System.assert(caseSAs.size() == 1);
        System.assert(caseSAs[0].Duration__c == 0);
        
        List<Service_Availability__c> setupSAs = [select Name, Status__c, Status_explanation__c, Duration__c, Start_DateTime__c from Service_Availability__c
                                                where Setup__c =: ca.Related_Setup__c
                                                //and Case__c =: updatedCase.Id
                                                //where Case__c =: updatedCase.Id
                                                order by Name desc];  
        System.debug('ADD CASE: SETUP SA count: ' + setupSAs.Size());        
        
        System.assert(setupSAs.size() == 1);
        System.assert(setupSAs[0].Duration__c == 0);
        
        
        /*
        Contract contract = new Contract();
        contract.Name = 'test contract';
        contract.Account = ma;
        contract.CurrencyIsoCode = 'EUR';
        contract.Status = 'Negotiation/review';
        contract.StartDate = Date.newInstance(2013, 5, 23);
        contract.ContractTerm = 36;
        contract.OwnerExpirationNotice = '90';
        contract.AccountId = ma.Id;
        
        insert contract;
        */       
    }
}

  • October 16, 2013
  • Like
  • 0

I change my code because my SOQL limit was always going over and this map/list seemed to be the only way to make it work. Now I'm still getting a error : Compile Error: unexpected token: 'List' at line 50 column 12 (the problem marked red).

 

global class ServiceAvailabililtyUpdaterForCase implements Schedulable,
                                                           Database.Stateful/*,
                                                           Database.Batchable<sObject>*/ {

    // Implement Schedulable interface function for entry function to schedule this batch
    global void execute(SchedulableContext sc){
        
        ServiceAvailabililtyUpdaterForCase updater = new ServiceAvailabililtyUpdaterForCase();
        Date currentDate = Date.newinstance(DateTime.Now().Year(), DateTime.Now().Month(), DateTime.Now().Day());          
        updater.HandleServiceAvailabilityChange(currentDate);     
    }    
    
    /*
    * Execute method of Batchable interface
    */
    global void execute( Database.BatchableContext BC, List<sObject> records ) {
        System.debug('ServiceAvailabililtyUpdaterForCase.execute batch');               
    }       
            
    public void HandleServiceAvailabilityChange(Date currentDate) {
        
        /*
        1) Fetch not closed Support Cases
        2) Fetch valid Service Availability objects per Case
        3) Sort SAs by a) Case b) Name
        4) Update last SA with duration until end of the month
        5) Create new SA from the beginning of the new month (with same Fault Classification)       
        */
        RecordType recordType = [select Id, Name from RecordType where SObjectType = 'Case' and Name = 'Support' LIMIT 1];
        
        System.Debug('SCHEDULED: SUPPORT CASE REC TYPE ID: ' + recordType.Id);              
                               
        
        List<Case> suppportCases =[select Id, Fault_Classification__c, Setup_Name__c, CaseNumber, Related_Setup__c,Status_Explanation__c
                            from Case                                                       
                            where RecordTypeId =: recordType.Id
                            and IsClosed =: false                           
                            order by CreatedDate desc];
        //Create new list which contains supportcases records                   
        List<Id> idList = new List<Id>();
            for (Case c : suppportCases) {
               idList.add(c.Id);
             System.Debug('SCHEDULED: CASE ' + c.CaseNumber + ' HANDLING STARTED');
               }
               //Creating list which contains service availability + setup records
                List <Service_Availability__c> c = [SELECT setup__r.id,setup__r.name, setup__r.service_availability__c,setup__r.contract__c,setup__r.cost_center__c,ID, Name, Status__c, Duration__c, Start_DateTime__c,case__c FROM Service_Availability__c WHERE Case__c IN : idList];

        //Create map which has list of sa-records
        Map<Id, List<service_availability__c>> service_availability = new Map<Id, List<service_availability__c>>
            List value = m.get(Id);
                for(service_availability__c d: c) {
                    if service_availability.containsKey(d.case__c){
                        service_availability.get(d.case__c).add(d);
                    } else {
                        List<service_availability__c> s = new List<service_availability__c>();
                        s.add(d);
                        service_availability.put(d.case__c, s);
                    }
                }
        RecordType recordTypeIncident = [select Id, Name from RecordType where SObjectType = 'Service_Availability__c' and Name = 'Incident' LIMIT 1];
            for (Id currentcase:service_availability.keySet()) {
                for (service_availability__c sa:service_availability.get(currentcase)) {
                    Id hoursToUse = saHelper.GetHoursToUse(c, relatedSetup);
                    if(hoursToUse != null && relatedSetup != null) {                                            
                
                System.debug('SCHEDULED: DATE IN LAST SA: ' + oldSAsPerCase[0].Start_DateTime__c);
                System.debug('SCHEDULED: CURRENT DATE: ' + DateTime.Now());
                                                            
                // Check if month has changed, year not                     
                if (oldSAsPerCase[0].Start_DateTime__c.Month() < DateTime.Now().Month() && oldSAsPerCase[0].Start_DateTime__c.Year() == DateTime.Now().Year()) {
                    System.debug('SCHEDULED: MONTH HAS CHANGED from: ' + oldSAsPerCase[0].Start_DateTime__c.Month() + ' to: ' + DateTime.Now().Month());
                    
                    // Update last SA with duration until end of the month             
                    oldSAsPerCase[0].Duration__c = saHelper.CalculateDurationUntilEndOfMonth(hoursToUse, oldSAsPerCase[0].Start_DateTime__c, currentDate);
                    
                    // Start of current month
                    // TODO: THIS CAUSES TEST CASE TO FAIL, SINCE LOCAL TIME IS USED THERE                
                    DateTime startOfCurrentMonth = DateTime.newinstance(currentDate.Year(), currentDate.Month(), 1, 0, 0, 0);
                    System.debug('SCHEDULED: START OF CURRENT MONTH: ' + startOfCurrentMonth);
                                                    
                    saHelper.InsertServiceAvailabilityObjectToCase(c, startOfCurrentMonth, recordTypeIncident, true);
                    update oldSAsPerCase[0];
                    
                    // Update corresponding Setup SA objects
                    if (!alreadyHandled.Contains(relatedSetup)) {
                        saHelper.UpdateSetupServiceAvailability(c, relatedSetup, true);                   
                        alreadyHandled.Add(relatedSetup);
                    }                   
                    
                // Year changed, so did month
                } else if (DateTime.Now().Year() > oldSAsPerCase[0].Start_DateTime__c.Year()) {
                    System.debug('SCHEDULED: YEAR HAS CHANGED from: ' + oldSAsPerCase[0].Start_DateTime__c.Year() + ' to: ' + DateTime.Now().Year());
                    System.debug('SCHEDULED: MONTH HAS CHANGED from: ' + oldSAsPerCase[0].Start_DateTime__c.Month() + ' to: ' + DateTime.Now().Month());
                     
                    oldSAsPerCase[0].Duration__c = saHelper.CalculateDurationUntilEndOfYear(hoursToUse, oldSAsPerCase[0].Start_DateTime__c, currentDate);
                     
                    // Start of current month                
                    DateTime startOfCurrentMonth = DateTime.newinstance(currentDate.Year(), currentDate.Month(), 1, 0, 0, 0);
                    System.debug('SCHEDULED: START OF CURRENT MONTH: ' + startOfCurrentMonth);
                                                    
                    saHelper.InsertServiceAvailabilityObjectToCase(c, startOfCurrentMonth, recordTypeIncident, true);
                    update oldSAsPerCase[0];
                    
                    // Update corresponding Setup SA objects
                    if (!alreadyHandled.Contains(relatedSetup)) {
                        saHelper.UpdateSetupServiceAvailability(c, relatedSetup, true);
                        alreadyHandled.Add(relatedSetup);
                    }
                                                            
                } else {
                    System.debug('SCHEDULED: MONTH not CHANGED');
                    System.debug(' BUSINESS HOURS NO FOUND');
                }
               }
            }                                                              
        }                       
    }

  • October 09, 2013
  • Like
  • 0

I'm new in writing apex classes + triggers so I have a problem now with a batch class which has a for loop so DML statement limit goes over, I was reading about bulkifying code, but it seems it's only for triggers not classes(please correct me if I'm wrong)? And how should I change this part of the code if I need to make it work :

        for (Case c : suppportCases) {
            System.Debug('SCHEDULED: CASE ' + c.CaseNumber + ' HANDLING STARTED');
                    
            List<Service_Availability__c> oldSAsPerCase =
                                            [select Name, Status__c, Duration__c, Start_DateTime__c from Service_Availability__c                                                     
                                            where Case__c =: c.Id
                                            order by Name desc];
            
            System.Debug('SCHEDULED: OLD SA COUNT: ' + oldSAsPerCase.Size());
Should I make it this way :

 

List<Service_Availability__c> oldSAsPerCase : [SELECT Name, Status__c, Duration__c, Start_DateTime__c from Service_Availability__c                                                     
                                            where Case__c =: c.Id
                                            order by Name desc];

 

System.Debug('SCHEDULED: OLD SA COUNT: ' + oldSAsPerCase.Size());

 

for (Case c : suppportCases) {
            System.Debug('SCHEDULED: CASE ' + c.CaseNumber + ' HANDLING STARTED'); ?

  • October 07, 2013
  • Like
  • 0

Hi, I'm getting this error message, Error:Apex trigger CaseResolutionTimeTrigger caused an unexpected exception, contact your administrator: CaseResolutionTimeTrigger: execution of BeforeUpdate caused by: System.NullPointerException: End date cannot be null: (System Code) ., So I was wondering how could I make this work so that even when I have entered the date to the field and I want to empy the date field it won't shout error.

 

trigger CaseResolutionTimeTrigger on Case (before update) {
    
    if (Trigger.isUpdate) {
        
        for (Case updatedCase:System.Trigger.new) {
            System.Debug('CaseResolutionTimeTrigger: CASE ID: ' + updatedCase.Id);           
                        
            RecordType recordType = [select Id, Name from RecordType where SObjectType = 'Case' and Name = 'Support' LIMIT 1];
            
            System.Debug('CaseResolutionTimeTrigger: FETCHED RECORD TYPE: ' + recordType.Id );
            System.Debug('CaseResolutionTimeTrigger: RECORD TYPE IN CASE: ' + updatedCase.RecordType.Id );
            
            // Get old Case data. We are also only interested in Support Cases.
                if (System.Trigger.oldMap.get(updatedCase.Id) != null /*&& updatedCase.RecordType == recordType*/ ) {
            
                Case oldCase = System.Trigger.oldMap.get(updatedCase.Id);            
                System.Debug('CaseResolutionTimeTrigger: OLD STATUS: ' + oldCase.Status);
                System.Debug('CaseResolutionTimeTrigger: NEW STATUS: ' + updatedCase.Status);

                  if (updatedCase.Date_and_time_of_resolution__c!= null && updatedCase.Related_Setup__c != null && updatedCase.Resolution_time__c == null ||(oldCase.Date_and_time_of_resolution__c!= updatedCase.Date_and_time_of_resolution__c)) {
                    
                    //Related Setup
                      Setup__c relatedSetup = [select Id, Contract__c, Cost_Center__c, Name, Service_Availability__c from Setup__c where Id =: updatedCase.Related_Setup__c];
                      System.Debug('CaseResolutionTimeTrigger: Related Setup: ' + relatedSetup.Name);
                    
                    //Get BusinessHours from Setup -> Contract-> Contract(Agreement) -> Business Hours
                    ServiceAvailability saHelper = new ServiceAvailability();
                    Id hoursToUse = saHelper.GetHoursToUse(updatedCase, relatedSetup);
                    if(hoursToUse != null ) {                                       
                        System.debug('CaseResolutionTimeTrigger: HOURS TO USE: ' + hoursToUse);
                                        
                     //Double ResolutionTime = DateTime.Now().GetTime() - Initial_Response__c.GetTime() - Date_and_time_of_resolution__c.GetTime();
                     Double resolutionTime =     BusinessHours.diff(hoursToUse,updatedCase.Initial_Response__c,updatedCase.Date_and_time_of_resolution__c);
                     Double rmMins = resolutionTime / 60000.0;
                     Double rmHrs = resolutionTime / 60000.0 / 60;
                     Double rmDays = resolutionTime / 60000.0 / 60 / 24;

                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (ms): ' + resolutionTime);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (mins): ' + rmMins);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (hrs): ' + rmHrs);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (days): ' + rmDays);                     
                        
                     updatedCase.Resolution_time__c = rmMins;
                    // update updatedCase
                     
                  } else {
                        
                     System.Debug('SETUP NOT FOUND: ' + updatedCase.Related_Setup__c);
                     }
                   }
                }
            }
        }
    }
}

  • October 07, 2013
  • Like
  • 0

Hi, I have trigger that's meant to calculate SLA minutes using BusinessHours.


Now I keep getting this error : Compile Error: Method does not exist or incorrect signature BusinessHours.diff(Id, Datetime, Decimal) at line 32 column 46

and I don't understand what is wrong here? (Highlighted sentence)

 

trigger CaseResolutionTimeTrigger on Case (before update) {
    
    if (Trigger.isUpdate) {
        
        for (Case updatedCase:System.Trigger.new) {
            System.Debug('CaseResolutionTimeTrigger: CASE ID: ' + updatedCase.Id);           
                        
            RecordType recordType = [select Id, Name from RecordType where SObjectType = 'Case' and Name = 'Support' LIMIT 1];
            
            System.Debug('CaseResolutionTimeTrigger: FETCHED RECORD TYPE: ' + recordType.Id );
            System.Debug('CaseResolutionTimeTrigger: RECORD TYPE IN CASE: ' + updatedCase.RecordType.Id );
            
            // Get old Case data. We are also only interested in Support Cases.
                 if (System.Trigger.oldMap.get(updatedCase.Id) != null /*&& updatedCase.RecordType == recordType*/ ) {
            
                Case oldCase = System.Trigger.oldMap.get(updatedCase.Id);            
                System.Debug('CaseResolutionTimeTrigger: OLD STATUS: ' + oldCase.Status);
                System.Debug('CaseResolutionTimeTrigger: NEW STATUS: ' + updatedCase.Status);
                  if (updatedCase.Date_and_time_of_resolution__c!= null && updatedCase.Related_Setup__c != null && updatedCase.Resolution_time__c == null ||(oldCase.Date_and_time_of_resolution__c!= updatedCase.Date_and_time_of_resolution__c)) {
                    
                    // Related Setup
                    Setup__c relatedSetup = [select Id, Contract__c, Cost_Center__c, Name, Service_Availability__c from Setup__c where Id =: updatedCase.Related_Setup__c];
                    System.Debug('CaseResolutionTimeTrigger: Related Setup: ' + relatedSetup.Name);
                    
                    // Get BusinessHours from Setup -> Contract-> Contract(Agreement) -> Business Hours
                    ServiceAvailability saHelper = new ServiceAvailability();
                    Id hoursToUse = saHelper.GetHoursToUse(updatedCase, relatedSetup);
                    if(hoursToUse != null ) {                                       
                        System.debug('CaseResolutionTimeTrigger: HOURS TO USE: ' + hoursToUse);
                                        
                     //Double ResolutionTime = Initial_Response__c.GetTime() - Date_and_time_of_resolution__c.GetTime();
                     Double ResolutionTime = BusinessHours.diff(hoursToUse, updatedCase.Initial_Response__c,updatedCase.Resolution_time__c);
                     Double rmMins = resolutionTime / 60000.0;
                     Double rmHrs = resolutionTime / 60000.0 / 60;
                     Double rmDays = resolutionTime / 60000.0 / 60 / 24;
                        
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (ms): ' + resolutionTime);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (mins): ' + rmMins);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (hrs): ' + rmHrs);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (days): ' + rmDays);                     
                        
                     updatedCase.Resolution_time__c = rmMins;
                     // update updatedCase
                     
                  } else {
                        
                     System.Debug('SETUP NOT FOUND: ' + updatedCase.Related_Setup__c);
                   }
                }
            }
        }
    }
}

  • October 03, 2013
  • Like
  • 0

I have a problem with my trigger which concerns resolution time ( it includes time from open case = initial response time to when a case is closed = resolution time), but it won't  re-calculate the resolution minutes if the response time has been set before and I'll try to change the date/time again. How should I change my code?


Here's my trigger:

´trigger CaseResolutionMinutesTrigger on Case (before update) {
    
    if (Trigger.isUpdate) {
        
        for (Case updatedCase:System.Trigger.new) {
            System.Debug('CaseResolutionMinutesTrigger: CASE ID: ' + updatedCase.Id);           
                        
            RecordType recordType = [select Id, Name from RecordType where SObjectType = 'Case' and Name = 'Support' LIMIT 1];
            
            System.Debug('CaseResolutionMinutesTrigger: FETCHED RECORD TYPE: ' + recordType.Id );
            System.Debug('CaseResolutionMinutesTrigger: RECORD TYPE IN CASE: ' + updatedCase.RecordType.Id );
            
            // Get old Case data. We are also only interested in Support Cases.
            if (System.Trigger.oldMap.get(updatedCase.Id) != null /*&& updatedCase.RecordType == recordType*/ ) {
            
                Case oldCase = System.Trigger.oldMap.get(updatedCase.Id);            
                System.Debug('CaseResolutionMinutesTrigger: OLD STATUS: ' + oldCase.Status);
                System.Debug('CaseResolutionMinutesTrigger: NEW STATUS: ' + updatedCase.Status);
                  if (updatedCase.Resolution_time__c != null && updatedCase.Resolution_minutes__c == null && updatedCase.Related_Setup__c != null ) {
                    
                    // Related Setup
                    Setup__c relatedSetup = [select Id, Contract__c, Cost_Center__c, Name, Service_Availability__c from Setup__c where Id =: updatedCase.Related_Setup__c];
                    System.Debug('CaseResolutionMinutesTrigger: Related Setup: ' + relatedSetup.Name);
                    
                    // Get BusinessHours from Setup -> Contract-> Contract(Agreement) -> Business Hours
                    ServiceAvailability saHelper = new ServiceAvailability();
                    Id hoursToUse = saHelper.GetHoursToUse(updatedCase, relatedSetup);
                    if(hoursToUse != null ) {                                       
                        System.debug('CaseResolutionMinutesTrigger: HOURS TO USE: ' + hoursToUse);
                                        
                     //Double resolutionMinutes = Initial_Response__c.GetTime() - Resolution_time__c.GetTime();
                     Double resolutionMinutes = BusinessHours.diff(hoursToUse, updatedCase.Initial_Response__c, System.now());
                     Double rmMins = resolutionMinutes / 60000.0;
                     Double rmHrs = resolutionMinutes / 60000.0 / 60;
                     Double rmDays = resolutionMinutes / 60000.0 / 60 / 24;
                        
                     System.Debug('CaseResolutionMinutesTrigger: RESOLUTION MINUTES (ms): ' + resolutionMinutes);
                     System.Debug('CaseResolutionMinutesTrigger: RESOLUTION MINUTES (mins): ' + rmMins);
                     System.Debug('CaseResolutionMinutesTrigger: RESOLUTION MINUTES (hrs): ' + rmHrs);
                     System.Debug('CaseResolutionMinutesTrigger: RESOLUTION MINUTES (days): ' + rmDays);                     
                        
                     updatedCase.Resolution_minutes__c = rmMins;
                   
                     // update updatedCase;
                   } else { 
                        System.Debug('SETUP NOT FOUND: ' + updatedCase.Related_Setup__c);
                   }
                }
            }
        }
    }
}

  • September 30, 2013
  • Like
  • 0
Hi,

I'm tracking a number fields history and now I've created a workflow rule which sends an email alert if this field value is changed (for example the value was first 4 and now it's changed to 6"
Now the updated New Value is only shown in the email and not what the value was before? So how can I make the old value also show in the emal?


  • March 06, 2014
  • Like
  • 1
Hi,
I have a soql query problem which I don't know how I should put it to make it work.
I'm trying to fetch all setups and all of them contain one of these contract information and also if the setup has a recurring fee or not. The setup doesn't have to have a recurring fee but I would like it to show all setups those which have recurring fee and those which doesn't have.

Select id, (Select id, name, date_of_invoice__c, setup__c from recurring_fee__c) from Setup__c where contract__c = 'a0oD0000001CdR7',  'a0oD0000001DIvB', 'a0oD0000001DGcw' and cost_center__r.groupid__c = '0012000000Jb5R6'  ORDER BY setup__c desc, date_of_invoice__c desc
  • February 05, 2014
  • Like
  • 1
Hi, I have a problem with my formula which should count End Date from Start Date + Contract Term, but the problem is that Contract Term values are not always divisible by 12? For example (37 or 41) .

Here is my formula before I found out that all the values aren't divisible by 12:

DATE(
(YEAR(Service_Contract_Period_Start_Date__c)+VALUE(TEXT(Service_Contract_Term__c ))/12),
MONTH(Service_Contract_Period_Start_Date__c),
DAY(Service_Contract_Period_Start_Date__c)
)

How should I solve this ?
Hi, I need to do a workflow (or validation rule I'm not sure which one to use) and it should do this "Setup status can be saved as "Cancelled" only if prior value has been "In delivery".
But when I do it like this the first Error goes : Extra " , " then when I take it off it says "Extra Pickval" 

AND(ISCHANGED(Setup_Status__c), "Cancelled"),
ISPICKVAL(PRIORVALUE(Setup_Status__c), "In Delivery"))

What would be a better solution for this?
I need some help with my workflow rule formula. Idea is when this Installation Completion date is once set and if someone changes the date after that I'll get an email alert that this field is updated.

Now I've made the email templates,alerts and started working on my workflow rule and this is what I've come up :

AND(ISCHANGED(Installation_Completion_Date__c))

and evaluation criteria is : Evaluate the rule when a record is created, and every time it’s edited

but I'm not sure how to put this part that alert goes off only when it has a date(old value) and the date changes(new value). Now whenever I put date to the field (even when I set the value for the first time) it sends me the email. 

  • March 04, 2014
  • Like
  • 0
I have a problem which concerns exporting/updating data with data loader. I have a custom object Setup which has a Recurring fee related list. Now I'd have to update Date of Invoice and Created date information from Recuirring fee and these changes have to be made only to recuirring fees in certain Setups. I noticed I can't  query from both custom objects setup and recurring fee, so how could I link these two together? In Recurring fee there is a lookup field Setup__c which connects these two, but how can I query right these both objects with data loader?
Also what is right way to put date to data loader, I've selected from Setting European Time so what is the right way to write it ?! I've tried so many different things, but I can't understand what is the right way.  It's stated in SF this way 28.1.2014 12:49
  • January 28, 2014
  • Like
  • 0
I have a SOQL limit problem which I'm not sure how to fix,  it concerns this class but I've tried to make it with lists and maps so the SOQL limit wouldn't exceed. And it's only that underlined part which doesn't work .

public class UpdateMainAccountTechnologyList
{  
    public Boolean UpdateList(Account acc)
    {
        Boolean hasPolycom = false;
        Boolean hasDS = false;
        Boolean hasCisco = false;
        Boolean hasVidyo = false;
       
        List<String> codecdetails = new List<String>();
       
        List<String> polycoms = new List<String>();
        polycoms.add('Polycom');
        polycoms.add('HDX');
        polycoms.add('VSX');
        polycoms.add('QDX');
        polycoms.add('Group');
       
        List<String> vidyos = new List<String>();
        vidyos.add('Vidyo');
        vidyos.add('HD50');
        vidyos.add('HD100');
        vidyos.add('HD200');
       
        List<String> ciscos = new List<String>();
        ciscos.add('Cisco');
        ciscos.add('Cx');
        ciscos.add('Cxx');
        ciscos.add('EXxx');
        ciscos.add('MXxx');
        ciscos.add('SXxx');
        ciscos.add('MXP');
        ciscos.add('Profile');
       
        List<String> signages = new List<String>();
        signages.add('Signage');
       
        List<Asset__c> assets = [select Codec_Model__c, Codec_Details__c from Asset__c where Setup__c in (select Id from Setup__c Where Main_Account__c = :acc.Name and RecordType.Name != 'Infra') and (Codec_Model__c != null or Codec_Details__c != null)];
        for(Asset__c assetti : assets)
        {
            codecdetails.add(assetti.Codec_Model__c + ' : ' + assetti.Codec_Details__c);
        }
           
        List<Setup__c> setupit = [select Platform_Manufacturer__c, Name, RelatedMCU__c from Setup__c where Main_Account__c = :acc.Name];
        List<Setup__c> infrasetupit = [select Id, Platform_Manufacturer__c from Setup__c where Platform_Manufacturer__c != null];
       
         // Mika R 2013-Dec-13: Map the infra setups
        Map<Id, String> infraSetupMap = New Map<Id, String>();
        for (Setup__c s: infrasetupit) if (!infraSetupMap.containsKey(s.Id)) infraSetupMap.put(s.Id, s.Platform_Manufacturer__c);
       
        for(Setup__c setuppi : setupit)
        {
            if(setuppi.Platform_Manufacturer__c != null)
            {
                codecdetails.add(setuppi.Platform_Manufacturer__c);
            }
            //if the account has only virtual meeting rooms, we must find setup that has vmr as related mcu and find in what platform that vmr is
            if(setuppi.RelatedMCU__c != null)
            {
                // Mika R 2013-Dec-13: Fetch infra from map
                if (infraSetupMap.containsKey(setuppi.RelatedMCU__c)) codecdetails.add(infraSetupMap.get(setuppi.RelatedMCU__c));
              
                //Setup__c MCUSetup = [select Platform_Manufacturer__c from Setup__c where Id = :setuppi.RelatedMCU__c];              
                /*
                if(MCUSetup.Platform_Manufacturer__c != null)
                {
                    codecdetails.add(MCUSetup.Platform_Manufacturer__c);
                }
                */
            }
        }

        for(String detail : codecdetails)
        {
             for(String polycom : polycoms)
             {
                 if(detail.contains(polycom))
                 {
                     hasPolycom = true;
                     break;
                 }
             }
               
            for(String vidyo : vidyos)
            {
                if(detail.contains(vidyo))
                {
                    hasVidyo = true;
                    break;
                }
            }
               
            for(String cisco : ciscos)
            {
                if(detail.contains(cisco))
                {
                    hasCisco = true;
                    break;
                }
            }
              
            for(String signage : signages)
            {
                if(detail.contains(signage))
                {
                    hasDS = true;
                    break;
                }
            }         
        }
            
        String accountData = acc.Service_Type_List__c;

        if(hasPolycom)
        {
            if(String.isBlank(accountData))
            {
                accountData = 'Polycom';
            }
            else if(!accountData.contains('Polycom'))
            {
                accountData += ';Polycom';
            }
        }
           
        if(hasVidyo)
        {
            if(String.isBlank(accountData))
            {
                accountData = 'Vidyo';
            }
            else if(!accountData.contains('Vidyo'))
            {
                accountData += ';Vidyo';
            }
        }
               
        if(hasCisco)
        {
            if(String.isBlank(accountData))
            {
                accountData = 'Cisco';
            }
            else if(!accountData.contains('Cisco'))
            {
                accountData += ';Cisco';
            }
        }
        if(hasDS)
        {
            if(String.isBlank(accountData))
            {
                accountData = 'DS';
            }
            else if(!accountData.contains('DS'))
            {
                accountData += ';DS';
            }
        }
           
        acc.Service_Type_List__c = accountData;
        update acc;
        return true;
    }
}
  • January 02, 2014
  • Like
  • 0

Hi I get this error message while trying to delete a setup from main account which has multiple setups.  Main idea is that this would go through all the main account setups even when one of the setups is deleted. I would appreciate if you could give me some guidance.

 

trigger SetupChangeTechnologyListCheck on Setup__c (after insert, after update, after delete)
{
    for(Setup__c s : trigger.new)
    {
        
        Account acc = [SELECT Name, Service_Type_List__c FROM Account WHERE RecordType.Name = 'Main Account' AND Name = :s.Main_Account__c];
        UpdateMainAccountTechnologyList techList = new UpdateMainAccountTechnologyList();
        techList.UpdateList(acc);
        
    }
}

  • December 11, 2013
  • Like
  • 0

I change my code because my SOQL limit was always going over and this map/list seemed to be the only way to make it work. Now I'm still getting a error : Compile Error: unexpected token: 'List' at line 50 column 12 (the problem marked red).

 

global class ServiceAvailabililtyUpdaterForCase implements Schedulable,
                                                           Database.Stateful/*,
                                                           Database.Batchable<sObject>*/ {

    // Implement Schedulable interface function for entry function to schedule this batch
    global void execute(SchedulableContext sc){
        
        ServiceAvailabililtyUpdaterForCase updater = new ServiceAvailabililtyUpdaterForCase();
        Date currentDate = Date.newinstance(DateTime.Now().Year(), DateTime.Now().Month(), DateTime.Now().Day());          
        updater.HandleServiceAvailabilityChange(currentDate);     
    }    
    
    /*
    * Execute method of Batchable interface
    */
    global void execute( Database.BatchableContext BC, List<sObject> records ) {
        System.debug('ServiceAvailabililtyUpdaterForCase.execute batch');               
    }       
            
    public void HandleServiceAvailabilityChange(Date currentDate) {
        
        /*
        1) Fetch not closed Support Cases
        2) Fetch valid Service Availability objects per Case
        3) Sort SAs by a) Case b) Name
        4) Update last SA with duration until end of the month
        5) Create new SA from the beginning of the new month (with same Fault Classification)       
        */
        RecordType recordType = [select Id, Name from RecordType where SObjectType = 'Case' and Name = 'Support' LIMIT 1];
        
        System.Debug('SCHEDULED: SUPPORT CASE REC TYPE ID: ' + recordType.Id);              
                               
        
        List<Case> suppportCases =[select Id, Fault_Classification__c, Setup_Name__c, CaseNumber, Related_Setup__c,Status_Explanation__c
                            from Case                                                       
                            where RecordTypeId =: recordType.Id
                            and IsClosed =: false                           
                            order by CreatedDate desc];
        //Create new list which contains supportcases records                   
        List<Id> idList = new List<Id>();
            for (Case c : suppportCases) {
               idList.add(c.Id);
             System.Debug('SCHEDULED: CASE ' + c.CaseNumber + ' HANDLING STARTED');
               }
               //Creating list which contains service availability + setup records
                List <Service_Availability__c> c = [SELECT setup__r.id,setup__r.name, setup__r.service_availability__c,setup__r.contract__c,setup__r.cost_center__c,ID, Name, Status__c, Duration__c, Start_DateTime__c,case__c FROM Service_Availability__c WHERE Case__c IN : idList];

        //Create map which has list of sa-records
        Map<Id, List<service_availability__c>> service_availability = new Map<Id, List<service_availability__c>>
            List value = m.get(Id);
                for(service_availability__c d: c) {
                    if service_availability.containsKey(d.case__c){
                        service_availability.get(d.case__c).add(d);
                    } else {
                        List<service_availability__c> s = new List<service_availability__c>();
                        s.add(d);
                        service_availability.put(d.case__c, s);
                    }
                }
        RecordType recordTypeIncident = [select Id, Name from RecordType where SObjectType = 'Service_Availability__c' and Name = 'Incident' LIMIT 1];
            for (Id currentcase:service_availability.keySet()) {
                for (service_availability__c sa:service_availability.get(currentcase)) {
                    Id hoursToUse = saHelper.GetHoursToUse(c, relatedSetup);
                    if(hoursToUse != null && relatedSetup != null) {                                            
                
                System.debug('SCHEDULED: DATE IN LAST SA: ' + oldSAsPerCase[0].Start_DateTime__c);
                System.debug('SCHEDULED: CURRENT DATE: ' + DateTime.Now());
                                                            
                // Check if month has changed, year not                     
                if (oldSAsPerCase[0].Start_DateTime__c.Month() < DateTime.Now().Month() && oldSAsPerCase[0].Start_DateTime__c.Year() == DateTime.Now().Year()) {
                    System.debug('SCHEDULED: MONTH HAS CHANGED from: ' + oldSAsPerCase[0].Start_DateTime__c.Month() + ' to: ' + DateTime.Now().Month());
                    
                    // Update last SA with duration until end of the month             
                    oldSAsPerCase[0].Duration__c = saHelper.CalculateDurationUntilEndOfMonth(hoursToUse, oldSAsPerCase[0].Start_DateTime__c, currentDate);
                    
                    // Start of current month
                    // TODO: THIS CAUSES TEST CASE TO FAIL, SINCE LOCAL TIME IS USED THERE                
                    DateTime startOfCurrentMonth = DateTime.newinstance(currentDate.Year(), currentDate.Month(), 1, 0, 0, 0);
                    System.debug('SCHEDULED: START OF CURRENT MONTH: ' + startOfCurrentMonth);
                                                    
                    saHelper.InsertServiceAvailabilityObjectToCase(c, startOfCurrentMonth, recordTypeIncident, true);
                    update oldSAsPerCase[0];
                    
                    // Update corresponding Setup SA objects
                    if (!alreadyHandled.Contains(relatedSetup)) {
                        saHelper.UpdateSetupServiceAvailability(c, relatedSetup, true);                   
                        alreadyHandled.Add(relatedSetup);
                    }                   
                    
                // Year changed, so did month
                } else if (DateTime.Now().Year() > oldSAsPerCase[0].Start_DateTime__c.Year()) {
                    System.debug('SCHEDULED: YEAR HAS CHANGED from: ' + oldSAsPerCase[0].Start_DateTime__c.Year() + ' to: ' + DateTime.Now().Year());
                    System.debug('SCHEDULED: MONTH HAS CHANGED from: ' + oldSAsPerCase[0].Start_DateTime__c.Month() + ' to: ' + DateTime.Now().Month());
                     
                    oldSAsPerCase[0].Duration__c = saHelper.CalculateDurationUntilEndOfYear(hoursToUse, oldSAsPerCase[0].Start_DateTime__c, currentDate);
                     
                    // Start of current month                
                    DateTime startOfCurrentMonth = DateTime.newinstance(currentDate.Year(), currentDate.Month(), 1, 0, 0, 0);
                    System.debug('SCHEDULED: START OF CURRENT MONTH: ' + startOfCurrentMonth);
                                                    
                    saHelper.InsertServiceAvailabilityObjectToCase(c, startOfCurrentMonth, recordTypeIncident, true);
                    update oldSAsPerCase[0];
                    
                    // Update corresponding Setup SA objects
                    if (!alreadyHandled.Contains(relatedSetup)) {
                        saHelper.UpdateSetupServiceAvailability(c, relatedSetup, true);
                        alreadyHandled.Add(relatedSetup);
                    }
                                                            
                } else {
                    System.debug('SCHEDULED: MONTH not CHANGED');
                    System.debug(' BUSINESS HOURS NO FOUND');
                }
               }
            }                                                              
        }                       
    }

  • October 09, 2013
  • Like
  • 0

I'm new in writing apex classes + triggers so I have a problem now with a batch class which has a for loop so DML statement limit goes over, I was reading about bulkifying code, but it seems it's only for triggers not classes(please correct me if I'm wrong)? And how should I change this part of the code if I need to make it work :

        for (Case c : suppportCases) {
            System.Debug('SCHEDULED: CASE ' + c.CaseNumber + ' HANDLING STARTED');
                    
            List<Service_Availability__c> oldSAsPerCase =
                                            [select Name, Status__c, Duration__c, Start_DateTime__c from Service_Availability__c                                                     
                                            where Case__c =: c.Id
                                            order by Name desc];
            
            System.Debug('SCHEDULED: OLD SA COUNT: ' + oldSAsPerCase.Size());
Should I make it this way :

 

List<Service_Availability__c> oldSAsPerCase : [SELECT Name, Status__c, Duration__c, Start_DateTime__c from Service_Availability__c                                                     
                                            where Case__c =: c.Id
                                            order by Name desc];

 

System.Debug('SCHEDULED: OLD SA COUNT: ' + oldSAsPerCase.Size());

 

for (Case c : suppportCases) {
            System.Debug('SCHEDULED: CASE ' + c.CaseNumber + ' HANDLING STARTED'); ?

  • October 07, 2013
  • Like
  • 0

Hi, I'm getting this error message, Error:Apex trigger CaseResolutionTimeTrigger caused an unexpected exception, contact your administrator: CaseResolutionTimeTrigger: execution of BeforeUpdate caused by: System.NullPointerException: End date cannot be null: (System Code) ., So I was wondering how could I make this work so that even when I have entered the date to the field and I want to empy the date field it won't shout error.

 

trigger CaseResolutionTimeTrigger on Case (before update) {
    
    if (Trigger.isUpdate) {
        
        for (Case updatedCase:System.Trigger.new) {
            System.Debug('CaseResolutionTimeTrigger: CASE ID: ' + updatedCase.Id);           
                        
            RecordType recordType = [select Id, Name from RecordType where SObjectType = 'Case' and Name = 'Support' LIMIT 1];
            
            System.Debug('CaseResolutionTimeTrigger: FETCHED RECORD TYPE: ' + recordType.Id );
            System.Debug('CaseResolutionTimeTrigger: RECORD TYPE IN CASE: ' + updatedCase.RecordType.Id );
            
            // Get old Case data. We are also only interested in Support Cases.
                if (System.Trigger.oldMap.get(updatedCase.Id) != null /*&& updatedCase.RecordType == recordType*/ ) {
            
                Case oldCase = System.Trigger.oldMap.get(updatedCase.Id);            
                System.Debug('CaseResolutionTimeTrigger: OLD STATUS: ' + oldCase.Status);
                System.Debug('CaseResolutionTimeTrigger: NEW STATUS: ' + updatedCase.Status);

                  if (updatedCase.Date_and_time_of_resolution__c!= null && updatedCase.Related_Setup__c != null && updatedCase.Resolution_time__c == null ||(oldCase.Date_and_time_of_resolution__c!= updatedCase.Date_and_time_of_resolution__c)) {
                    
                    //Related Setup
                      Setup__c relatedSetup = [select Id, Contract__c, Cost_Center__c, Name, Service_Availability__c from Setup__c where Id =: updatedCase.Related_Setup__c];
                      System.Debug('CaseResolutionTimeTrigger: Related Setup: ' + relatedSetup.Name);
                    
                    //Get BusinessHours from Setup -> Contract-> Contract(Agreement) -> Business Hours
                    ServiceAvailability saHelper = new ServiceAvailability();
                    Id hoursToUse = saHelper.GetHoursToUse(updatedCase, relatedSetup);
                    if(hoursToUse != null ) {                                       
                        System.debug('CaseResolutionTimeTrigger: HOURS TO USE: ' + hoursToUse);
                                        
                     //Double ResolutionTime = DateTime.Now().GetTime() - Initial_Response__c.GetTime() - Date_and_time_of_resolution__c.GetTime();
                     Double resolutionTime =     BusinessHours.diff(hoursToUse,updatedCase.Initial_Response__c,updatedCase.Date_and_time_of_resolution__c);
                     Double rmMins = resolutionTime / 60000.0;
                     Double rmHrs = resolutionTime / 60000.0 / 60;
                     Double rmDays = resolutionTime / 60000.0 / 60 / 24;

                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (ms): ' + resolutionTime);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (mins): ' + rmMins);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (hrs): ' + rmHrs);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (days): ' + rmDays);                     
                        
                     updatedCase.Resolution_time__c = rmMins;
                    // update updatedCase
                     
                  } else {
                        
                     System.Debug('SETUP NOT FOUND: ' + updatedCase.Related_Setup__c);
                     }
                   }
                }
            }
        }
    }
}

  • October 07, 2013
  • Like
  • 0

Hi, I have trigger that's meant to calculate SLA minutes using BusinessHours.


Now I keep getting this error : Compile Error: Method does not exist or incorrect signature BusinessHours.diff(Id, Datetime, Decimal) at line 32 column 46

and I don't understand what is wrong here? (Highlighted sentence)

 

trigger CaseResolutionTimeTrigger on Case (before update) {
    
    if (Trigger.isUpdate) {
        
        for (Case updatedCase:System.Trigger.new) {
            System.Debug('CaseResolutionTimeTrigger: CASE ID: ' + updatedCase.Id);           
                        
            RecordType recordType = [select Id, Name from RecordType where SObjectType = 'Case' and Name = 'Support' LIMIT 1];
            
            System.Debug('CaseResolutionTimeTrigger: FETCHED RECORD TYPE: ' + recordType.Id );
            System.Debug('CaseResolutionTimeTrigger: RECORD TYPE IN CASE: ' + updatedCase.RecordType.Id );
            
            // Get old Case data. We are also only interested in Support Cases.
                 if (System.Trigger.oldMap.get(updatedCase.Id) != null /*&& updatedCase.RecordType == recordType*/ ) {
            
                Case oldCase = System.Trigger.oldMap.get(updatedCase.Id);            
                System.Debug('CaseResolutionTimeTrigger: OLD STATUS: ' + oldCase.Status);
                System.Debug('CaseResolutionTimeTrigger: NEW STATUS: ' + updatedCase.Status);
                  if (updatedCase.Date_and_time_of_resolution__c!= null && updatedCase.Related_Setup__c != null && updatedCase.Resolution_time__c == null ||(oldCase.Date_and_time_of_resolution__c!= updatedCase.Date_and_time_of_resolution__c)) {
                    
                    // Related Setup
                    Setup__c relatedSetup = [select Id, Contract__c, Cost_Center__c, Name, Service_Availability__c from Setup__c where Id =: updatedCase.Related_Setup__c];
                    System.Debug('CaseResolutionTimeTrigger: Related Setup: ' + relatedSetup.Name);
                    
                    // Get BusinessHours from Setup -> Contract-> Contract(Agreement) -> Business Hours
                    ServiceAvailability saHelper = new ServiceAvailability();
                    Id hoursToUse = saHelper.GetHoursToUse(updatedCase, relatedSetup);
                    if(hoursToUse != null ) {                                       
                        System.debug('CaseResolutionTimeTrigger: HOURS TO USE: ' + hoursToUse);
                                        
                     //Double ResolutionTime = Initial_Response__c.GetTime() - Date_and_time_of_resolution__c.GetTime();
                     Double ResolutionTime = BusinessHours.diff(hoursToUse, updatedCase.Initial_Response__c,updatedCase.Resolution_time__c);
                     Double rmMins = resolutionTime / 60000.0;
                     Double rmHrs = resolutionTime / 60000.0 / 60;
                     Double rmDays = resolutionTime / 60000.0 / 60 / 24;
                        
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (ms): ' + resolutionTime);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (mins): ' + rmMins);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (hrs): ' + rmHrs);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (days): ' + rmDays);                     
                        
                     updatedCase.Resolution_time__c = rmMins;
                     // update updatedCase
                     
                  } else {
                        
                     System.Debug('SETUP NOT FOUND: ' + updatedCase.Related_Setup__c);
                   }
                }
            }
        }
    }
}

  • October 03, 2013
  • Like
  • 0