• Anthony Linz
  • NEWBIE
  • 0 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello all. I'm having an issue with my Visualforce controller code and was wondering if anyone had any ideas for me.

The error I'm receiving is:
Code:
System.Exception: DML currently not allowed

Class.maExtension.save: line 18, column 13
External entry point
 
My controller code is:
Code:
public class maExtension {

 public scr__c scr {get; private set;}

 public maExtension() {
  scr = new scr__c();
 }

 public pagereference save() {
  scr.market_area__c = getmarket().id;
  system.debug('Market ID: ' + scr.market_area__c);
  system.debug('First Name: ' + scr.first_name__c);
  system.debug('Last Name: ' + scr.last_name__c);
  system.debug('Full Address: ' + scr.street_1__c + 
   ' ' + scr.street_2__c + ' ' + scr.city__c + 
   ' ' + scr.state__c + ' ' + scr.zip_code__c);
  try {
   insert scr;
   system.debug('Insert Successful');
  } catch(System.DmlException e) {
   system.debug(e.getDmlMessage(0));
  }
  return null;
 }

 ma__c market;

 public string getzip() {
  string zip = apexpages.currentpage().getparameters().get('zip');
  return zip;
 }

 public string getaddress() {
  string address = apexpages.currentpage().getparameters().get('street');
  return address;
 }

 public string getcity() {
  string city = getmarket().name;
  return city;
 }

 public string getstate() {
  string state = getmarket().primary_state__c;
  return state;
 }

 public boolean getmarketexists() {
  string zip = getzip();
  integer count = [select count() 
  from ma__c 
  where primary_zip_code__c = :zip 
  limit 1];
  boolean marketexists = count > 0 ? true : false;
  return marketexists;
 }

 public boolean getmarkethascoverage() {
  string zip = getzip();
  integer count = [select count() 
  from ma__c 
  where primary_zip_code__c = :zip 
  and (status__c = 'Partial Coverage' or status__c = 'Full Coverage') 
  limit 1];
  boolean getmarkethascoverage = count > 0 ? true : false;
  return getmarkethascoverage;
 }

 public ma__c getmarket() {
  if (getmarketexists() == true) {
   string zip = getzip();
   market = [select id, name, primary_zip_code__c, primary_state__c, status__c 
   from ma__c 
   where primary_zip_code__c = :zip 
   limit 1];
  } else {
   market = new ma__c();
  }
  return market;
 }

}
 
My Visualforce Page is:
Code:
 <apex:form id="scrform">
  <apex:inputfield id="scrfirstname" value="{!scr.first_name__c}" />First Name<br />
  <apex:inputfield id="scrlastname" value="{!scr.last_name__c}" />Last Name<br />
  <apex:inputfield id="scremail" value="{!scr.email_address__c}" />Email<br />
  <apex:inputfield id="scrstreet1" value="{!scr.street_1__c}" />Street Address 1<br />
  <apex:inputfield id="scrstreet2" value="{!scr.street_2__c}" />Street Address 2<br />
  <apex:inputfield id="scrcity" value="{!scr.city__c}" />City<br />
  <apex:inputfield id="scrstate" value="{!scr.state__c}" />State<br />
  <apex:inputfield id="scrzip" value="{!scr.zip_code__c}" />Zip Code<br />
  <apex:commandbutton action="{!save}" value="Sign Me Up" /><br />
 </apex:form>

When the "Sign Me Up" button invoking the save() method is clicked, I receive the exception. Any help would be greatly appreciated. Thanks!
  • October 21, 2008
  • Like
  • 0