You need to sign in to do that
Don't have an account?
Help with code
Hi folks,
Here is the code for my task but it's nt working, here is my task, if you go to solutions in case realated list, and when you click on find solutions and select any solution then it gets attached to the case and the casecontact gets the solution as an email, iam not able to figure out what needs to be done in this code to get executed, can anyone help me out with this please.
trigger solutionInsert on Solution (after insert) {
List<Id> sIdList;
Map<Id,String> userMap = new Map<Id,String>();
Map<Id,Id> caseMap = new Map<Id,Id>();
for(Solution s:Trigger.New)
{
sIdList.add(s.id);
}
if(sIdList.size()>0)
{
List<Case> cList = [select c.id,c.Owner.Email,c.Owner.Name,c.OwnerId,(select cs.caseId,cs.SolutionId from CaseSolutions cs) from Case c where c.id in:sIdList limit 1];
for(Case c:cList)
{
userMap.put(c.OwnerId,c.Owner.Email);
}
for(Solution s: Trigger.New)
{
Id sId = s.Id;
Id oId = caseMap.get(sId);
String emailId = userMap.get(oId);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {emailId};
mail.setToAddresses(toAddresses);
}
}
}
You code is going to fire when you create a Solution, not attach one to a Case.
If you're trying to trigger the email as soon as the solution is attached, you should be triggering on the CaseSolution object, not the Solution object. CaseSolution is a union object between Case and Solution.
That said, I'm not sure if that allows triggers, so you'll have to check. If so, the flow would be like this:
I have a feeling that won't work.
You can't create a trigger on CaseSolution.
And I don't believe that a trigger on Solution will execute when a Solution is added into a Case.