function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MATTYBMEMATTYBME 

My Case VF Create New page is causing our Assignement rules to fail

Ok I have this code running on our Customer Portal to create a New Case:

 

 

<apex:page standardController="case" extensions="CustomerPortalNewCaseExtension" tabstyle="trouble_tickets__tab">
<apex:sectionHeader title="Trouble Tickets" subtitle="New Trouble Ticket"/>
<apex:form >
<apex:pageBlock title="New Trouble Ticket">
<apex:pageBlockButtons >
<apex:commandButton action="{!viewSuggestionSave}" value="Submit" />
<apex:commandButton action="{!viewSuggestionSaveAdd}" value="Submit & Add Attachment" />
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Trouble Ticket Details" columns="1">
<apex:inputField value="{!case.priority}" required="true"/>
<apex:outputField value="{!case.status}">
<apex:outputText ><font style="color:red">New</font></apex:outputText>
</apex:outputField>
<apex:inputField value="{!case.subject}" required="true" style="width: 400px;"/>
<apex:inputField value="{!case.description}" required="true" style="width: 700px; height: 100px;"/>
<apex:outputField value="{!case.Resolution__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockSection >
<c:CaseQuickTipsGuideComponent />
<c:CaseAttachmentsInstructions />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

with this extension:

 

 

public class CustomerPortalNewCaseExtension {

private ApexPages.StandardController controller;
private Case c;
public CustomerPortalNewCaseExtension(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference viewSuggestionSave() {
controller.save();
c = (Case)controller.getRecord();
return new PageReference('/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1');
}
public PageReference viewSuggestionSaveAdd() {
controller.save();
c = (Case)controller.getRecord();
return new PageReference('/p/attach/NoteAttach?pid=' + c.Id + '&retURL=/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1');
}
static testMethod void testCustomerPortalNewCaseExtension() {
Case testCase = new Case();
testCase.Subject = 'Test Subject';
testCase.Priority = 'Medium';
testCase.Description = 'Test Description';
insert testCase;

ApexPages.StandardController caseController = new ApexPages.standardController(testCase);
CustomerPortalNewCaseExtension caseExt = new CustomerPortalNewCaseExtension(caseController);
PageReference theRef = caseExt.viewSuggestionSave();
System.AssertEquals('/ui/solution/SolutionSuggestionPage?autoredirected=1&caseid=' + testCase.Id,theRef.getUrl());

theRef = caseExt.viewSuggestionSaveAdd();
System.AssertEquals('/p/attach/NoteAttach?autoredirected=1&pid=' + testCase.Id + '&retURL=%2Fui%2Fsolution%2FSolutionSuggestionPage%3Fcaseid%3D' + testCase.Id,theRef.getUrl());

}
}

 

 

 

MATTYBMEMATTYBME

(Continued)

 

Why would our Assignment rules not run? This is what I recieved from Salesforce Support when I troubleshooted this:


I turned on your debug logs and
logged a test case for your test Contact. I went back to the debug logs
and it looks like you have some custom code overwriting some info that
is necessary for the Assignment rules to read that this is a Portal
User submitting a case.

If you look at the debug logs,
Assignment rules didn't even run on this case, only Workflow and
Validation. Further, if you look at the third log for Mathusala, you
will see:

***Begining Page Log for /apex/CustomerPortalNewCase

20090128212517.601:External
entry point:     returning from end of method public
CustomerPortalNewCaseExtension<Constructor>(ApexPages.StandardController)
in 0 ms

Cumulative profiling information:

No profiling information for SOQL operations.

No profiling information for SOSL operations.

No profiling information for DML operations.

1 most expensive method invocations:

Class.CustomerPortalNewCaseExtension:
line 5, column 12: public
CustomerPortalNewCaseExtension<Constructor>(ApexPages.StandardController):
executed 1 time in 0 ms

So it looks to me like you're
overwriting something with the new case creation on the Self Service
Portal. We don't support code, so I'm not qualified to tell you what
exactly here is causing the Assignment Rules not to fire, but I can
refer you to our Developer Support forums for more information on
getting the Assignment Rules to work with the code you have in place.


 

Why would Workflow and Validation rules run but Assignment rules not?

TehNrdTehNrd

Ability to invoke assignment rules has been released with Spring '09:

 

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_database_dmloptions.htm?SearchType=Stem

MATTYBMEMATTYBME

Any reason why Workflow and Validation rules still run and Assignment don't? And not available until the Spring 09 release? 

 

Thanks for the reference to the developer manual. I am assuming that I can just use the example given?

  

Database.DMLOptions dmo = new Database.DMLOptions();dmo.assignmentRuleHeader.useDefaultRule= true;

 If this is so I am assuming I should be able to place it in my existing extension correct? Something like:

 

 

public class CustomerPortalNewCaseExtension {

 

private ApexPages.StandardController controller;

private Case c;

public CustomerPortalNewCaseExtension(ApexPages.StandardController controller) {

this.controller = controller;

}

public PageReference viewSuggestionSave() {

controller.save();

c = (Case)controller.getRecord();

return new PageReference('/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1'); }

public PageReference viewSuggestionSaveAdd() {

controller.save();

c = (Case)controller.getRecord();

return new PageReference('/p/attach/NoteAttach?pid=' + c.Id + '&retURL=/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1');

}

Database.DMLOptions dmo = new Database.DMLOptions();

dmo.assignmentRuleHeader.useDefaultRule= true;

}

static testMethod void testCustomerPortalNewCaseExtension() {

Case testCase = new Case();

testCase.Subject = 'Test Subject';

testCase.Priority = 'Medium';

testCase.Description = 'Test Description';

insert testCase;

 

ApexPages.StandardController caseController = new ApexPages.standardController(testCase); CustomerPortalNewCaseExtension caseExt = new CustomerPortalNewCaseExtension(caseController); PageReference theRef = caseExt.viewSuggestionSave(); System.AssertEquals('/ui/solution/SolutionSuggestionPage?autoredirected=1&caseid=' + testCase.Id,theRef.getUrl());

 

theRef = caseExt.viewSuggestionSaveAdd();

System.AssertEquals('/p/attach/NoteAttach?autoredirected=1&pid=' + testCase.Id + '&retURL=%2Fui%2Fsolution%2FSolutionSuggestionPage%3Fcaseid%3D' + testCase.Id,theRef.getUrl()); }

}

 

Message Edited by MATTYBME on 01-29-2009 04:39 AM
TehNrdTehNrd

You need to add this line before the insert:

testCase.setOptions(dmo);

 


 

MATTYBMEMATTYBME

 

 

public class CustomerPortalNewCaseExtension { private ApexPages.StandardController controller; private Case c; public CustomerPortalNewCaseExtension(ApexPages.StandardController controller) { this.controller = controller; } public PageReference viewSuggestionSave() { controller.save(); c = (Case)controller.getRecord(); return new PageReference('/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1'); } public PageReference viewSuggestionSaveAdd() { controller.save(); c = (Case)controller.getRecord(); return new PageReference('/p/attach/NoteAttach?pid=' + c.Id + '&retURL=/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1'); } Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule= true; } static testMethod void testCustomerPortalNewCaseExtension() { Case testCase = new Case(); testCase.Subject = 'Test Subject'; testCase.Priority = 'Medium'; testCase.Description = 'Test Description'; testCase.setOptions(dmo); insert testCase; ApexPages.StandardController caseController = new ApexPages.standardController(testCase); CustomerPortalNewCaseExtension caseExt = new CustomerPortalNewCaseExtension(caseController); PageReference theRef = caseExt.viewSuggestionSave(); System.AssertEquals('/ui/solution/SolutionSuggestionPage?autoredirected=1&caseid=' + testCase.Id,theRef.getUrl()); theRef = caseExt.viewSuggestionSaveAdd(); System.AssertEquals('/p/attach/NoteAttach?autoredirected=1&pid=' + testCase.Id + '&retURL=%2Fui%2Fsolution%2FSolutionSuggestionPage%3Fcaseid%3D' + testCase.Id,theRef.getUrl()); } }

 

 

 

Recieving a:

 

 Error: Compile Error: unexpected token: dmo.assignmentRuleHeader.useDefaultRule at line 19 column 5

Message Edited by MATTYBME on 01-29-2009 10:00 AM
TehNrdTehNrd

Put this:

 

 

Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true;

 inside your

testCustomerPortalNewCaseExtension() 
 

 

MATTYBMEMATTYBME

Arrgh the new code insert reformats the code. Very frustrating. So I did the insert so it now looks like this:

 

 

public class CustomerPortalNewCaseExtension { private ApexPages.StandardController controller; private Case c; public CustomerPortalNewCaseExtension(ApexPages.StandardController controller) { this.controller = controller; } public PageReference viewSuggestionSave() { controller.save(); c = (Case)controller.getRecord(); return new PageReference('/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1'); } public PageReference viewSuggestionSaveAdd() { controller.save(); c = (Case)controller.getRecord(); return new PageReference('/p/attach/NoteAttach?pid=' + c.Id + '&retURL=/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1'); } Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule= true; } static testMethod void testCustomerPortalNewCaseExtension() { Case testCase = new Case(); testCase.Subject = 'Test Subject'; testCase.Priority = 'Medium'; testCase.Description = 'Test Description'; testCase.setOptions(dmo); insert testCase; Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true; ApexPages.StandardController caseController = new ApexPages.standardController(testCase); CustomerPortalNewCaseExtension caseExt = new CustomerPortalNewCaseExtension(caseController); PageReference theRef = caseExt.viewSuggestionSave(); System.AssertEquals('/ui/solution/SolutionSuggestionPage?autoredirected=1&caseid=' + testCase.Id,theRef.getUrl()); theRef = caseExt.viewSuggestionSaveAdd(); System.AssertEquals('/p/attach/NoteAttach?autoredirected=1&pid=' + testCase.Id + '&retURL=%2Fui%2Fsolution%2FSolutionSuggestionPage%3Fcaseid%3D' + testCase.Id,theRef.getUrl()); } }

 Still gettting the error.

 

 

TehNrdTehNrd

This saves and executes fine for me:

static testMethod void testCustomerPortalNewCaseExtension() { Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true; Case testCase = new Case(); testCase.Subject = 'Test Subject'; testCase.Priority = 'Medium'; testCase.Description = 'Test Description'; testcase.setOptions(dmo); insert testCase; }

 


 

MATTYBMEMATTYBME

So thefull extension being:

 

 

public class CustomerPortalNewCaseExtension { private ApexPages.StandardController controller; private Case c; public CustomerPortalNewCaseExtension(ApexPages.StandardController controller) { this.controller = controller; } public PageReference viewSuggestionSave() { controller.save(); c = (Case)controller.getRecord(); return new PageReference('/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1'); } public PageReference viewSuggestionSaveAdd() { controller.save(); c = (Case)controller.getRecord(); return new PageReference('/p/attach/NoteAttach?pid=' + c.Id + '&retURL=/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1'); } Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule= true; } static testMethod void testCustomerPortalNewCaseExtension() { Case testCase = new Case(); testCase.Subject = 'Test Subject'; testCase.Priority = 'Medium'; testCase.Description = 'Test Description'; testCase.setOptions(dmo); insert testCase; Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true; ApexPages.StandardController caseController = new ApexPages.standardController(testCase); CustomerPortalNewCaseExtension caseExt = new CustomerPortalNewCaseExtension(caseController); PageReference theRef = caseExt.viewSuggestionSave(); System.AssertEquals('/ui/solution/SolutionSuggestionPage?autoredirected=1&caseid=' + testCase.Id,theRef.getUrl()); theRef = caseExt.viewSuggestionSaveAdd(); System.AssertEquals('/p/attach/NoteAttach?autoredirected=1&pid=' + testCase.Id + '&retURL=%2Fui%2Fsolution%2FSolutionSuggestionPage%3Fcaseid%3D' + testCase.Id,theRef.getUrl()); }

 

 works for you? Wierd. I still get the

 

 

 

 Error: Compile Error: unexpected token: dmo.assignmentRuleHeader.useDefaultRule at line 19 column 5
TehNrdTehNrd
You need to declar the DML options object before you can use it.


}
static testMethod void testCustomerPortalNewCaseExtension() {
Case testCase = new Case();
testCase.Subject = 'Test Subject';
testCase.Priority = 'Medium';
testCase.Description = 'Test Description';

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
testCase.setOptions(dmo);
insert testCase;

ApexPages.StandardController caseController = new ApexPages.standardController(testCase);
CustomerPortalNewCaseExtension caseExt = new CustomerPortalNewCaseExtension(caseController);
PageReference theRef = caseExt.viewSuggestionSave();
System.AssertEquals('/ui/solution/SolutionSuggestionPage?autoredirected=1&caseid=' + testCase.Id,theRef.getUrl());

theRef = caseExt.viewSuggestionSaveAdd();
System.AssertEquals('/p/attach/NoteAttach?autoredirected=1&pid=' + testCase.Id + '&retURL=%2Fui%2Fsolution%2FSolutionSuggestionPage%3Fcaseid%3D' + testCase.Id,theRef.getUrl());

}

MATTYBMEMATTYBME

Ok this saves as the static testmethod but is not part of the actual extension. Meaning it saves looking like this:

 

public class CustomerPortalNewCaseExtension { private ApexPages.StandardController controller; private Case c; public CustomerPortalNewCaseExtension(ApexPages.StandardController controller) { this.controller = controller; } public PageReference viewSuggestionSave() { controller.save(); c = (Case)controller.getRecord(); return new PageReference('/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1'); } public PageReference viewSuggestionSaveAdd() { controller.save(); c = (Case)controller.getRecord(); return new PageReference('/p/attach/NoteAttach?pid=' + c.Id + '&retURL=/ui/solution/SolutionSuggestionPage?caseid=' + c.Id + '&autoredirected=1'); } static testMethod void testCustomerPortalNewCaseExtension() { Case testCase = new Case(); testCase.Subject = 'Test Subject'; testCase.Priority = 'Medium'; testCase.Description = 'Test Description'; Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true; testCase.setOptions(dmo); insert testCase; ApexPages.StandardController caseController = new ApexPages.standardController(testCase); CustomerPortalNewCaseExtension caseExt = new CustomerPortalNewCaseExtension(caseController); PageReference theRef = caseExt.viewSuggestionSave(); System.AssertEquals('/ui/solution/SolutionSuggestionPage?autoredirected=1&caseid=' + testCase.Id,theRef.getUrl()); theRef = caseExt.viewSuggestionSaveAdd(); System.AssertEquals('/p/attach/NoteAttach?autoredirected=1&pid=' + testCase.Id + '&retURL=%2Fui%2Fsolution%2FSolutionSuggestionPage%3Fcaseid%3D' + testCase.Id,theRef.getUrl()); } }

 

 

Therefore it will not fire this assignment rule correct? I have tried it and the assignment rule is not working.

TomSnyderTomSnyder
Has anyone been successful triggering asignment rules via DMLOptions?
 
I have a similar issue: 
 
 
MATTYBMEMATTYBME
Ok as an addendum to this I am doing this in my Sandbox environment that is now in Spring 09 release.
TomSnyderTomSnyder

I got my to compile,  mine was a customcontroller not an extention.  However,  it didn't trigger the rule.  

 

Check metadata to be sure your extention is using version 15?

 

 

 

<?xml version="1.0" encoding="UTF-8"?><ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>15.0</apiVersion> <status>Active</status></ApexClass>

 

 

 

glorgeglorge

I'm also unable to get Case assignment rules to trigger using the following idioms:

 

 

Case myCase = new Case();

// do assignment... 

Database.DMLOptions dmo = new Database.DMLOptions();

dmo.assignmentRuleHeader.useDefaultRule= true;

myCase.setOptions(dmo);

insert myCase;

 

 

Case myCase = new Case();

// do assignment...

Database.DMLOptions dmo = new Database.DMLOptions();

dmo.assignmentRuleHeader.useDefaultRule= true;

myCase.setOptions(dmo);

Database.insert(myCase, dmo);

 

 I also tried using the dmo.assignmentRuleHeader.assignmentRuleId=<id> method.

 

Has anyone successfully triggered assignment rules with these options?

 


 

Message Edited by glorge on 02-25-2009 09:26 PM
Message Edited by glorge on 02-25-2009 09:26 PM
werewolfwerewolf

There appears to be a bug with DMLOptions and case assignment rules right now.