for work order object create a record data type as 'Parent Work Order' ,for Work Order object create a field 'Parent Order -data type(self lookup) i have to run a batch which associates all the work orders of same toplevel(this is a field in work order object) under single project work order.if the parent work order is there then use it,else create a new parent work order
global class WorkOrderBatch implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext bc)
{
return Database.getQueryLocator('select id,name,SVMXC__Top_Level__c,Parent_Work_Order__c from SVMXC__Service_Order__c where SVMXC__Top_Level__c <> null');
}
global void execute(Database.BatchableContext bc,list<SVMXC__Service_Order__c> batch)
{ List<string> namelist =new List<string>();
for(SVMXC__Service_Order__c na:batch)
{
namelist.add(na.name);
}
List<SVMXC__Service_Order__c> updatelist=new List<SVMXC__Service_Order__c>();
List<SVMXC__Service_Order__c> serviceorderlist=new List<SVMXC__Service_Order__c>();
for(SVMXC__Service_Order__c serviceorder :[select RecordTypeId,name,Parent_Work_Order__c
from SVMXC__Service_Order__c where name in:namelist ])
{
serviceorder.Parent_Work_Order__c=serviceorder.RecordTypeId;
updatelist.add(serviceorder);
}
update updatelist;
}
global void finish(Database.BatchableContext bc)
{
}
}
in mycode there is no error but the parent work field does not populate
Parent_Work_Order__c
field, which I assume is a lookup relationship? That should simply fail. Do you want the Id instead, to create a parent-child relationship?