I have some code that is used both through a normally licensed user and through a "Site Guest User" for a public Force.com Site. I am aware that for the latter type of User Chatter capabilities are not supported.

My first go at adding a guard (to not insert a FeedItem and so avoid any error) was get the describe information for FeedItem and check the isCreateable but that returns true:

describe=Schema.DescribeSObjectResult[getKeyPrefix=0D5;getLabel=Feed Item;getLabelPlural=Feed Items;getName=FeedItem;isAccessible=true;isCreateable=true;isCustom=false;isCustomSetting=false;isDeletable=true;isDeprecatedAndHidden=false;isFeedEnabled=false;isMergeable=false;isQueryable=true;isSearchable=true;isUndeletable=false;isUpdateable=false;]

with the above produced by this test code when run through a Force.com Site:

public with sharing class TestController {
    public PageReference doit() {
        System.debug('describe=' + FeedItem.SobjectType.getDescribe());
        System.debug('user=' + UserInfo.getUserType());
        insert new FeedItem(
                        Type = 'LinkPost',
                        Title = 'Test title',
                        ParentId = 'a0N900000098HOdEAM',
                        LinkUrl = 'http://www.google.com',
                        Body = 'Test body'
        return null;

So I am looking for an alternative technique other than catching the DmlException:

DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Entity is read-only: FeedItem: []

I note that the UserInfo.getUserType() returns "Guest" instead of "Standard" when access is through a Force.com Site. Is that the best thing to use? In my org I see 8 possible values; are these documented anywhere?

1 Answer 1


Yes, you have it correct, I think your best bet is to use the UserInfo class. The getUserType() function that you called out is likely easiest. Alternatively, you could use getProfileId() to check to make sure you don't have the guest profile.

Also, there is a good overview of user types on this other Stack Exchange post: What are the possible options for UserType?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .