+ Start a Discussion
sparkysparky 

showing custom object name field as required

There have been a few posts about making fields show as required (little red bar):
* http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=2419
* http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=1254

in which SF folks say that in order to make the bar appear, just use an inputField element, and make the field required in your field definitions.

Fair enough, that seems to work most of the time.

However, in my current project I've got a custom object, and the Name field is included on a VF page.  And I'm using an inputField element, but it's not showing the red bar.  And moreover, if I leave the field blank, it gets filled in somehow with the ID of the record, rather than throwing an error.

I thought Name fields were required by definition.  If I edit the record in the standard layout, I get the red bar and leaving the Name blank throws an error.

I'm using the standard controller (with an extension).  Is this a bug?

Thanks much!
jwetzlerjwetzler
That is very weird.  I'll log a bug for it.  In the meantime can you just mark it as required="true"?  I think that should give you everything you need.
hisrinuhisrinu
Hi,

The name field will be stored with the id field.
Not only name field if there is any req fields, if you didn't provide any value to them then salesforce will automatically stores the record id.
So it is better to use either inputfield or you have to write your own error handling, if that field is null throw an error message before save.

Thanks
Srini
jwetzlerjwetzler
Sorry hisrinu but I don't think any of that is true.  In this case yes, we seem to be stuffing the id into the name of the custom object, but this does not happen for all required fields (I don't believe it happens for any other required fields, actually).  This original poster is already using inputField -- this is something wacky on our end and forcing it to be required="true" seems to take care of both the styling issues and the error handling.
JaggyJaggy

Hi Guys,

 

In 2012, I am also facing the same error. Am I missing something here?

 

<apex:page standardcontroller="Position__c"  >
    <apex:form>
        <apex:pageblock mode='edit'>
        
        <apex:pageblockButtons>
        <apex:commandButton action="{!save}" value="save"/>
        </apex:pageblockButtons>
        
        <apex:pageBlockSection>
        <apex:inputfield value="{!position__c.name}"  />
        </apex:pageBlockSection>
        
       </apex:pageblock>
        
    </apex:form>
</apex:page>

 

Paras @ E7Paras @ E7
Same Issue. Did anybody get solution ?