You need to sign in to do that
Don't have an account?
Get number of solutions attached to a case - Need your help
Hello,
I'm trying to get the number of solutions attached to case (the goal is to be able to use a email template displaying the last added solution only with something like :
<apex:repeat first="{!relatedTo.nb_solutions__c-1}" value="{!relatedTo.CaseSolutions}" var="line">
<apex:outputText value="{!line.Solution.SolutionNote}" escape="false" />
</apex:repeat>).
Here is my code:
trigger CountSolution on Case (after update) { case.nb_solutions__c = [select casesolution.SolutionId from casesolution where caseID = :case.Id]; update case.nb_solutions__c; }
But I'm getting this error:
Save error: Invalid bind expression type of Schema.SObjectField for column of type Id CountSolution.trigger /Test Trigger/src/triggers line 2 Force.com save problem
I'm a "newbie", so any help or direction is appreciated. :smileyembarrassed:
Here is the final code and tricks :
Trigger
Test Class
Button "Quick Answer" (Update Case Status to "Closed" and update "nb_solutions__c"
All Answers
Try this :
Hope this helps..
Regards,
J
Hello J20,
Many thanks for your reply.
I tought it would work... but I got the exact same error testing your code:
Save error: Invalid bind expression type of Schema.SObjectField for column of type Id CountSolution.trigger /Test Trigger/src/triggers line 3 Force.com save problem
Other suggesstions are welcome.
Thanks again for your help!
Thank you.
Now, I'm getting a new error:
Description Resource Path Location Type
Save error: Initial term of field expression must be a concrete SObject: LIST<Case> CountSolution.trigger /Test Trigger/src/triggers line 3 Force.com save problem
I'm a newbie. :smileyembarrassed:
Thanks for you help!!
Where exactly you are getting the error ? on VF page or on Trigger ?
Try this but this will work on a single record and bulkify this code if you want to handle more than 1 record at a time :
Hello j020,
I'm using Eclipse to test the trigger and I'm having a new error :
Save error: Illegal assignment from LIST<CaseSolution> to String
(Also I tried to save it manually into my SFDC account but I got the same message)
Any idea why I'm getting this error?
About the query...
select casesolution.SolutionId from casesolution where caseID =:trigger.new.id
If I am not wrong you need a number to assign it to the case, right ?
But according to the query you are querying for solutionID ....
Can you modify it to select Count(ID) from casesolution where caseID =:trigger.new.id
Error in the first case :
Description Resource Path Location Type
Save error: Initial term of field expression must be a concrete SObject: LIST<Case> CountSolution.trigger /Test Trigger/src/triggers line 3 Force.com save problem
And I got the same error with :
My goal is to count the solutions attached to a case and add this value to a custom field in the case.
The code above might not be the best way to do these. Do you have a suggestion or another correction to add to the code?
Thanks you for your help!
Hope this works..
trigger CountSolution on Case (after update) {
Case objCase;
String strNum = String.ValueOf([select Count(ID) from casesolution where caseID =:Trigger.New[0].id]);
objCase.nb_solutions__c = strNum;
update objCase;
}
Sorry wasreplying earlier without accessing machines .....
Regards,
J
Hello,
I'm having a new error but we are close I'm sure:
Description Resource Path Location Type
Save error: Illegal assignment from String to Decimal CountSolution.trigger /Test Trigger/src/triggers line 4 Force.com save problem
Thank you again!!!
EDIT :
I found the solution and change the filed type of my custom field nb_solution__c from number to text.
It works!!!
Now, I'm trying to create the test class. I did one but that one convers only 56% of the trigger.
What could I add to this test class to reach at least 75%?
In addition, it seems the trigger is not totaly right, because when a email to case comes the case can't be created. May be because I forgot to add a condition in the trigger in case the "casesolution" doesn't exist (this will be the case for all new cases...). What do you think about that?
Here is the error that I received by email after I succed in saving the trigger :
or if I try to modifie a case and to save it :
Apex trigger CountSolution caused an unexpected exception, contact your administrator: CountSolution: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.CountSolution: line 4, column 1
That will be great if you could help me again!
Here is the final code and tricks :
Trigger
Test Class
Button "Quick Answer" (Update Case Status to "Closed" and update "nb_solutions__c"
Hi All,
When attache the solution form the case page, after update trigger is not triggered so how can we calculate the count. I want to achieve when attach the soution, send the email notification. how to achieve this please let me know.