0
    <apex:page controller="MyController" tabStyle="Account"  showChat="false">
        <apex:form >
            <apex:pageBlock title="Congratulations {!$User.FirstName}">
                You belong to Account Name: <apex:inputField value="{!account.name}"/>
               <apex:commandButton action="{!save}" value="save"/></apex:pageblock>
        </apex:form>
    </apex:page>



    /* Apex class*/

    public class MyController {

        private final Account account;

        public MyController() {
            account = [SELECT Id, Name, Site FROM Account 
                       WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        }

        public Account getAccount() {
            return account;
        }

        public PageReference save() {
            update account;
            return null;
        }
    }




Unable to insert account name.any solution to get rid from below error:

System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:page> in page fresh14

誰でも最善の解決策を提案できますか。主な問題は、パブリック PageReference save() コードの「挿入」オプションにあります

誰でもコードを挿入できますか

また

挿入コードと更新コードの組み合わせ。

4

1 に答える 1

3
 public Account account {get;set;}       
 public MyController() {
        string accId =  ApexPages.currentPage().getParameters().get('id');
          if(accId  != null)           
           account = [SELECT Id, Name, Site FROM Account 
                       WHERE Id = :accId  ];
         else account = new Account ();
        }


        public PageReference save() {
            upsert account;
            return null;
        }
于 2013-06-12T05:31:02.273 に答える