You need to sign in to do that
Don't have an account?

dmlexception error
I am getting error : System.LimitException: DML currently not allowed
Class.heatclass.getStore: line 9, column 1
my code is:
public String getStore() {
for(integer ac=0;ac<mapstr.size();ac++)
{
try{
auditcount__c e=new auditcount__c(Name='hello',count__c=5);
insert e;
}
catch(System.DMLException ex)
{
ApexPages.addMessages(ex);
}
}
return null;
}
You have 2 issues, one is the "Insert e" is hitting the governor limit becuase you are inserting for every record. What you want to do is move it outside the for loop like below. Also I think you might run into an issue with the return null, probably want to return an empty string like "return ' ' "
public String getStore() {
for(integer ac=0;ac<mapstr.size();ac++)
{
auditcount__c e=new auditcount__c(Name='hello',count__c=5);
}
try{
insert e;
}
catch(System.DMLException ex)
{
ApexPages.addMessages(ex);
}
return null;
}
Hope this helps
Regards
-Henry
Hi Tapasvini,
I think the above mentionded code wont work because it will overrive the value in auditcount__c e.
The workarround can be:
public String getStore()
{
try
{
List<auditcount__c> listOfAuditcount = new List<auditcount__c>();
for(integer ac=0;ac<mapstr.size();ac++)
{
auditcount__c e=new auditcount__c(Name='hello',count__c=5);
listOfAuditcount.add(e);
}
insert listOfAuditcount;
}
catch(System.DMLException ex)
{
ApexPages.addMessages(ex);
}
}
Let me know your feedback.
Sincerely,
Praful G.