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
MukulMukul 

Want to save a rule in an Object

Hi all,

 

I am very new to the Apex development and  CustomControllers.

 

I am building a "Custom Report" like application where you can choose some operators and create a filter.

 

On clicking the Save button, i want to save that filter in a record in an object. Can anyone please tell me what should my save function look like?

 

Here is my visual page code : 

 <apex:page controller="newScoreRuleController" tabStyle="Lead">
  <script type="text/javascript">
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;  
     return false;
  }  
  </script>
  <apex:sectionHeader title="Scoring Rule Wizard" subtitle="Step 1 of 2"/>
    <apex:form id="myform">
     <apex:pageBlock title="Select a Lead's value" mode="edit" id="pgB">
   
        <apex:pageBlockButtons >
          <apex:commandButton value="Next" onclick="moveToNext(); "/>
          <apex:commandButton action="{!cancel}" value="Cancel"
                              onclick="return confirmCancel()" immediate="true"/>
                             
        </apex:pageBlockButtons>
         <apex:pageBlockSection title="Select a lead's field" id="pgBS">

        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->
        <apex:selectList id="fldName" multiselect="false" required="true">
        <apex:selectOptions value="{!leadFields}"></apex:selectOptions>
          <script type="text/javascript">
        function leadChosen() {
   var selectedVal = document.getElementById('{!$Component.fldName}').value;
   var isChosen = alert(selectedVal + ' is chosen');
   if (isChosen) return true;   
   return false;
  }
  function moveToNext() {
     var selectedVal = document.getElementById('{!$Component.fldName}').value;
     parent.document.location.href = "https://nl.na6.visual.force.com/apex/scoreRuleStep2?fld=" + selectedVal;
    //return selectedVal;
  }
     </script>
        </apex:selectList>
          <apex:selectList id="wtList" multiselect="false" value="{!}" required="true">
        <apex:selectOptions value="{!weightList}"></apex:selectOptions>
         </apex:selectList>
      </apex:pageBlockSection>
          </apex:pageBlock>
           </apex:form>
       </apex:page>

 

Here is my controller code: 

 

public class newScoreRuleController {

  Lead lead;
  public Lead getLead() {
   if(lead == null) lead = new Lead();
   return lead;
  }
 
  public String getFieldName() {
   String s = ApexPages.currentPage().getParameters().get('fld');
   return s;
  }
 
  public List<SelectOption> getLeadFields() {
   List<SelectOption> options = new List<SelectOption>();
   options.add(new SelectOption('AnnualRevenue','Annual Revenue'));
   options.add(new SelectOption('Title','Title'));
   options.add(new SelectOption('No.OfEmployees','No. Of Employees'));
   return options;
  }
 
 
  public PageReference step1() {
   return Page.scoreRuleStep1;
  }
 
  public PageReference step2() {
   return Page.scoreRuleStep2;
  }
 
    public PageReference cancel() {
     PageReference leadsPage = new ApexPages.StandardController(lead).view();
     leadsPage.setRedirect(true);
     return leadsPage;
  }


  public PageReference save() {
   // Create an object and save the rule and field there
   // TODO: Save an object
  // Dont know what should be done here  

  // scoringRule__c myScoringRule = new scoringRule__c();
  // myScoringRule.Annual Revenue = lead.Revenue;
   PageReference leadPage = new ApexPages.StandardController(lead).view();
   leadPage.setRedirect(true);
   return leadPage;
 }

}