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
sayanasreekanth@gmail.comsayanasreekanth@gmail.com 

DML currently not allowed

Hi All

 

I amtrying to insert a value  in a custom object field  whenever user hits the tab in visualforce page. As well i am trying to pull the user information who clciked the tab. When i checked the debuglogs it is entering in to the loop and throwing the DML currently not allowed Error. What should i need to do inorder to insert a value. Appreciate your help 

 

Here is the part of the vf page

 <apex:tab label="Credit History" id="BTNtabSix" onclick="Callcon('Credithistory');" style="background-color: white;" >

<apex:actionFunction name="callCon" oncomplete="callCon1();">
<apex:param name="firstParam" value="" assignTo="{!Tabselected}"/>
</apex:actionFunction>
<apex:actionfunction name="callCon1" action="{!searchtab}"/>

</apex:tab>

 

Here is my part of my controller. I called the searchtab method in one of the void method

public with sharing class SummaryPageController {

public used_tab__c Tab; //sreekanth
public List<tools_of_users__c> uList;
public String Tabselected {get;set;}
Integer cnt;

 public void objCustomerAccountInfo(){

 

lstCreditHistory = [SELECT Account_DOB__c,Account_Id__c from FROM Credit_History__c WHERE Account_Id__c =:strAccId  LIMIT 999];
if(lstCreditHistory.size()>0) objCreditHistory = lstCreditHistory[0];
searchtab();

}

Public PageReference searchtab() {

Tab = new used_tab__c(); //sreekanth
uList = new List<tools_of_users__c>();

if(Tabselected != null && Tabselected != '') {

system.debug('###### '+Tabselected);
Tab.tab_used__c ='Tabselected';
}

system.debug('###### '+Tab.tab_used__c);
cnt = [SELECT COUNT() FROM tools_of_users__c WHERE User_Record_Id__c = :Userinfo.getUserId()];

if(cnt == 0) //not existing yet
{
ulist.add(new tools_of_users__c(User_Record_Id__c = Userinfo.getUserId()));
try{
Database.SaveResult saveResult = Database.Insert(uList[0], false);

System.debug('************* New List_of_User__c Id: ' + saveResult.getId());

Tab.users__c = saveResult.getId();
insert Tab;


}catch(System.DMLException de){
System.debug('************insert of new tools used to NEW user FAILED:'+'\n'+ de.getMessage());
}

}else{
//get the current user record Id
uList= [SELECT Id, User_Record_Id__c FROM tools_of_users__c WHERE User_Record_Id__c = :Userinfo.getUserId()];
Tab.users__c = uList[0].Id;

try{
insert Tab;
//update uList[0];
system.debug('################### '+Tab.Id);

}catch(System.DMLException de){
System.debug('************insert of new tools used to EXISTING user FAILED: '+'\n'+ de.getMessage());
}
}
return null;
}
}

 

Best Answer chosen by Admin (Salesforce Developers) 
manuel-jose-condemanuel-jose-conde

hi,

are you using a custom component in your visualforce page? If you are make sure you have the attribute allowDML set to true when calling that component in the VF page.

 

Regards

Manuel