You need to sign in to do that
Don't have an account?
ApexDev
Unexpected token '<' in Apex Trigger
Hi :) I try to write Apex Trigger for Work Order object, which prevent user to Completed the Work Order if Service_Type__c field is empty.
Can someone check my code? I get the issue that is unexpected token '<'. Thank you!
trigger ValidateWorkOrderLineItem on WorkOrder (before update) {
Map<String, WorkOrder> mapWoToId = new Map<String,WorkOrder>();
for(WorkOrder w : Trigger.New) {
if(w.Status =='Completed'){
mapWoToId.put(w.Id, w);
}
}
List<WorkOrderLineItem> woLineItemList = [select woli.Status, woli.workOrderId
from WorkOrderLineItem woli
where woli.WorkOrderId IN :mapWoToId.keySet() and woli.Status != 'Completed' and woli.WOLI__c == 'Parent' and woli.Parent_WOLI__c == TRUE and woli.Service_type__c == ''];
for(WorkOrderLineItem woli : woLineItemList) {
WorkOrder parentWO = mapWoToId.get(woli.workOrderId);
parentWO.addError('Please fill the Service Type on each Parent Work Order Line Item');
}
}
Can someone check my code? I get the issue that is unexpected token '<'. Thank you!
trigger ValidateWorkOrderLineItem on WorkOrder (before update) {
Map<String, WorkOrder> mapWoToId = new Map<String,WorkOrder>();
for(WorkOrder w : Trigger.New) {
if(w.Status =='Completed'){
mapWoToId.put(w.Id, w);
}
}
List<WorkOrderLineItem> woLineItemList = [select woli.Status, woli.workOrderId
from WorkOrderLineItem woli
where woli.WorkOrderId IN :mapWoToId.keySet() and woli.Status != 'Completed' and woli.WOLI__c == 'Parent' and woli.Parent_WOLI__c == TRUE and woli.Service_type__c == ''];
for(WorkOrderLineItem woli : woLineItemList) {
WorkOrder parentWO = mapWoToId.get(woli.workOrderId);
parentWO.addError('Please fill the Service Type on each Parent Work Order Line Item');
}
}
Just small error in your query . not need to add == while comparision in soql. So just update the query as below and it should save with out any issue.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Just small error in your query . not need to add == while comparision in soql. So just update the query as below and it should save with out any issue.
If this solution helps, Please mark it as best answer.
Thanks,