You need to sign in to do that
Don't have an account?
Kumaresan M 2
Record locking in detail record when i try to insert details in future method ?
I am getting error "UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []" when i try to insert detail record.
Eligible Employee is detail object, Master is inserted already.
Here is my code, where i am looping string list and calling future methods to process more records asynchrously:
set<string> str=new set<string>();
List<string> strLst=new List<string>();
Integer w=0;
for(string l:LoadedMSIDList){
ResultString=ResultString+l+',';
Eligible_Employees__c e=new Eligible_Employees__c();
if(EmployeeMap.containskey(l)){
str.add(l);
strLst.add(l);
ResultString=ResultString+'Successfully inserted into system \n';
}
else{
ResultString=ResultString+'Invalid MSID \n';
}
w++;
if(strLst.size()>1999 || w==LoadedMSIDList.size()){
DMLbatch(str,strLst,EligibilityRecord.id);
str.clear();
strLst.clear();
}
}
Here is my future method which will insert detail records asynchronuosly:
@future(callout=false)
public static void DMLbatch(Set<string> str,List<String> strLst,string myId){
List<Eligible_Employees__c> EligibleEmployeeList1=new List<Eligible_Employees__c>();
Map<string,Employee__c> EmployeeMaps=new Map<string,Employee__c>();
List<Employee__c> EmpLst=WaiversUtility.getEmployeeListonMSID(str);
for(Employee__c emp:EmpLst){
EmployeeMaps.put(emp.Emp_ID__c,emp);
}
for(string s:strLst){
Eligible_Employees__c e1=new Eligible_Employees__c();
e1.Employee__c=EmployeeMaps.get(s).id;
e1.Eligibility__c=myId;
EligibleEmployeeList1.add(e1);
}
insert EligibleEmployeeList1;
}
Please help me on this to resolve this.
Eligible Employee is detail object, Master is inserted already.
Here is my code, where i am looping string list and calling future methods to process more records asynchrously:
set<string> str=new set<string>();
List<string> strLst=new List<string>();
Integer w=0;
for(string l:LoadedMSIDList){
ResultString=ResultString+l+',';
Eligible_Employees__c e=new Eligible_Employees__c();
if(EmployeeMap.containskey(l)){
str.add(l);
strLst.add(l);
ResultString=ResultString+'Successfully inserted into system \n';
}
else{
ResultString=ResultString+'Invalid MSID \n';
}
w++;
if(strLst.size()>1999 || w==LoadedMSIDList.size()){
DMLbatch(str,strLst,EligibilityRecord.id);
str.clear();
strLst.clear();
}
}
Here is my future method which will insert detail records asynchronuosly:
@future(callout=false)
public static void DMLbatch(Set<string> str,List<String> strLst,string myId){
List<Eligible_Employees__c> EligibleEmployeeList1=new List<Eligible_Employees__c>();
Map<string,Employee__c> EmployeeMaps=new Map<string,Employee__c>();
List<Employee__c> EmpLst=WaiversUtility.getEmployeeListonMSID(str);
for(Employee__c emp:EmpLst){
EmployeeMaps.put(emp.Emp_ID__c,emp);
}
for(string s:strLst){
Eligible_Employees__c e1=new Eligible_Employees__c();
e1.Employee__c=EmployeeMaps.get(s).id;
e1.Eligibility__c=myId;
EligibleEmployeeList1.add(e1);
}
insert EligibleEmployeeList1;
}
Please help me on this to resolve this.
https://developer.salesforce.com/page/The_Salesforce_Bulk_API_-_Maximizing_Parallelism_and_Throughput_Performance_When_Integrating_or_Loading_Large_Data_Volumes
https://developer.salesforce.com/blogs/engineering/2014/08/managing-task-locks-data-loads.html
Do you have any thing for this ?
Iterator Class:
global with sharing class CSVIterator implements Iterator<String>, Iterable<String>
{
private String m_CSVData;
private String m_introValue;
public CSVIterator(String fileData, String introValue)
{
m_CSVData = fileData;
m_introValue = introValue;
}
global Boolean hasNext()
{
return m_CSVData.length() > 1 ? true : false;
}
global String next()
{
String row = m_CSVData.subString(0, m_CSVData.indexOf(m_introValue));
m_CSVData = m_CSVData.subString(m_CSVData.indexOf(m_introValue) + m_introValue.length(),m_CSVData.length());
return row;
}
global Iterator<String> Iterator()
{
return this;
}
}
Batch Class:
global class ReadAndPopulateBatch implements Database.batchable<String>, Database.Stateful
{
public String m_csvFile;
public String fileId;
public Map<Integer,string> OrderMap;
global Iterable<String> start(Database.batchableContext batchableContext)
{
return new CSVIterator(m_csvFile,'\n');
}
global void execute(Database.BatchableContext batchableContext, List<String> scope)
{
system.debug('************Limits.getHeapSize()'+Limits.getHeapSize());
list<Wav_Custom_data__c> insertlist=new list<Wav_Custom_data__c>();
.... code to process reocrds to insert....
Database.Insert(insertlist);
insertlist.clear();
system.debug('************Limits.getHeapSize()2'+Limits.getHeapSize());
}
global void finish(Database.BatchableContext batchableContext){
}
}