Find your content:

Search form

You are here

Determine from Apex (or API) whether Google Apps integration is enabled


Is there any way to determine from Apex (or through the API if not in Apex) whether a Salesforce org has the Google Apps integration enabled?

If so, is there any way to access from Apex/API some of the Google Apps to Salesforce integration data, e.g. the user-specific Gmail-to-Salesforce BCC address?

Attribution to: zachelrath

Possible Suggestion/Solution #1

RE: 'Google Apps integration enabled?'

I can confirm $Organization.GoogleAppsDomain is available in custom formula fields. So you can create one of these on the User object and do this.

User me = [select GoogleAppsDomain__c from User where Id = :UserInfo.getUserId()];
System.debug('Google App Domain: ' + me.GoogleAppsDomain__c);

RE: 'the user-specific Gmail-to-Salesforce BCC address?'

This information is held in EmailServicesFunction and EmailServicesAddress objects.

Allowing you to do these queries to discover if the service is active and what the BCC address is.

System.debug('Is active? ' + 
      [select IsActive from EmailServicesFunction 
         where FunctionName = 'EmailToSalesforce'].IsActive);

System.debug('emailtosalesforce@' + 
      [select EmailDomainName from EmailServicesAddress 
         where RunAsUserId = :UserInfo.getUserId()].EmailDomainName);

The above should give you the BCC address, something like this...

Hope this answers your question! :)

Attribution to: Andrew Fawcett

Possible Suggestion/Solution #2

EDIT (thanks PJC)

I must have had a brainfart moment... there's a merge field $Organization.GoogleAppsDomain that could be used in formula fields, probably on VF pages too. But I failed to figure out how to get it from apex and SELECT on Organization object is equally fruitless...

Original answer

Very very crude idea but I'm too tired to play with xml parsers or pattern/matcher.

Would screenscraping of relevant setup page work for you?

Pagereference pageref = new Pagereference('/ui/setup/google/GoogleAppsSetupUi/d');
String content = pageref.getcontent().toString();

Integer start = content.lastIndexOf('Google Apps Domain');

outputs (among others) correct domain for me. Of course a check if current user is System Administrator etc. would be needed...

Attribution to: eyescream
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content