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
Amita TatarAmita Tatar 

record not getting saved in the object

Hi all,
 I have below code. My VF page records are not getting saved in the database. I have used standard save.
Can you tell me where i am going wrong>?
class------------------------------------------------

public with sharing class createOpportunityClass{

public Lead lead {get;set;}
public List<Existing_Policies__c> exLst{get;set;}
public List<Existing_Policies__c> eList{get;set;}
public Id lId;
public String parameter {get;set;}

public createOpportunityClass(ApexPages.StandardSetController controller){
   lId = ApexPages.CurrentPage().getParameters().get('id');
   exLst = controller.getRecords();
   system.debug('***************exLst**********'+exLst);
   eList = [select Lead__r.Company, Lead__r.Name, Chose_not_to_take_cover__c, Cover_not_applicable__c, 
           Current_Broker__c, Current_Insurer__c, Insured_Elsewhere__c, Insured_via_Gauntlet__c,Renewal_Date__c,
            Lead__c, Notes_Comments__c, Policy_Type__c, Product_Cover_Type__c, Quotation_Requested__c from Existing_Policies__c where Lead__c =: lId];                               
}

public pagereference createOpportunity(){

Existing_Policies__c policy = [select Lead__r.Company, Lead__r.Name, Chose_not_to_take_cover__c, Cover_not_applicable__c, Current_Broker__c, 
                                 Current_Insurer__c, Insured_Elsewhere__c, Insured_via_Gauntlet__c,
                                 Lead__c, Notes_Comments__c, Policy_Type__c,Renewal_Date__c, Product_Cover_Type__c, Quotation_Requested__c from Existing_Policies__c where id =: parameter];                               
 
for(Existing_Policies__c ex : eList){
    if(ex.id == parameter){
        Opportunity o = new Opportunity();
        Account a = [select Id from Account where Name =: policy.Lead__r.Company limit 1];
        o.AccountId = a.Id;
        
        o.name = policy.Lead__r.Company + ' - ' + policy.Product_Cover_Type__c;
        o.Stagename = 'Pre-Qualification';
        o.CloseDate = date.Today();
        o.Chose_not_to_take_cover__c  = policy.Chose_not_to_take_cover__c;
        o.Cover_not_applicable__c  = policy.Cover_not_applicable__c ;
        o.Policy_Type3__c = policy.Policy_Type__c;
        o.Insured_via_Gauntlet__c  = policy.Insured_via_Gauntlet__c;
        o.Insured_Elsewhere__c = policy.Insured_Elsewhere__c;
        o.Notes_Comments__c = policy.Notes_Comments__c;
        o.Current_Broker__c = policy.Current_Broker__c;
        o.Product_Cover_Type__c = policy.Product_Cover_Type__c;
        o.Quotation_Requested__c = policy.Quotation_Requested__c ;
        o.Current_Insurer__c = policy.Current_Insurer__c;
        o.Renewal_Date__c = policy.Renewal_Date__c;
        insert o;
        PageReference pageRef = new PageReference('/' + o.id); 
        pageRef.setRedirect(true);
        return pageRef;
    } 
}    
return null;
}

}


PAGE---------------------------------------------------------

<apex:page standardController="Existing_Policies__c" recordSetVar="Existing_Policies__c"
tabStyle="Existing_Policies__c" sidebar="false" extensions="createOpportunityClass">

<apex:form >
<apex:pageBlock >
<apex:pageMessages />
    
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!eList}" var="a">

<apex:column value="{!a.Product_Cover_Type__c}"/>
<apex:column headerValue="Policy Type">
<apex:inputfield value="{!a.Policy_Type__c}"/>
</apex:column>

<apex:column headerValue="Insured via Gauntlet">
      <apex:inputfield value="{!a.Insured_via_Gauntlet__c}"/>
  </apex:column>
  <apex:column headerValue="Insured Elsewhere">
      <apex:inputfield value="{!a.Insured_Elsewhere__c}"/>
  </apex:column>
  <apex:column headerValue="Current Broker">
      <apex:inputfield value="{!a.Current_Broker__c}"/>
  </apex:column>
  <apex:column headerValue="Current Insurer">
      <apex:inputfield value="{!a.Current_Insurer__c}"/>
  </apex:column>
  <apex:column headerValue="Renewal Date">
      <apex:inputfield value="{!a.Renewal_Date__c}"/>
  </apex:column>
  <apex:column headerValue="Quotation Requested">
      <apex:inputfield value="{!a.Quotation_Requested__c}"/>
  </apex:column>
  <apex:column headerValue="Chose Not to take Cover">
      <apex:inputfield value="{!a.Chose_not_to_take_cover__c}"/>
  </apex:column>
  <apex:column headerValue="Cover Not Applicable" width="10PX">
      <apex:inputfield value="{!a.Cover_not_applicable__c }"/>
  </apex:column>
  <apex:column headerValue="Notes & Comments">
      <apex:inputfield value="{!a.Notes_Comments__c}"/>
  </apex:column>
  
  <apex:column style="width:150px" headerValue="Create Opportunity">
  <!--<apex:commandButton action="{!createOpportunity}" value="Create Opportunity"/>-->
      <apex:commandLink action="{!createOpportunity}" styleClass="btn" value="Create">
         <apex:param name="test" assignTo="{!parameter}" value="{!a.id}"/>
      </apex:commandLink> 
  </apex:column>
  
</apex:pageBlockTable>
<!-- <apex:panelGrid columns="2">
<apex:commandLink action="{!previous}">Previous</apex:commandlink>
<apex:commandLink action="{!next}">Next</apex:commandlink>
</apex:panelGrid>  -->

</apex:pageBlock>
</apex:form>
</apex:page>
Please help me out with what is wrong in my code.

Thanks,
Amita Tatar