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
Venkat Reddy sfdVenkat Reddy sfd 

Apex code not working. record not saving when i click on save button

Hi,
When I am saving my record i am getting this Error:
Attempted to upsert a null list
Error is in expression '{!save}' in component <apex:commandButton> in page brandpage: Class.Brandvfcontroller.save: line 15, column 1


here i am attaching my Apex code and VFcode. please correct it...
Thanks in Advance 
 
public with sharing class Brandvfcontroller {

 public METADATA_Brand__c bran;

  public void insertBrandvfcontroller(){
             bran = [SELECT Id, Name, BRAND_ABBR__c,BRAND_CODE__c,BRAND_END_DATE__c,BRAND_ID__c,BRAND_START_DATE__c,
                    DEFAULT_CAMPAIGN__c,Description__c,DISPLAY_FLAG__c,DISPLAY_SEQUENCE__c,Franchise__c,FRANCHISE_ID__c,
                       SRC_SYS_KEY__c,STATUS__c FROM METADATA_Brand__c WHERE Id =: ApexPages.currentPage().getParameters().get('id')];
      }
       public METADATA_Brand__c getbran(){
       return bran;
       
       }
          public PageReference save() {
             Upsert bran;
             PageReference pref = new ApexPages.StandardController(bran).view();
               return pref;    
  }
}
 
<apex:page controller="Brandvfcontroller" showHeader="false" sidebar="false">
  <style>
        body .bPageBlock .pbBody .red .pbSubheader{
            background-color:#c00000;
        }
        body .bPageBlock .pbBody .grey .pbSubheader{
            background-color:#c0c0c0;
        }
        body .bPageBlock .pbBody .grey .pbSubheader h3{
            color:#000;
        }
        body .bPageBlock .pbBody .blue .pbSubheader{
            background-color:#0000FF;
        }        
    </style>
       <apex:form >     
    <apex:pageBlock title="Brand">
                <apex:outputPanel styleClass="blue" >
                <apex:pageblockSection title="Brand Details" columns="2" collapsible="false">
     <apex:inputField value="{!bran.Name}"/>
     <apex:inputField value="{!bran.Franchise__c}"/>
     <apex:inputField value="{!bran.BRAND_ABBR__c}"/>
     <apex:inputField value="{!bran.BRAND_CODE__c}"/>
     <apex:inputField value="{!bran.Description__c}"/>
     <apex:inputField value="{!bran.BRAND_ID__c}"/>
     <apex:inputField value="{!bran.BRAND_END_DATE__c}"/>
     <apex:inputField value="{!bran.BRAND_START_DATE__c}"/>
     <apex:inputField value="{!bran.DEFAULT_CAMPAIGN__c}"/>
     <apex:inputField value="{!bran.DISPLAY_FLAG__c}"/>
     <apex:inputField value="{!bran.DISPLAY_SEQUENCE__c}"/>
     <apex:inputField value="{!bran.FRANCHISE_ID__c}"/>
     <apex:inputField value="{!bran.SRC_SYS_KEY__c}"/>
     <apex:inputField value="{!bran.STATUS__c}"/>
                    </apex:pageblockSection>
            </apex:outputPanel>
     <apex:pageBlockButtons location="bottom" >
    <apex:commandButton value="Save" action="{!save}"/>

    
   </apex:pageBlockButtons>
  </apex:pageBlock>
  </apex:form> 
</apex:page>

 
Deepak Kumar ShyoranDeepak Kumar Shyoran
Put a small condition before upserting list like 
if(bran.size != null && bran.size() > 0)
     upsert bran ;
Venkat Reddy sfdVenkat Reddy sfd
Method does not exist or incorrect signature: [SOBJECT:METADATA_Brand__c].size() at line 15 column 14


Hi Depak, Its giving Error.
Deepak Kumar ShyoranDeepak Kumar Shyoran
Ohh I made a mistake I pretend bran as List instance use this 
if(bran != null )
     upsert bran ;