• KDP
  • NEWBIE
  • 0 Points
  • Member since 2010

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

So, I've written triggers to set the value of a case owner's department field based on the queue name or the user department.  The triggers work just fine, including when I did a dataload to populate a different field.  Post upsert extract showed that the upsert initiated the trigger, which populated that department field for 68k records.

 

Unfortunately, I'm having problems getting the test class to complete.  It is returning a too many soql statements during a map statement that is before any processing loops.

 

The too many SOQL statements is occurring at the second map statement.

 

Trigger:

 

trigger Case_SetOwnerDept_Update on Case (before update) {
// When 'Owner' field is changed, update 'Case Owner's Department' too
Set <String> sUserIDs = new Set<String>();
Set <String> sQueueIDs = new Set<String>();
Set <String> sOwnerIDs = new Set<String>();

Map <String, User> mUsers = new Map<String,User>([Select ID, Department from User where ID in:sUserIDs]);
Map <String, Group> mGroups = new Map<String,Group>([Select ID, Name From Group where type='Queue' and ID in :sQueueIDs]);
Map<ID, Case> mCases = new Map<ID, Case>();

system.debug('mUser size: ' + mUsers.size());
system.debug('mGroupgs size: ' +mGroups.size());

For (Case c :trigger.new){
    String sOwner = c.ownerid;
    if(sOwner.substring(0,3)=='005'){
        sUserIDs.add(c.OwnerID);
    } else {
        sQueueIDs.add(c.OwnerID);
    }
}


//Now run through trigger again to populate department
For (Case c :trigger.new){
        Case oldCase = trigger.oldMap.get(c.Id);
        string oOwner = oldCase.Ownerid;
    if (c.ownerid != oldCase.ownerid){
        mCases.put(c.OwnerId, c);
    }
    String sOwner = c.ownerid;
        system.debug ('Old Case owner id: '+oOwner);
        system.debug ('New Case Owner id: '+sOwner);   
  {  
    if(sOwner.substring(0,3)=='005'){
        //String sOwner = c.OwnerID;    
        User oUser = mUsers.get(sOwner);
        if(oUser!=null){
            c.Case_Owners_Department__c=oUser.Department;
            system.debug('Set Owner Department user department: ' + c.Case_Owners_Department__c);
        }
    } else {
        String sGroup = c.OwnerID;
        Group oGroup = mGroups.get(sGroup);
        if(oGroup!=null){
            c.Case_Owners_Department__c=oGroup.name;
            system.debug('Set Owner Department as queue name: ' + c.Case_Owners_Department__c);
        }
    }
}
}
}

 

Any thoughts would be appreciated since I was scheduled to put this into production today, and if I can't work this out...

  • October 23, 2010
  • Like
  • 0

I can and have set up validation on the detail record that prevents it from saving if its master record is not at a particular status; however, I would prefer that the New button on the related list be either hidden or return an alert based on master record status.

 

Ex.

 

Projects - master with action items - detail

 

New Action item should not be created unless project is approved.  I can prevent action item creation with object validation, but from a user perspective, it makes more sense if the button on the related list is hidden until project=approved, or  if clicking New returns an alert that master status must be xxx.

 

Can this be done with custom button using formula?  

 

Or will it require javascript or a trigger?

 

Thank you.

 

 

  • February 17, 2010
  • Like
  • 0

HI - I've installed the stand-alone Force.com IDE.  And when the IDE tries to start, I get the following error, which I cannot get past:

 

 

---------------------------
Forceide
---------------------------
JVM terminated. Exit code=-1
-Dfile.encoding=UTF-8
-Xms256m
-Xmx1024m
-XX:PermSize=128M
-XX:MaxPermSize=512M
-Djava.class.path=C:\Program Files\salesforce.com\Force.com IDE\../Common/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
-os win32
-ws win32
-arch x86
-showsplash
-launcher C:\Program Files\salesforce.com\Force.com IDE\forceide.exe
-name Forceide
--launcher.library C:\Program Files\salesforce.com\Force.com IDE\../Common/plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519\eclipse_1206.dll
-startup C:\Program Files\salesforce.com\Force.com IDE\../Common/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
-install C:\Program Files\salesforce.com\Force.com IDE
-configuration C:\Program Files\salesforce.com\Force.com IDE\configuration
-vm C:\Program Files\Java\jre6\bin\client\jvm.dll
-vmargs
-Dfile.encoding=UTF-8
-Xms256m
-Xmx1024m
-XX:PermSize=128M
-XX:MaxPermSize=512M
-Djava.class.path=C:\Program Files\salesforce.com\Force.com IDE\../Common/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
---------------------------
OK   
---------------------------

 

Any ideas anyone? 

 

I have uninstalled previous Java versions, and installed the latest Java runtime.

 

2nd machine this happened on.