• tyler_jennings
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies
I have a simple trigger that creates a tracking record every time the owning group changes (we call this escalation group).  The purpose is to have time tracking similar to how salesforces give you time in status for  service and support cases.  However, the trigger fails with an exception if there are more than 20 records in the new_entries set.   I can work around this, but my solutions  are  seriously kludgy.  Is there a better approach I'm missing?

-Tyler

Here is the code:

trigger recordStatusDates on Case (after update) {

  List<Case_Status_Log__c> new_entries = new List<Case_Status_Log__c>();

  for( integer i = 0; i < Trigger.new.size(); ++i) {

    if (Trigger.old[i].status != Trigger.new[i].status) {
      new_entries.add(Util.buildCaseStatusLog('Status', Trigger.new[i].id, Trigger.old[i].status, Trigger.old[i].status_changed__c, Trigger.new[i].status_changed__c));
    }
    if (Trigger.old[i].escalation_group__c != Trigger.new[i].escalation_group__c) {
      new_entries.add(Util.buildCaseStatusLog('Escalation_group',
          Trigger.new[i].id, Trigger.old[i].escalation_group__c,
          Trigger.old[i].escalation_group_changed__c, Trigger.new[i].escalation_group_changed__c));
    }
  }
  insert new_entries;
}

//Copied from Util
public static Case_Status_Log__c buildCaseStatusLog(String typeOf, Id id, String value, Datetime oldDate, Datetime newDate) {
      Case_Status_Log__c csl = new Case_Status_Log__c();
      csl.case__c = id;
      csl.value__c = value;
      csl.value_type__c = typeOf;
      csl.start_datetime__c = oldDate;
      csl.stop_datetime__c = newDate;
     
      if(oldDate != null && newDate != null) {
        csl.hours_in_state__c = util.hoursBetween(
                                   csl.start_datetime__c,
                                   csl.stop_datetime__c);
      }
      return csl;
  }
We have a simple trigger that takes the name of the owning group of a case and assigns that value to a field on the case for easy reporting & view creation. This trigger works fine in tests as well as for regular SFDC users. However, this trigger throws an exception when it is executed during the creation of a case from the customer portal.

The trigger:

Map queues =
new Map([select id, name from Group where type = 'Queue']);

for (Case ca : Trigger.new) {
if(queues.containsKey(ca.ownerId)) {
ca.escalation_group__c = queues.get(ca.ownerId).name;
}
}
}

The Customer Portal Exception:

Apex trigger updateEscalationGroup caused an unexpected exception, contact your administrator: updateEscalationGroup: compiling trigger body caused by: line 3, column 26: sObject type 'Group' is not supported.

From what I've read I thought apex code was not limited by the object access of the executing user. At first glance this does appear to be a permission issue, but I have not been able to find any way to effectively change it.

Thanks,

-Tyler
Someone tell me why this won't compile, I can see the LicenseType column in the apex explorer.  I can also run the below SOQL query fine (minus the where clause).

Code:
Profile p = [Select p.LicenseType from Profile p where id = :UserInfo.getProfileId()];
System.debug(p.LicenseType);

 

We have a requirement that a closed case should not be updatable by customer portal users, but still allow internal users to modify the case. 

I'm wondering how to test this since I must be able to switch the "current user" multiple times to assert all the different scenarios.  So far, It doesn't appear that this is possible. 

Secondly, am I going to have to jump through hoops to acheive 75% coverage in this case?
This trigger does _not_ save 'Hello!' to the Area__c field on the case, I can't figure out why.  There are no errors.  Here's the log output:

*** Beginning copyFieldsOnCreate on Case trigger event bulk AfterInsert for 500T0000000n9Tf

20070731134615.308:Trigger.copyFieldsOnCreate: line 1, column 1: TriggerBody: copyFieldsOnCreate
20070731134615.308:Trigger.copyFieldsOnCreate: line 2, column 3: SelectLoop:Static: name: Trigger.new, type: LIST:SOBJECT:Case
20070731134615.308:Trigger.copyFieldsOnCreate: line 2, column 31: Block with 3 statements
20070731134615.308:Trigger.copyFieldsOnCreate: line 6, column 5: DeclareVar: Local: name: c, type: SOBJECT:Case with initial value(s): InlineQuery: [select c.id, c.Area__c from Case c where c.Id = :ca.Id]
20070731134615.308:Trigger.copyFieldsOnCreate: line 6, column 14: SOQL query with 1 row finished in 13 ms
20070731134615.308:Trigger.copyFieldsOnCreate: line 6, column 5: initial value: Case:{Id=500T0000000n9TfIAI}
20070731134615.308:Trigger.copyFieldsOnCreate: line 7, column 5: SOBJECT:Case.Area__c assigned Literal: Hello!
20070731134615.308:Trigger.copyFieldsOnCreate: line 8, column 5: Update: SOBJECT:Case
20070731134615.308:Trigger.copyFieldsOnCreate: line 8, column 5: DML Operation executed in 352 ms

Cumulative resource usage:
Number of SOQL queries: 1 out of 20
Number of query rows: 1 out of 1000
Number of DML statements: 1 out of 20
Number of DML rows: 1 out of 100
Number of transaction control statements: 0 out of 0
Number of script statements: 3 out of 10200
Maximum heap size: 0 out of 100000


*** Ending copyFieldsOnCreate on Case trigger event bulk AfterInsert for 500T0000000n9Tf
Can anyone point out my flaw?

Thanks!

The examples for unit testing seem to be mixing the unit tests in with the domain classes.  I don't really like this, as I like to keep test classes separate from the domain classes being tested.  The problem seems to be that if you sepratate your test methods into test classes, Apex expects your test classes to be covered, which turns into an infinite loop. 

Can anyone share what they feel may be a clean and scalable way to do testing with Apex code?

thanks

Jeremy
Someone tell me why this won't compile, I can see the LicenseType column in the apex explorer.  I can also run the below SOQL query fine (minus the where clause).

Code:
Profile p = [Select p.LicenseType from Profile p where id = :UserInfo.getProfileId()];
System.debug(p.LicenseType);

 

This trigger does _not_ save 'Hello!' to the Area__c field on the case, I can't figure out why.  There are no errors.  Here's the log output:

*** Beginning copyFieldsOnCreate on Case trigger event bulk AfterInsert for 500T0000000n9Tf

20070731134615.308:Trigger.copyFieldsOnCreate: line 1, column 1: TriggerBody: copyFieldsOnCreate
20070731134615.308:Trigger.copyFieldsOnCreate: line 2, column 3: SelectLoop:Static: name: Trigger.new, type: LIST:SOBJECT:Case
20070731134615.308:Trigger.copyFieldsOnCreate: line 2, column 31: Block with 3 statements
20070731134615.308:Trigger.copyFieldsOnCreate: line 6, column 5: DeclareVar: Local: name: c, type: SOBJECT:Case with initial value(s): InlineQuery: [select c.id, c.Area__c from Case c where c.Id = :ca.Id]
20070731134615.308:Trigger.copyFieldsOnCreate: line 6, column 14: SOQL query with 1 row finished in 13 ms
20070731134615.308:Trigger.copyFieldsOnCreate: line 6, column 5: initial value: Case:{Id=500T0000000n9TfIAI}
20070731134615.308:Trigger.copyFieldsOnCreate: line 7, column 5: SOBJECT:Case.Area__c assigned Literal: Hello!
20070731134615.308:Trigger.copyFieldsOnCreate: line 8, column 5: Update: SOBJECT:Case
20070731134615.308:Trigger.copyFieldsOnCreate: line 8, column 5: DML Operation executed in 352 ms

Cumulative resource usage:
Number of SOQL queries: 1 out of 20
Number of query rows: 1 out of 1000
Number of DML statements: 1 out of 20
Number of DML rows: 1 out of 100
Number of transaction control statements: 0 out of 0
Number of script statements: 3 out of 10200
Maximum heap size: 0 out of 100000


*** Ending copyFieldsOnCreate on Case trigger event bulk AfterInsert for 500T0000000n9Tf
Can anyone point out my flaw?

Thanks!