4

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?

  • 2
    The BCC email address isn't limited to Google integration. See salesforce.stackexchange.com/questions/948/… for how to get it. – Daniel Hoechst Oct 23 '12 at 16:46
  • Thanks Daniel! I've voted up your answer to the related question for that part of the question, but I'll leave this question here as I think it will be helpful for other users to connect the dots between these two topics, plus part 1 of this question is really the main issue. – zachelrath Oct 23 '12 at 19:10
4

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...

emailtosalesforce@43krtb393randomtextyqkd3evtps4q6tzdwerdd008qjotwj6icl.g-cinxmas.g.le.salesforce.com

Hope this answers your question! :)

| improve this answer | |
  • Putting the GoogleAppsDomain and EmailServicesAddress for each user into a corresponding Formula field on the User object is a great solution. Not ideal for the EmailServicesAddress because it can change and you can't do triggers on that object, but if this was really a big issue, someone could always use a Scheduled Apex job to update it every day or something. – zachelrath Nov 2 '12 at 12:49
1

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');
system.debug(content.substring(start,start+100));

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

| improve this answer | |
  • this surely can't be the solution, there must be a way to query this from the database, or read it from the salesforce API – pjcarly Oct 25 '12 at 20:57
  • Yeah exactly my thoughts, going to play with this over the weekend, surely there has to be some discoverable change to the org metadata we can depend on. After that getting the info needed is the next challenge... :) – Andrew Fawcett Oct 26 '12 at 22:54
  • Wow, this is a hard-core hack. I can't recommend this to anyone else as an answer, but it is definitely creative, and it's pure Apex (e.g. no custom fields), so I'll give you +1 for that :) – zachelrath Nov 2 '12 at 12:47
  • 1
    @zachelrath "I'd like to thank the Academy..." ;) not my best piece of code and luckily I've never had to scrape Setup in "production quality" deliverables... But I think we all had our share of screenscraping, ugly hacks, Selenium/bookmarklets that would mass click checkboxes on profiles... Eh :D – eyescream Nov 2 '12 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.