You need to sign in to do that
Don't have an account?
Andrew G
Using List contains does detect Id
Hello
I'm doing a bit of code where I'm checking if a Work Type Id in a Work Order is in a List for Work Type Ids, but the contains method does not seem to be detecting the match:
Code snippet
So, the debug shows that the Ids are apparently the same, but the IF statement using the the contains does resolve to TRUE.
Any thoughts on what I am missing?
Regards
Andrew
I'm doing a bit of code where I'm checking if a Work Type Id in a Work Order is in a List for Work Type Ids, but the contains method does not seem to be detecting the match:
Code snippet
List<ServiceAppointment> svcAppts = new List<ServiceAppointment>(); //List of Ids where their is an auto generate feature enabled List<Id> listWorkTypeIds = new List<Id>(); for ( WorkType wt : [SELECT Id FROM WorkType WHERE ShouldAutoCreateSvcAppt = TRUE] ) { listWorkTypeIds.add(wt.Id); } System.debug('DEBUG : Worktype count ' + listWorkTypeIds.size()); for ( WorkOrder workOrder : workOrders ) { tempDecimal = workOrder.Crew_Size__c; crewSize = tempDecimal.intValue(); System.debug('DEBUG : crewSize: ' + crewSize); tempDecimal = workOrder.ServiceAppointmentCount; System.debug('DEBUG : RAW service count : ' + tempDecimal); System.debug('****DEBUG : list work type : ' + listWorkTypeIds[0]); System.debug('****DEBUG : WO work type : ' + workOrder.workTypeId); if (listWorkTypeIds.contains(workOrder.workTypeId)) { apptCount = tempDecimal.intValue() + 1; System.debug('DEBUG : ADJUSTED service count : ' + tempDecimal); } else { apptCount = tempDecimal.intValue(); System.debug('DEBUG : SAME service count : ' + tempDecimal); }Now, the debug looks like this:
08:10:49.875 (1834107162)|SOQL_EXECUTE_BEGIN|[92]|Aggregations:0|SELECT Id FROM WorkType 08:10:49.875 (1848717624)|SOQL_EXECUTE_END|[92]|Rows:1 08:10:49.875 (1849133376)|USER_DEBUG|[95]|DEBUG|DEBUG : Worktype count 1 08:10:49.875 (1849315483)|USER_DEBUG|[101]|DEBUG|DEBUG : crewSize: 1 08:10:49.875 (1849418406)|USER_DEBUG|[104]|DEBUG|DEBUG : RAW service count : 0 08:10:49.875 (1849462073)|USER_DEBUG|[105]|DEBUG|****DEBUG : list work type : 08q0l00000001jtAAA 08:10:49.875 (1849543426)|USER_DEBUG|[106]|DEBUG|****DEBUG : WO work type : 08q0l00000001jtAAA 08:10:49.875 (1849692808)|USER_DEBUG|[113]|DEBUG|DEBUG : SAME service count : 0
So, the debug shows that the Ids are apparently the same, but the IF statement using the the contains does resolve to TRUE.
Any thoughts on what I am missing?
Regards
Andrew
would have thought Ids would have worked.
Cheers to me
All Answers
would have thought Ids would have worked.
Cheers to me
Now, the weirdest part of all this for me was; if I added a debug line somewhere that just referenced the list variable name, everything worked fine. For example, if you are experiencing the same issue as I did, if you put System.Debug(listWorkTypeIds); between line 4 and line 5 in your original code above, I bet your code will work with the List<Id>. If you get a chance, try it, and let me know if that works for you. Now of course, adding a debug line to fix code is not a great idea, which is why I like changing the method to return a String rather than a List<Id>, that's what I did to get around this issue. Also, I tried List<String> and List<Object> and still had the same problem, but again, the debug line made it work every time.