+ Start a Discussion
ehartyeehartye 

Need suggestions - Trigger on CaseSolution

Those of you familiar with the table structure for Cases and Solutions know that the CaseSolution table is used to allow a many-to-many relationship.

 

I'm trying to trigger apex when the user adds a solution or removes one from the case. The problem is that you can do this without editing the case or the solution. You also cannot trigger on the CaseSolution SObject.

 

Does anyone have a suggestion for triggering on this event? 

Best Answer chosen by Admin (Salesforce Developers) 
snugglessnuggles

One option:  Try overriding the case view page with a custom VF page that immediately redirects to the regular case detail page with the override=1 parameter so it goes to the standard page layout.  You will notice that the solution attachment function is broken.  Stick with me here.. 

 

<apex:page standardController="Case" extensions="caseOverrideController" action="{!caseRedirect}">

</apex:page>
public class caseOverrideController2 {
private final Id caseId;
public caseOverrideController2(ApexPages.StandardController controller) {
caseId = controller.getRecord().Id;
}
public pageReference caseRedirect(){
return new PageReference('/' + caseId +'?nooverride=1');
}
}

 

 If you alter your code to pass along the "a_case_soln" parameter like this:

 

public class caseOverrideController {
     private final Id caseId;
     public caseOverrideController(ApexPages.StandardController controller) {
         caseId = controller.getRecord().Id;
     }
     public pageReference caseRedirect(){
        if (ApexPages.CurrentPage().getParameters().containsKey('a_case_soln'))
              return new pageReference('/'+caseId+'?nooverride=1&a_case_soln='+ApexPages.CurrentPage().getParameters().get('a_case_soln'));

 

else return new pageReference('/'+caseId+'?nooverride=1');
}
}

 

 

Then it will attach your solution to the case!

 

You could then do whatever you like from within the controller.

 

This will only work for solutions attached through the UI though, since it's a VF solution.

Message Edited by snuggles on 08-05-2009 04:00 PM

All Answers

snugglessnuggles

One option:  Try overriding the case view page with a custom VF page that immediately redirects to the regular case detail page with the override=1 parameter so it goes to the standard page layout.  You will notice that the solution attachment function is broken.  Stick with me here.. 

 

<apex:page standardController="Case" extensions="caseOverrideController" action="{!caseRedirect}">

</apex:page>
public class caseOverrideController2 {
private final Id caseId;
public caseOverrideController2(ApexPages.StandardController controller) {
caseId = controller.getRecord().Id;
}
public pageReference caseRedirect(){
return new PageReference('/' + caseId +'?nooverride=1');
}
}

 

 If you alter your code to pass along the "a_case_soln" parameter like this:

 

public class caseOverrideController {
     private final Id caseId;
     public caseOverrideController(ApexPages.StandardController controller) {
         caseId = controller.getRecord().Id;
     }
     public pageReference caseRedirect(){
        if (ApexPages.CurrentPage().getParameters().containsKey('a_case_soln'))
              return new pageReference('/'+caseId+'?nooverride=1&a_case_soln='+ApexPages.CurrentPage().getParameters().get('a_case_soln'));

 

else return new pageReference('/'+caseId+'?nooverride=1');
}
}

 

 

Then it will attach your solution to the case!

 

You could then do whatever you like from within the controller.

 

This will only work for solutions attached through the UI though, since it's a VF solution.

Message Edited by snuggles on 08-05-2009 04:00 PM
This was selected as the best answer
ehartyeehartye

Thank you for the quick and detailed reply.

 

I wound up doing something very similar. Rather than override the Case View page, I used an embedded visual force page on the page layout.