I am getting a DML not allowed error from my visual force page.
The error is caused by an update and insert call in a method which seems to be the constructor.
Can someone give me a solution to how I can update and insert this list of records without hitting this error?
Code snippet:
public with sharing class SalesInvoiceHelper
{
public static List<CTransaction_Item__c> generateSalesInvoiceLineItems(Id salesInvoiceId, List<OpportunityLineItem> prodList)
{
List<CTransaction_Item__c> lineItems = new List<CTransaction_Item__c>();
List<OpportunityLineItem> oneOffPayments = new List<OpportunityLineItem>();
List<OpportunityLineItem> renewals = new List<OpportunityLineItem>();
RenewalValues__c rv = RenewalValues__c.getOrgDefaults();
for(OpportunityLineItem oli : prodList)
{
//I removed the code in here from the snippet to keep my post from being too long, as it is quite long and not causing any problems.
}
**//This line is causing DML not allowed.**
if(oneOffPayments.size() > 0) {update oneOffPayments; oneOffPayments.clear();}
**//This line is causing DML not allowed.**
if(renewals.size() > 0){ insert renewals; renewals.clear();}
return lineItems; //Returns all of the items
}