You need to sign in to do that
Don't have an account?

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());
}
}
(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?
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
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()); }
}
You need to add this line before the insert:
testCase.setOptions(dmo);
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
Put this:
Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true;
inside your
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.
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; }
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()); }
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.
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>
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?
There appears to be a bug with DMLOptions and case assignment rules right now.