You need to sign in to do that
Don't have an account?
svd
System.Exception: DML currently not allowed..help needed.
Hi,
I'm trying to call a action method in my controller through my java script code in the visualforce page. but my action method consists of 'Insert' DML statement and so I'm getting the following error.
System.Exception: DML currently not allowed. External entry point
here is a piece from my code.
<apex:page>
<script type="text/javascript">
function register(regId)
{
// I have some code to add regId to my query String. Then I call my action method in controller.
{!register};
}
</script>
< // some visual force component that calls Java script 'register' function />
</apex:page>
my action method code is as follows:
public Pagereference getRegister()
{
scheduleId = System.currentPageReference().getParameters().get('schID'); // getting the query string added by my javascript method
userId = UserInfo.getUserId();
Registration__c reg = new Registration__c(Activity_Schedule_ID__c = scheduleId, User__c = userId );
insert reg;
return null;
}
Is there any other way that I can get this done. Any help is appreciated. Thanks in advance.
Thanks,
DSV
I'm trying to call a action method in my controller through my java script code in the visualforce page. but my action method consists of 'Insert' DML statement and so I'm getting the following error.
System.Exception: DML currently not allowed. External entry point
here is a piece from my code.
<apex:page>
<script type="text/javascript">
function register(regId)
{
// I have some code to add regId to my query String. Then I call my action method in controller.
{!register};
}
</script>
< // some visual force component that calls Java script 'register' function />
</apex:page>
my action method code is as follows:
public Pagereference getRegister()
{
scheduleId = System.currentPageReference().getParameters().get('schID'); // getting the query string added by my javascript method
userId = UserInfo.getUserId();
Registration__c reg = new Registration__c(Activity_Schedule_ID__c = scheduleId, User__c = userId );
insert reg;
return null;
}
Is there any other way that I can get this done. Any help is appreciated. Thanks in advance.
Thanks,
DSV
Thanks for your reply.
My requirement :
when I press a button in Visual Force page, I need to get a confirmation window (yes/no type) and when user hits Yes, then I need to get my register function called.So for this confirmation window, I'm using javascript. My problem is I'm unable to call action methods/ getter methods that consist of DML operations from java script code. Is there a way a achieve this. If so, please give me some details on how to achieve it.
Thanks again,
DSV
It sounds like you're making this overly complicated. Somethings like this should be fine:
Message Edited by jwetzler on 11-24-2008 11:00 AM
thanks for your time and help. Yes, this info helps. But here is the problem I face with this logic.
My VF page has some n courses and each course has a Register button. When I click register button and after user confirmation I need that particular subject to be registered in the system. (Add a record with UserID and SubjectID to a custom object).To do this I need to send the Subject ID to my controller. But VF can not pass arguments to APEX functions. So I was doing it through dummy query strings.
So is there a way that I can set query string (add an ID parameter) when user clicks Register button and then ask for confirmation.
Thank you,
SVD