Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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

action="{!$Action.Account.New}"
share|improve this answer
3  
I think you need to throw the URLFOR on that...{!URLFOR($Action.Account.New)} –  Peter Knolle Jan 30 '13 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! –  LaceySnr Jan 30 '13 at 1:34
    
Thank you both. Now the button works perfectly now. I voted up for both of you. –  Jie Feb 1 '13 at 22:19
add comment

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!
share|improve this answer
1  
This is also an interesting answer which I did not know before. I voted up. –  Jie Feb 1 '13 at 22:21
    
thanks :^] appreciated, considering you were already down the Visualforce path –  user320 Feb 1 '13 at 23:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.