function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt FolgerMatt Folger 

Rendering a delete button only when the record meets certain criteria

Hi, I'm trying to make the VF record view page that I created to have a Delete button that deletes the record, but only to render that when the record itself is owned by the user that's trying to delete it AND if a certain field in that record equals "Original".

Not sure how to do either, I've yet to make any VF code that directly uses something within the record itself.  

Is this possible? And can anyone point me in the right direction?
Best Answer chosen by Matt Folger
Shrikant BagalShrikant Bagal
@Matt use following code:
<apex:commandButton id="deleteBtn" 
                                value="Delete"     
                                action="{!Delete}" 
                                rendered="{!Record.OwnerId = $User.Id
                                 && Vencorr__c.Inquiry_Status__c= 'Original'}"/>

if resolved marked as answer.

All Answers

Shrikant BagalShrikant Bagal
<apex:commandButton id="deleteBtn"
                                value="Delete"     
                                action="{!URLFOR($Action.ObjectName.Delete,RecordId)}" 
                                rendered="{!Record.OwnerId = $User.ID AND conditionalField = 'Original'}"/>
@Matt Just Try above code, hope it will help you.
Matt FolgerMatt Folger
Thanks for the help!  But I'm having some difficulties.

---------------------------------------------

                <apex:commandButton id="deleteBtn" 
                                value="Delete"     
                                action="{!Delete}" 
                                rendered="{!Record.OwnerId = $User.ID
                                 AND Vencorr__c.Inquiry_Status__c= 'Original'}"/>

The above code gives me the following error:  Error: Syntax error. Found '$User.ID'

The code below gives me the error:  [Error] Error: Unknown property 'Vencorr__cStandardController.RecordId'

                <apex:commandButton id="deleteBtn" 
                                value="Delete"     
                                action="{!URLFOR($Action.Vencorr__c.Delete,RecordId)}"
                                rendered="{!Record.OwnerId = $User.ID
                                 AND Vencorr__c.Inquiry_Status__c= 'Original'}"/>


Am I missing something fairly obvious?

 
Shrikant BagalShrikant Bagal
@Matt use following code:
<apex:commandButton id="deleteBtn" 
                                value="Delete"     
                                action="{!Delete}" 
                                rendered="{!Record.OwnerId = $User.Id
                                 && Vencorr__c.Inquiry_Status__c= 'Original'}"/>

if resolved marked as answer.
This was selected as the best answer
Matt FolgerMatt Folger
Worked like a champ! Thanks!