0

In my org, Case OWD is Private and Case has two child objects (Transaction1 and Transaction2) whose OWD is Private too.

Transaction-1 and Transaction-2 object has lookup relationship with Case.

I have a single form, in that form fields are from the Case Object and Transaction-1 object. When I submit the form, naturally Case record will save first and then Transaction-1 means child object will save later.

This is happening through custom VF Page. On the save method. I am calling assignment rules only after both the Parent child records saved.

1) When Case is submitted to Queue, original requestor should get the read access and Queue should become the Owner of the case.

The problem which I see before trigger we can't changed the Ownership of the case and after insert we dont have the way to identify who was the original requestor for the case.

On Case object, I created some out of the Share Rule, if record type is refund, those case should be shared with Group-ABC and Group-XYZ in Edit mode.

But I am struggling to replicate very same on the child object. So what I did

1) First Insert Case and Child record

2) Then Call Assignment Rules

3) Again update the case record in the same saved method.

If I do this, then I can see Apex Sharing is replicating properly on the child object as well without any Custom Apex Sharing logic.

Could someone please update what is happening ?

insert currentCase;

insert currentTransaction_1;

Database.DMLOptions dmlOptss = fetchAssignmentRule();
if(dmlOptss != NULL){
    currentCase.setOptions(dmlOptss);
}
update currentCase;

Here is the method

public Database.DMLOptions fetchAssignmentRule(){
    //Fetching the active case assignment rule
    AssignmentRule  AR = new AssignmentRule();
    AR = [SELECT id FROM AssignmentRule WHERE SobjectType = 'Case' AND Active = TRUE LIMIT 1];

    if(AR.Id != NULL)
    {
        //Creating the DMLOptions for "Assign using active assignment rules" checkbox
        Database.DMLOptions dmlOpts = new Database.DMLOptions();
        dmlOpts.assignmentRuleHeader.assignmentRuleId = AR.id;
        dmlOpts.emailHeader.triggerUserEmail = true;
        return dmlOpts;
    }
    return null;
}
  • What is your exact requirement? you have mentioned about your implementation, but that might be achieved by configuration itself – Santanu Boral Feb 24 '18 at 16:13
  • 2
    fetchAssignmentRule will throw an exception when there is no active case assignment rule. – sfdcfox Feb 24 '18 at 16:23

Your Answer

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

Browse other questions tagged or ask your own question.