You need to sign in to do that
Don't have an account?
Solution for DML currently not allowed
List<Group> leadQueueRec = [Select Id, Name from Group where Name = 'LeadQueue'];
List<Lead> leadRec = [Select Id, Name, OwnerId from Lead where Name='James'];
if(leadRec.size() > 0){
leadrec[0].OwnerId = leadQueueRec[0].Id;
update leadrec[0];
}
Above snippet of code I am able to run throgh System Log successfully.
But when I am writing same code in one actionFuction It is giving the Exception
DML currently not allowed
System.Exception: DML currently not allowed
So I am not getting the reason for this? Does anybody come across same error and knows what is the solution to handle this?
Is this in an apex page or a component?
If its a component, you'll need to set the allowDML attribute to true.
You should be able to do this from an action method tied to a page with no problem.
All Answers
Is this in an apex page or a component?
If its a component, you'll need to set the allowDML attribute to true.
You should be able to do this from an action method tied to a page with no problem.
Thanks a lot Bob, my issue is resolved
This error also occurs when you you try to write the query or insert the data in the loop.Good that your issue is resolved but I am writing for those who faces the same error even if they acitvate their DML settings.
You wouldn't get DML not currently allowed if you had your SOQL/DML in a loop. You'd hit governor limits in that case which would give you a different error - too many SOQL queries for example.
DML not currently allowed errors will occur if:
(1) You attempt DML in a component without the AllowDML=true
(2) You attempt DML in a controller constructor
(3) You attempt DML in a get method in a controller.
Oh!
Thanks for this information but I do remembered I got this error once. Let me recall it and post back again.
Thanks for the knowledge share, by the way.
I have a similar situation here, but I am not able to find out any solution.
My visualforce page is overriding standard view page of Account object. so when user opens company tab and clicks a company he will be looking at my overidden VF page. Now I want to store the user clicks in my custom object. My code is as below.
<apex:page standardController="account" extensions="myController">
<apex:detail subject="{!accountId}" relatedList="false" title="true" relatedListHover="true" showChatter="true"/>
</apex:page>
public with sharing class myController{
public String accountId {get; set;} //account id
public Account acc {get; set;} // account record
Public Id userId {get; set;} // user logged record
public myController(ApexPages.StandardController controller) {
accountId = controller.getId();
userId=userinfo.getuserid();
UserRoleId=UserInfo.getUserRoleId();
acc=[SELECT id,ownerId FROM Account where id=:accountId];
logCompany();}
public void logCompany() {
Search_Logs__c SearchLog= new Search_Logs__c() ;
SearchLog.Company_Name__c=accountId;
SearchLog.Date_Accessed__c=system.today();
SearchLog.Primary_Owner__c=acc.OwnerId;
SearchLog.User_Accessed__c=userId;
insert SearchLog;}
}
I am trying to call a method which does DML operation from my constructor. I cannot use any commandbutton here.
Any ideas..please
Regards,
Raj
I called the method from page action as below
<apex:page standardController="account" extensions="myController" action="{!logCompany}">
<apex:detail subject="{!accountId}" relatedList="false" title="true" relatedListHover="true" showChatter="true"/>
</apex:page>
not from the constructor
Thanks,
Raj