+ Start a Discussion
Geoff SpozettaGeoff Spozetta 

Custom Logic - Show Only records created by the logged in User

Hi,

I'm looking to edit the logic on my views so that the logged in user can only see the records that they themselves have created for ordering purposes on a custom object. 

So far what I have is:


IF(
CreatedbyID = $User.id  )

However not really sure where to go from from here. Any assistances would be appreciated.
 
Best Answer chosen by Geoff Spozetta
kryzkryz
Hi Geoff,

I did not use any apex trigger to create this. I just created a custom formula field in an object with a return type as text then I use the formula i have provided you.

User-added image

All Answers

James LoghryJames Loghry
If you're talking about list views, you can do this by specifying the "Created By Alias" filter:

User-added image
Geoff SpozettaGeoff Spozetta
Hi James,

I'm looking to only display the records that the current user has created; If a different user is loggged in I want them to ony be able to see their records, so the user has to be a variable.

Regards,

Geoff
kryzkryz
You need to create the formula in your custom object with Text as a return type:
 
IF(CreatedById = $User.Id, "True", "False")
Save the formula. 

Then create a List View that has a filter:

Your_Formula_Field__c equals True
Geoff SpozettaGeoff Spozetta
Hi kryz,

I'm not sure I understand what you mean by text as a return type. Are you advising me to
 
<apex:outputtext "IF(CreatedById = $User.Id, "True", "False")>
</apextoutputtext>

Regards,

Geoff
 
kryzkryz
Hi Geoff,

I did not use any apex trigger to create this. I just created a custom formula field in an object with a return type as text then I use the formula i have provided you.

User-added image
This was selected as the best answer
kryzkryz
Right after creating the Formula field, you can now use that as a filter in your listviews:

User-added image
Geoff SpozettaGeoff Spozetta
Hi Kryz,

I'm creating the addtional filed, however I'm running into the following issue. I am using this on a custom object.:

Error: Field CreatedById may not be used in this type of formula
 
anto nirmalanto nirmal
Hey Geoff,

Instead of all this complication, Cant you just use the My Contacts/Accounts in the Filter Criteria?

As a common practice, if your question is answered, please choose 1 best answer.
Additionally you can give every answer a like if that answer is helpful to you.

Regards,
Anto Nirmal
Geoff SpozettaGeoff Spozetta
Hi Anto,

My understanding is that the most direct method is to tie the UserID to the View, rather than going through Contacts

Regards,


Geoff
Geoff SpozettaGeoff Spozetta
HJi Kryz,

I went back and read your reply properly, and its worked. you've solved a significant headache for me and I really appreciate your assistance