I have created a custom Visualforce page for when a User is editing a task. I also need to create one for when a User creates a new Task. The pages are almost identical except there are some extra fields in a separate PageBlockSection that are available in the Edit page that aren't available in the New record page.

Is it possible to create only one page and Hide or Show sections depending on if it is an edit or a new page?


Yes, assuming you are using standardController="Task" for the vf page, you can check to see if the record's Id has been set. If not, then it is a "new" record.

<!-- Don't show unless it is an existing record -->
<apex:pageBlockSection rendered="{!NOT(ISBLANK(Task.Id))}">

  • I am, I also have an extension that gathers that data for a couple of fields. Thanks! – Mike Jun 2 '15 at 16:46
  • Another question, If I wanted to only display if Task.Id is null, I'd just remove the ! correct? – Mike Jun 2 '15 at 16:58
  • Nevermind, I am dumb. just needed to remove the NOT – Mike Jun 2 '15 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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