function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anushka BansalAnushka Bansal 

delete a record


public class ACP_TopOpenOpportunity_Component_Ctrl {
ACP_Top_Open_Opportunity__c opp = new ACP_Top_Open_Opportunity__c();

 public String accPlanId {
  get;
  set;
 }

 public String id {
  get;
  set;
 }

 public pageReference deleteRec() {
 opp = [Select id from ACP_Top_Open_Opportunity__c where id = :id];
    delete opp;
  return null;
 }

 public List < ACP_Top_Open_Opportunity__c > TopOpenOpportunityList {
  get{return getTopOpenOpportunityList(); }
  set;
 }
 
 public ACP_TopOpenOpportunity_Component_Ctrl() { 
 }

 public List < ACP_Top_Open_Opportunity__c > getTopOpenOpportunityList() {
  String query = 'SELECT ';
  for (Schema.FieldSetMember f: this.getFields()) {
   query += f.getFieldPath() + ',';
  }
  query += 'ACP_Account_Plan__c FROM ACP_Top_Open_Opportunity__c where ACP_Account_Plan__c = \'a0J0S000000hw3V\'';
  System.debug('query++' + query);
  return Database.query(query);

 }

 public List < Schema.FieldSetMember > getFields() {
  return SObjectType.ACP_Top_Open_Opportunity__c.FieldSets.ACP_Top_Open_Oppurtunity_Fieldset.getFields();
 }
}


******************VISUALFORCE CODE***********************************
<apex:column headerClass=" " id="delete" rendered="{!flag}"><apex:commandLink value="" onclick="return confirm('Are you sure?')" action="{!deleteRec}" styleClass="glyphicon glyphicon-trash"> <apex:param name="id"
                value="{!acpPur.id}"
                assignTo="{!id}"/></apex:commandLink> </apex:column>


its giving the error
System.LimitException: DML currently not allowed 
Class.ACP_TopOpenOpportunity_Component_Ctrl.deleteRec: line 34, column 1
GauravGargGauravGarg
Hi Anushka,

This is allowed, there might be some issues internally. We have multiple solutions to it:
  • Firstly, we can debug this issues. if you understand debug logs or you can post it here so that I could analyse them. 
  • Try using Database.delete(opp, false) instead of delete command. 
  • Please try deleting the list of Opportinities in Asynchronous call like: queueable Methods / Future methods
    • create another method with @future anonym and pass the Opp_Id to the method. 


Hope this will solve your issue!!!

Thanks,
Gaurav
Skype: gaurav62990