+ Start a Discussion
ehartyeehartye 

Assign solution category based on custom case dropdown

Sooo... you'll probably be able to tell by my crazy code that I've been round and round with this one, but all I want to do is assign a solution category based on the user's drop-down selection on the originating case. I ensure the dropdown selections always correspond with a solution category using a seperate process.

 

The dropdown field is "feature_area__c". 

 

My test code all passes fine, but when I execute this, I get the awesome "An error has occurred while processing your request."

 

 

public static void AssignSolutionCategory(solution[] solutions)
{
Map<Id,string> solutionCaseMap = New Map<Id,string>();
List<string> solutionIdList = New List<string>();
for (CaseSolution cs : [Select SolutionId,CaseId from casesolution where SolutionId in :solutions])
{

//I do this to ensure I only have one case match per solution
if (solutionCaseMap.containsKey(cs.SolutionId)==false)
{
solutionCaseMap.put(cs.SolutionId,cs.CaseId);
solutionIdList.add(cs.SolutionId);
}
}
If (solutionCaseMap.size() > 0)
{
Map<Id,string> caseFeatureAreaMap = New Map<id, string>();
for (Case c : [Select Id,Feature_Area__c from case where id in (Select CaseId from casesolution where SolutionId in :solutionCaseMap.keySet())])
{
caseFeatureAreaMap.put(c.id, c.Feature_Area__c);
}
List<CategoryNode> categoryNodeList = New List<CategoryNode>();
for (CategoryNode cn : [Select Id,MasterLabel from categorynode])
{
categoryNodeList.add(cn);
}
List<CategoryData> category = New List<CategoryData>();
for (integer x = 0; x < categoryNodeList.size(); x++)
{
for (integer i = 0; i < solutionIdList.size(); i++)
{
If (caseFeatureAreaMap.get(solutionCaseMap.get(solutionIdList[i])) == categoryNodeList[x].MasterLabel)
{
CategoryData cd = new CategoryData();
cd.CategoryNodeId = categoryNodeList[x].id;
cd.RelatedSobjectId = solutionIdList[i];
category.add(cd);
}
}
}
insert category;
}

}

 

 P.S. -- What's the trick to pasting code into a post without all the formatting screwing up?? Woot figured it out! Firefox good, Chrome bad :P

Message Edited by ehartye on 06-15-2009 08:14 PM
Message Edited by ehartye on 06-15-2009 08:17 PM
Message Edited by ehartye on 06-15-2009 08:20 PM
Message Edited by ehartye on 06-15-2009 08:26 PM
XactiumBenXactiumBen

for (CaseSolution cs : [Select SolutionId,CaseId from casesolution where SolutionId in :solutions])

 

Doesn't the in keyword require a set of Ids, not a list of solutions?

 

 

Try doing this to see if it solves your issue:

 

 

Set<Id> solutionIds = new Set<Id>(); for (Solution s : solutions) solutionIds.add(s.Id); for (CaseSolution cs : [Select SolutionId,CaseId from casesolution where SolutionId in :solutionIds])

 

ehartyeehartye
Thanks for the great suggestion! No luck, however :(
ehartyeehartye

After tweaking some test code, I was able to get it to error when it tries to insert the CategoryData.

 

I've seen this error message on other posts about a bug that was supposed to be fixed. Has anyone ever seen this?

 

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>.

 

In case it matters, I'm calling this code with an after insert trigger on solutions. I get the same behavior when I test it as an after update. 

ehartyeehartye

Things have gotten a little better. After fixing an error in my test code, I was able to deploy this as an after update script on solutions. It works very well.

 

I would prefer to do it as an after insert, but when I try, I still get the white-screen-of-death  "An error has occurred while processing your request." message.

 

Any thoughts?