4

So I have some code that creates a case. The case is assigned a RecordTypeId before the insert.

When I test this, instead of the ID assigned in the code - the RecordTypeId is the default type specified in the user profile.

I have no idea why this is happening. I can see the Assignment Rule assign the case based on the RecordTypeID. this shows the correct ID. However, a few WF_Rule evaluations below the RecordTypeID has changed. There's nothing in between that is changing the RecordTypeID.

So I'm stuck. Only thing I can think of is I may have inadvertently created two instances of the same record which is causing confusion. I'm not sure how that would be happening.

I'm using an Extension of the standard Case Controller and a custom Save method.

Here's some snippets:

private final Case mycase;
public Research_Request_Ext(ApexPages.StandardController controller) {
     this.mycase = (Case) controller.getrecord();
     newCase();
}

public void newCase() {
     RecordType ResearchRecordType = [SELECT Description, DeveloperName, Id, IsActive, Name, SobjectType FROM RecordType WHERE DeveloperName = 'Research_Request'
      AND SobjectType = 'Case'
      and IsActive = true
     ];
     this.mycase.RecordTypeId = ResearchRecordType.id;
}

public PageReference MySave() {
    AssignmentRule AR = new AssignmentRule(); //Assignment Rule Query
    AR = [select id from AssignmentRule where SobjectType = 'Case'
     and Active = true limit 1
     ];
    //Creating DML Options
    Database.DMLOptions dmlOpts = new Database.DMLOptions();
    PageReference NewPage = Page.Research_Request;
    string mode = ApexPages.currentPage().getParameters().get('mode');
    boolean ContainsErrors = false;
    system.debug('Saved is being called!');
    if (AR != null) {
        dmlOpts.assignmentRuleHeader.assignmentRuleID = AR.ID;
        mycase.setOptions(dmlOpts);
        mycase.description = mycase.description + '\n On Insert: ' + MyCase.RecordTypeID;
        insert mycase;

        NewPage.getParameters().put('id', mycase.id);
        NewPage.getParameters().put('mode', 'View');
        return NewPage.setRedirect(true)

    }
}
5

Thanks to Robert Cruz ‏@Bob_Cruz_ on Twitter for answering this.

The Support Settings for cases has an option to override existing record type with the assignee's default record type.

That was causing the issue. Flipping that to "Keep the existing record type" fixes the problem

  • Ca_peterson was planning on it but stackexchange doesn't allow me to accept my own answer until after 2 days of posting. I got 6 more hours to wait – Salesforce Wizard Sep 27 '12 at 13:05
  • Learn something new everyday. Pardon my nagging then. – ca_peterson Sep 27 '12 at 15:59
  • Hey that's not nagging. You were just trying to improve the community site. – Salesforce Wizard Sep 27 '12 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.