You need to sign in to do that
Don't have an account?
Suman Kundu
System.LimitException: DML currently not allowed - from Approval.process(req)
public ReversePaymentController(ApexPages.StandardController con)
{
this.controller = con;
shouldRenderPageBlock = true;
UserRole r = [select Id from UserRole where Name = 'Customer Service Managers'];
if(r != null)
{
System.debug('::::::::::'+r.Id);
o2bc__Subscription__c subs = [select Id, o2bc__Account__c, o2bc__Invoice__c, Credit_Card__c from o2bc__Subscription__c where Id = :controller.getId()];
if(subs.o2bc__Invoice__c != null)
{
List<o2bc__Payment__c> pList = [select Id, Name, Mes_Transaction_ID__c , o2bc__Payment_Amount__c, o2bc__Invoice__r.Name, o2bc__Invoice_Line__c, o2bc__Invoice_Line__r.Name, o2bc__Invoice_Line__r.o2bc__Unit_Rate__c, o2bc__Invoice_Line__r.o2bc__Subscription__c, o2bc__Account__c, o2bc__Account__r.Name, o2bc__Invoice__c, o2bc__Payment_Method__c, o2bc__Has_Processed__c, o2bc__Refund_Amount__c, o2bc__Status__c from o2bc__Payment__c where o2bc__Invoice__c = :subs.o2bc__Invoice__c and o2bc__Payment_Method__c = 'Credit Card'];
if(pList != null && pList.size() > 0)
{
for(o2bc__Payment__c pay1 : pList)
{
if(String.valueOf(pay1.o2bc__Status__c).equals('Processed') && pay1.o2bc__Has_Processed__c)
{
pay = pay1;
break;
}
}
if(pay != null)
{
payamt = pay.o2bc__Payment_Amount__c;
payMethod = pay.o2bc__Payment_Method__c;
hasProcessed = pay.o2bc__Has_Processed__c;
refAmount = String.valueOf(payamt);
note = '';
reason = '';
if(UserInfo.getUserRoleId() != r.Id)
{
// create approval
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Submitted for reversing payment.');
req.setObjectId(pay.Id);
Approval.ProcessResult result = Approval.process(req); //throwing error line:52
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, 'CSR Manager is only granted to do this process.'));
shouldRenderPageBlock = false;
}
}
else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'Reverse Payment is only allowed on processed payments.'));
shouldRenderPageBlock = false;
}
}
else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There is no payment processed by Credit Card.'));
shouldRenderPageBlock = false;
}
}
else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There is no invoice in this subscription.'));
shouldRenderPageBlock = false;
}
}
else
{
}
}
Here from 52nd line where process method has been called, throws this error.
I have used a component where I have also used allowDML="true", but still it throws error.
Please help me.
Yes it is working from page action method.
All Answers
You cannot have a DML statement run in your constructor.
Thank you very much. I didn't know it.
So in this case, should I call Approval.process method from page.action?
Yes it is working from page action method.