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

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: 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(){
                       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">
        body .bPageBlock .pbBody .red .pbSubheader{
        body .bPageBlock .pbBody .grey .pbSubheader{
        body .bPageBlock .pbBody .grey .pbSubheader h3{
        body .bPageBlock .pbBody .blue .pbSubheader{
       <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:pageBlockButtons location="bottom" >
    <apex:commandButton value="Save" action="{!save}"/>


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 ;