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
Daniel RetaleatoDaniel Retaleato 

How can I get the name of the current app in the Apex Controller?

I need to get the name of the current app in the controller. So far I'm trying:
public static String getAppName() {
         UserAppInfo userAppInfo = [SELECT Id, AppDefinitionId FROM UserAppInfo WHERE UserId = :UserInfo.getUserId() LIMIT 1];
        AppDefinition appDefinition = [SELECT DurableId, Label FROM AppDefinition Where DurableId = :userAppInfo.AppDefinitionId LIMIT 1];
       return appDefinition.Label;
    }
But Im getting 3 errors:

Line 1: No such column 'AppDefinitionId' on entity 'UserAppInfo'
Line 2: Invalid type: AppDefinition
Line 3: Variable does not exist: appDefinition

Can anyone provide some insight as to what I may be doing wrong? Thanks!
Best Answer chosen by Daniel Retaleato
Khan AnasKhan Anas (Salesforce Developers) 
Hi Daniel,

Greetings to you!

Your code looks good to me. Make sure you are using API version 43.0 or later. As per the Salesforce doc, AppDefinitionId field on UserAppInfo object and AppDefinition object are available in API version 43.0 and later.

Please refer to the below links which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userappinfo.htm

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_appdefinition.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Daniel,

Greetings to you!

Your code looks good to me. Make sure you are using API version 43.0 or later. As per the Salesforce doc, AppDefinitionId field on UserAppInfo object and AppDefinition object are available in API version 43.0 and later.

Please refer to the below links which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userappinfo.htm

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_appdefinition.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Atla Satheesh 8Atla Satheesh 8
Hi Daniel,

I beleive the issue is with version
Daniel RetaleatoDaniel Retaleato
Thank you very much! The program is working as intended now.
david wolar 3david wolar 3
thanks for this info blogger at  : nifty blender (https://niftyblender.com/best-blender)
Robert HowardRobert Howard
Great discussion, thanks!
fsagfd gfdshgfsagfd gfdshg
Thank you for explaining these points. I'm working for custom home builders (https://cornerstonebuilthomes.com/) and I want to use the saleforce script for my business website.