You need to sign in to do that
Don't have an account?
SFDC_2706
ERROR :DML Currently Not Allowed
Hello, I am Getting 'DML not allowed Error'.I am bulk approving my records through list button.I am calling my vf page through button and add logic in my apex controller. below is my apex controller. Thanks for any help in advance.
Apex controller
public class Claim_Approval{
public ApexPages.StandardSetController setController;
public List < Claim__c > selectedListViewRecords {get;set;}
public set<Id> ids = new set<Id>();
public Claim_Approval(ApexPages.StandardSetController setcontroller) {
this.setcontroller = setcontroller;
List<Claim__c> selectedListViewRecords =(List<Claim__c>) setcontroller.getSelected();
Set<Id> ids = new Set<Id>();
for(Claim__c rec: selectedListViewRecords){
ids.add(rec.id);
}
List<Approval.ProcessWorkitemRequest> requests = new List<Approval.ProcessWorkitemRequest>();
List<ProcessInstanceWorkitem> workItems;
workItems = [SELECT Id, ProcessInstanceId FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId IN :ids];
for(ProcessInstanceWorkitem workItem : workItems){
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setWorkitemId(workItem.Id);
req.setAction('Approve');
req.setComments('No Comment.');
requests.add(req);
system.debug('requests'+requests);
}
Approval.ProcessResult[] processResults = Approval.process(requests,false);
}
}
Apex controller
public class Claim_Approval{
public ApexPages.StandardSetController setController;
public List < Claim__c > selectedListViewRecords {get;set;}
public set<Id> ids = new set<Id>();
public Claim_Approval(ApexPages.StandardSetController setcontroller) {
this.setcontroller = setcontroller;
List<Claim__c> selectedListViewRecords =(List<Claim__c>) setcontroller.getSelected();
Set<Id> ids = new Set<Id>();
for(Claim__c rec: selectedListViewRecords){
ids.add(rec.id);
}
List<Approval.ProcessWorkitemRequest> requests = new List<Approval.ProcessWorkitemRequest>();
List<ProcessInstanceWorkitem> workItems;
workItems = [SELECT Id, ProcessInstanceId FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId IN :ids];
for(ProcessInstanceWorkitem workItem : workItems){
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setWorkitemId(workItem.Id);
req.setAction('Approve');
req.setComments('No Comment.');
requests.add(req);
system.debug('requests'+requests);
}
Approval.ProcessResult[] processResults = Approval.process(requests,false);
}
}
Can you check the similar question in answered where the solution is mentioned .
"allowDML" attribute of the Visualforce component must be set to true in order for the save method to function.
https://developer.salesforce.com/forums/?id=906F0000000952VIAQ
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
JUST SIMPLE:-
You need to set the allowDML attribute of your component to true for DML to be allowed by your component. just example:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh