+ Start a Discussion

DML currently not allowed

Can someone help. Im getting this error and know not how to resolve.

System.LimitException: DML currently not allowed
Class.WorksheetLender.getRateX: line 33, column 1

public Price_Range__c getRateX() {
Lender__c a = new Lender__c (Name = 'KEY');
insert a;
String Key ;
Decimal amount=[SELECT Finance_Amount__c FROM Worksheet__c LIMIT 1].Finance_Amount__c;
if(amount >150000 && amount <250000){
if(amount >99999 && amount <149999){
return [SELECT Range_Rate_Month24__c FROM Price_Range__c WHERE Id =: a.id  LIMIT 1];

I know that this isn't best practice to hardcode id but this is only practice knowledge. And then work my way up to bulk and simplify. Thanks for your help
Phillip SouthernPhillip Southern
Where are you calling this from?  VF page, trigger, batch, etc...
Above is from my Controller.

and this is from my VF.

<td width="150px">
<apex:outputfield id="lender4" value="{!lender4.Name}"/>(<apex:outputtext value="{!RateX.Range_Rate_Month24__c}"/>)