4

I know we can create detail object from the master object by default. Like we can create contacts from account. But now I got a requirement to create Account from a Contact detail page. As we know, only the visualforce page which is using Contact standardcontroller can be added into a Contact page layout. But to call create() on Account, we have to use Account standardcontroller. So I tried to create a custom button calling a visualforce page which is using Account standardcontroller. Like below:

<apex:page standardController="Account" recordSetVar="accounts" tabStyle="account">
    <apex:form >
    <apex:pageBlock >
            <apex:commandButton action="{!create}" value="Create New Account"/>
            <apex:repeat value="{!accounts}" var="a">
                <apex:pageBlockSection columns="3" >
                    <apex:outputText value="{!a.Name}"/>
                    <apex:outputText value="{!a.BillingCity}"/>
                    <apex:outputText value="{!a.Phone}"/>
                </apex:pageBlockSection>
            </apex:repeat>   
    </apex:pageBlock>
    </apex:form>
</apex:page>

But I got the error: java.lang.UnsupportedOperationException: You cannot call create() on a non-null object .

I do not know how can I solve this problem now. Could anyone help me? Thanks

2 Answers 2

6

You probably want to be using the Account New action, rather than calling create:

action="{!$Action.Account.New}"
3
  • 4
    I think you need to throw the URLFOR on that...{!URLFOR($Action.Account.New)} Commented Jan 30, 2013 at 0:02
  • I didn't actually try the code but thought that might have been for when you use the link tag as opposed to a button... will have to check and find out!
    – Matt Lacey
    Commented Jan 30, 2013 at 1:34
  • Thank you both. Now the button works perfectly now. I voted up for both of you.
    – Jie
    Commented Feb 1, 2013 at 22:19
1

Very quick 'n dirty idea: how about "quick create"? Doesn't fit all cases but worth knowing about :^]

  1. Setup > Customize > User Interface > Show Quick Create

    setup quick add

  2. Create new detail record and open the lookup to the master

    account lookup

  3. hit the new button

    search

  4. create the master record

    new account record

Caveats:

  • won't display all fields!
  • won't work on all objects!
  • won't always be able to apply your validation rules!
2
  • 1
    This is also an interesting answer which I did not know before. I voted up.
    – Jie
    Commented Feb 1, 2013 at 22:21
  • thanks :^] appreciated, considering you were already down the Visualforce path Commented Feb 1, 2013 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .