I wrote one for loop and perform insert,update operation inside the for loop, it is working clearly but i need to perform that operation outside the for loop so is the better way to do it ?
for(Exhibition_Line_Item__c ELI : [Select Item__c, Line_Total__c,Invoice_Line__c, Line_Description__c,Exhibitor__c from Exhibition_Line_Item__c where Exhibitor__c in : exIdList]){
invLine = new Invoice_Line__c();
if(ELI.Line_Description__c != null){
invLine.Line_Description__c = ELI.Item__c +' : '+ ELI.Line_Description__c;
}else{
invLine.Line_Description__c = ELI.Item__c;
}
invLine.Line_Total__c = ELI.Line_Total__c;
invLine.invoice__c = invoiceExhibitor.get(ELI.Exhibitor__c).Invoice__c;
insert invLine;
Invoice_Line__c inLI = new Invoice_Line__c();
inLI = [select Id, Name from Invoice_Line__c where id =: invLine.Id];
ELI.Invoice_Line__c = inLI.Id;
update ELI;
if(invIDs == null){
invIDs = invoiceExhibitor.get(ELI.Exhibitor__c).Invoice__c;
}else{
invIDs += ',' + invoiceExhibitor.get(ELI.Exhibitor__c).Invoice__c;
}
}