You need to sign in to do that
Don't have an account?
Patrick Foy
Trying to convert Apex Query List to string not sure if this is correct
I am trying to execute a SOQL query that may return a list. If list is null I want to set default value. I am new to apex so not sure if this is correct.
// SET USERNAME STRING string username = '%'+UserInfo.getFirstName()+'%'; //SET DEFAULT PRODUCTid Id ProductID = '01t46000000nPO0AAM'; //MAP IDMAPPRODUCT2 Map<Id> idmapproduct2 = new Map<Id>([Select Id FROM Product2 WHERE ProductCode like '%LAB %' AND ProductCode like:username]); system.debug(idmapproduct2); //CHECK IF MAP IS NULL AND IF NOT SET IT TO PRODUCT ID if(idmapproduct2 != null) {ProductID = idmapproduct2;}
All Answers
I am getting no problems but received this error : System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, WorkOrderCheckIN2: execution of AfterInsert caused by: System.ListException: List index out of bounds: 0 Trigger.WorkOrderCheckIN2: line 15, column 1: []
thank you so much for working with me on this. So I am still getting a error.
Stack trace
I'm sorry I just feel a little incompetent here I have beel all over high and low trying to fix this and no luck I keep hitting same issue.
I was hopeful that it would emulate this query
Select Id FROM Product2 WHERE ProductCode like '%LAB %' AND ProductCode like '%ZACH%'
That query when I run it in query editor returns 1
I'm not sure the correct value is being passed into username could that be where my break is?
Try this
I tried that and still no success here is log.
Username is null and products both are not working
We are half way username did populatecorrectly this time. query still failed. I'm also kind of curious because even if the query returns null it should use the variable I set.
Try with that trigger, checking for null is not enough, we have to check if the list is empty. The disadvantage with this is that the ID is hardcded and will probably not be the same in the production instance.
I do have a new error:
System.DmlException: Update failed. First exception on row 0 with id a130t000000DYSFAA4; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, WorkOrderCheckIN2: execution of AfterUpdate
caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OptimaPro.MOBSVC_WorkOrderLine: execution of AfterInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.OptimaPro.MOBSVC_InstalledProduct_WorkOrderLine.createInstalledProduct: line 48, column 1
Trigger.OptimaPro.MOBSVC_WorkOrderLine: line 11, column 1: []
Trigger.WorkOrderCheckIN2: line 25, column 1: []
Stack trace
Class.WorkOrderCheckINTest2.WorkOrderCheckINTest2Method: line 44, column 1
System.DmlException: Update failed. First exception on row 0 with id a130t000000DYSjAAO; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, WorkOrderCheckIN2: execution of AfterUpdate
caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OptimaPro.MOBSVC_WorkOrderLine: execution of AfterInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.OptimaPro.MOBSVC_InstalledProduct_WorkOrderLine.createInstalledProduct: line 48, column 1
Trigger.OptimaPro.MOBSVC_WorkOrderLine: line 11, column 1: []
Trigger.WorkOrderCheckIN2: line 26, column 1: []
Stack:
Class.WorkOrderCheckINTest2.WorkOrderCheckINTest2Method: line 43, column 1
Here is debug if it helps I don't get why it is running all those steps after. Looks like it is completing all the list just not inserting right.
Class.OptimaPro.MOBSVC_InstalledProduct_WorkOrderLine.createInstalledProduct: line 48, column 1
Could you check that line or share the code for the class OptimaPro.MOBSVC_InstalledProduct_WorkOrderLine
Cannot access just shows hidden probably because of managed package. I just threw that debug in a few spots and check and I don't see why it shouldn't work beyond hitting that wall. I may just have to get a hold of them and see what i'm up against. code coverage is at 100% now though for this. So i should be ok to deploy right?