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