Jump to content
jereze

Search in Salesforce (Alfred 3 worklfow)

Recommended Posts

Description

 

Alfred 3 workflow to search in Salesforce.

 

salesforce-on-mac.gif.1f8a90f1080af17551288f87bedb703d.gif


Keywords

 

  • `sf [blabla]` to search for any contact, account, opportunity, lead
  • `sf > login` to connect
  • `sf > logout` to log out
  • `sf > debug` to write some debugs logs


Requirements

 

  • Alfred version 3.5 (should work on 3.0 or later)
  • Mac OS X 10.12 (not yet tested on 10.13, feedbacks welcome)
  • A Salesforce account with an access to the REST API

 

Resources

 

 

 

Edited by jereze

Share this post


Link to post

I love this!! Thank you for developing it.

 

There seems to be a bug. Occasionally, when I type in a command it says "Type at least two characters to search in Salesforce", no matter how many characters are in there. Then when I hit enter a notification pops up saying "New access token" and it starts working normally again. It's not a huge issue because it works fine after that, but I find it occasionally does this. Any idea why?

Thanks again for making this

Share this post


Link to post

Hi able,

 

Thank you very much for your feedback.

 

Hum, I'm not able to reproduce the bug you mention. Are you typing very fast when you get wrongly the "Type at least two characters to search in Salesforce" message?

 

About the notification: the token (ie. authorization) given by the Salesforce REST API expires after few hours. So the workflow needs to refresh the token every few hours. I should remove the notification.

 

I will wait for more feedbacks before releasing a new version with bugfixes.

Share this post


Link to post

Looks useful. I have a few observations from reading the code:

 

Is requests really necessary for this workflow? It looks like Alfred-Workflow's http library would be sufficient. The workflow's almost 20MB, and it looks like it could be under 500KB.

 

You might also want to consider skipping logging.basicConfig(). The Workflow object initialises a "smarter" logger. It logs to a file in the workflow's cache directory (so Dropbox won't constantly be syncing the logfile in the workflow directory) and uses a RotatingFileHandler to keep the size of the logfile sane. If you use Workflow.logger, you can then also enter workflow:openlog as a query to open the log file directly.

 

Also, you don't need to test the length of wf.args. Because you call the script with "$query" (in quotation marks) there will always be an argument, even if it's just an empty string.

Edited by deanishe

Share this post


Link to post
On 10/31/2017 at 3:41 PM, deanishe said:

Looks useful. I have a few observations from reading the code:

 

Is requests really necessary for this workflow? It looks like Alfred-Workflow's http library would be sufficient. The workflow's almost 20MB, and it looks like it could be under 500KB.

 

You might also want to consider skipping logging.basicConfig(). The Workflow object initialises a "smarter" logger. It logs to a file in the workflow's cache directory (so Dropbox won't constantly be syncing the logfile in the workflow directory) and uses a RotatingFileHandler to keep the size of the logfile sane. If you use Workflow.logger, you can then also enter workflow:openlog as a query to open the log file directly.

 

Also, you don't need to test the length of wf.args. Because you call the script with "$query" (in quotation marks) there will always be an argument, even if it's just an empty string.

 

Thank you deanishe. BTW, your library alfred-workflow is great, thank you for the great work.

 

In a first version, I was using Alfred-Workflow's http library but I had several Python SSL Errors. Using requests solved the issues. I thought including requests library would make the workflow more reliable across the different MacOS versions.

 

About the logging, that's a good suggestion you make. How can I use the logger of Workflow also in server.py that starts in a new process?

 

About the test on the length of wf.args, indeed, you are right. I will remove it.

 

Share this post


Link to post
2 hours ago, jereze said:

I had several Python SSL Errors

 

Oh right. Shame. Python's SSL support is pretty crappy.

 

2 hours ago, jereze said:

How can I use the logger of Workflow also in server.py that starts in a new process?

 

Just use it. I mean, you have a Workflow instance in there. It's the same logging library under the hood, so it will work just as well. The only thing you have to be really careful with when running parallel processes is Workflow.settings.

 

Share this post


Link to post

Hey there!

 

Thank you for building this - really cool workflow and it would be extremely useful for productivity! Unfortunately, I am encountering an error message when I try to open the search results because our org isn't using Lightning Experience, but rather Salesforce Classic. Any advice?

Screen Shot 2018-03-28 at 5.07.39 PM.png

Share this post


Link to post

Hi @wefikus!

 

Thanks for your message.

Can you confirm that you can search with the plugin but then you get an error when the page is opened in your browser? I will have a look at it very soon.

Share this post


Link to post
On 4/7/2018 at 4:01 AM, jereze said:

Hi @wefikus!

 

Thanks for your message.

Can you confirm that you can search with the plugin but then you get an error when the page is opened in your browser? I will have a look at it very soon.

Hi @jereze thanks for getting back to me!

Yes, the search itself works very well - the error message appears when I try to open the record in the browser.

Thanks a million for looking into this!

Share this post


Link to post

Hi everyone,

 

I am getting the following error:

5ad0de45a3888_ScreenShot2018-04-13at18_43_23.thumb.png.1cc4f258b78be0313ae6c9a4d3553432.png

 

Rest API is enabled for my account and SF organization. 

Does anyone know what I might be doing wrong? Any help would be greatly appreciated. I have been looking for this exact feature.

 

Best,

Benedikt

 

Share this post


Link to post

Hi @AcidAlfred, welcome to the forum.

 

Unfortunately, screenshots aren't much help diagnosing problems. We can't even see which URL caused the problem, or what the actual problem was.

 

Please read this thread about reporting issues for the information we need to help you.

Share this post


Link to post
Posted (edited)

Hi all,

 

I just published a new version (0.0.2). You should update manually (no auto update yet).

 

@wefikus : There is now an option to open links in Salesforce Classic. This should fix your issue.

 

@AcidAlfred : Indeed, some logs would be helpful. Also, do you know if your Salesforce organization has any IP restriction?

 

@deanishe : Thanks for your help :)

Edited by jereze
typo

Share this post


Link to post
Posted (edited)
16 minutes ago, jereze said:

Hi all,

 

I just published a new version (0.0.2). You should update manually (no auto update yet).

 

@wefikus : There is now an option to open link in Salesforce Classic. This should fix your issue.

 

@AcidAlfred : Indeed, some logs would be helpful. Also, do you know if your Salesforce organization has any IP restriction?

 

@deanishe : Thanks for your help :)

You're seriously awesome @jereze ! Thank you for such a quick turn around! Everything works flawlessly now!

Edited by wefikus

Share this post


Link to post

Thanks for the quick responses.

 

@deanishe Thank you for the Link

 

@wefikus It seems like there are no restricted IPs.

 

 

Below is the debugger output. I get the same error any time I start a "sf xxx" search. Logging in works fine.

 

Quote

[2018-04-15 17:29:32][STDERR: input.scriptfilter] 17:29:32 workflow.py:2225 DEBUG    Workflow version : 0.0.2
17:29:32 workflow.py:2633 DEBUG    Got password : jereze.salesforce:access_token
17:29:32 workflow.py:2633 DEBUG    Got password : jereze.salesforce:refresh_token
17:29:32 workflow.py:2633 DEBUG    Got password : jereze.salesforce:instance_url
17:29:32 workflow.py:1628 DEBUG    Reading settings from `/Users/xxx/Library/Application Support/Alfred 3/Workflow Data/jereze.salesforce/settings.json` ...
17:29:32 workflow.py:2423 DEBUG    Set last run version : 0.0.2
17:29:32 workflow.py:2267 DEBUG    Workflow finished in 0.135 seconds.
[2018-04-15 17:29:33][STDERR: input.scriptfilter] 17:29:32 workflow.py:2225 DEBUG    Workflow version : 0.0.2
17:29:32 workflow.py:2633 DEBUG    Got password : jereze.salesforce:access_token
17:29:32 workflow.py:2633 DEBUG    Got password : jereze.salesforce:refresh_token
17:29:33 workflow.py:2633 DEBUG    Got password : jereze.salesforce:instance_url
17:29:33 workflow.py:1628 DEBUG    Reading settings from `/Users/xxx/Library/Application Support/Alfred 3/Workflow Data/jereze.salesforce/settings.json` ...
17:29:33 workflow.py:2423 DEBUG    Set last run version : 0.0.2
17:29:33 workflow.py:2267 DEBUG    Workflow finished in 0.121 seconds.
[2018-04-15 17:29:38][ERROR: input.scriptfilter] Code 1: 17:29:33 workflow.py:2225 DEBUG    Workflow version : 0.0.2
17:29:33 workflow.py:2633 DEBUG    Got password : jereze.salesforce:access_token
17:29:33 workflow.py:2633 DEBUG    Got password : jereze.salesforce:refresh_token
17:29:33 workflow.py:2633 DEBUG    Got password : jereze.salesforce:instance_url
17:29:38 salesforce_api.py:50 INFO     API get call: https://eu10.salesforce.com/services/data/v40.0/search/?q=FIND+{lead}+IN+ALL+FIELDS+RETURNING+Account+(Id%2C+Name%2C+Type)%2C+Contact+(Id%2C+Name%2C+Email)%2C+Opportunity+(Id%2C+Name%2C+StageName%2C+CloseDate)%2C+Lead+(Id%2C+Name)+WITH+METADATA%3D'LABELS'+
17:29:38 salesforce_api.py:57 DEBUG    [{"message":"\nFIELDS RETURNING Account (Id, Name, Type), Contact (Id, Name, Email)\n                                    ^\nERROR at Row:1:Column:56\nNo such column 'Type' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.","errorCode":"INVALID_FIELD"}]
17:29:38 workflow.py:2243 ERROR    API error when calling https://eu10.salesforce.com/services/data/v40.0/search/?q=FIND+{lead}+IN+ALL+FIELDS+RETURNING+Account+(Id%2C+Name%2C+Type)%2C+Contact+(Id%2C+Name%2C+Email)%2C+Opportunity+(Id%2C+Name%2C+StageName%2C+CloseDate)%2C+Lead+(Id%2C+Name)+WITH+METADATA%3D'LABELS'+ (400): [{"message":"\nFIELDS RETURNING Account (Id, Name, Type), Contact (Id, Name, Email)\n                                    ^\nERROR at Row:1:Column:56\nNo such column 'Type' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.","errorCode":"INVALID_FIELD"}]
Traceback (most recent call last):
  File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.5E6052FE-B26B-4BBA-A171-21BC8E59264E/workflow/workflow.py", line 2236, in run
    func(self)
  File "salesforce_search.py", line 136, in main
    'q': "FIND {%s} IN ALL FIELDS RETURNING Account (Id, Name, Type), Contact (Id, Name, Email), Opportunity (Id, Name, StageName, CloseDate), Lead (Id, Name) WITH METADATA='LABELS' " % query.replace("\\", "\\\\").replace("'", "\\'")
  File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.5E6052FE-B26B-4BBA-A171-21BC8E59264E/salesforce_api.py", line 58, in api_call
    raise ValueError('API error when calling %s (%i): %s' % (r.url, r.status_code, r.text))
ValueError: API error when calling https://eu10.salesforce.com/services/data/v40.0/search/?q=FIND+{lead}+IN+ALL+FIELDS+RETURNING+Account+(Id%2C+Name%2C+Type)%2C+Contact+(Id%2C+Name%2C+Email)%2C+Opportunity+(Id%2C+Name%2C+StageName%2C+CloseDate)%2C+Lead+(Id%2C+Name)+WITH+METADATA%3D'LABELS'+ (400): [{"message":"\nFIELDS RETURNING Account (Id, Name, Type), Contact (Id, Name, Email)\n                                    ^\nERROR at Row:1:Column:56\nNo such column 'Type' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.","errorCode":"INVALID_FIELD"}]
17:29:38 workflow.py:2267 DEBUG    Workflow finished in 4.694 seconds.

 

 

Share this post


Link to post
5 minutes ago, AcidAlfred said:

Thanks for the quick responses.

 

@deanishe Thank you for the Link

 

@wefikus It seems like there are no restricted IPs.

 

 

Below is the debugger output. I get the same error any time I start a "sf xxx" search. Logging in works fine.

 

 

 

 

Here is the error: "No such column 'Type' on entity 'Account'"

The plugin tries to get the Type on Accounts (a standard field), but Salesforce API returns an error. Do you know if the field 'Type' is available and retrievable?

Share this post


Link to post

@jereze  Thanks for your help and excuse the late feedback. Indeed the "type" field in our org was hidden. After making it visible the search is now working. 

 

Do you think it would be possible to extend the workflow to be able to change e.g. the status of a lead?

 

Thanks a lot, this is great,

Benedikt

 

 

Share this post


Link to post

@AcidAlfred Sorry for answering late. Great that the plugin now works.

Updating fields with the plugin is possible. But which objects (leads, contacts, opportunities...) should be editable, and which of their field (only the status?)? If the plugin allows editing, it should be not too difficult to use, and generic enough so that it is useful for different people/organizations. For now I don't have enough visibility about this.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×