Code Monkey home page Code Monkey logo

salesforce-webhook-creator's Introduction

Salesforce Webhook Creator

This is a simple web app that makes it easy to create Webhooks on Salesforce. For usage info see: http://www.jamesward.com/2014/06/30/create-webhooks-on-salesforce-com

Either use a shared instance of this app: https://salesforce-webhook-creator.herokuapp.com/

Or deploy your own instance on Heroku:

  1. Create a new Connected App in Salesforce:

    1. Create a Connected App
    2. Check Enable OAuth Settings
    3. Set the Callback URL to http://localhost:9000/_oauth_callback
    4. In Available OAuth Scopes select Full access (full) and click Add
    5. Save the new Connected App and keep track of the Consumer Key & Consumer Secret for later use
  2. Deploy this app on Heroku: Deploy

  3. Edit the Connected App on Salesforce and update the Callback URL to be https://YOUR_APP_NAME.herokuapp.com/_oauth_callback

Local Dev

Run Locally:

export FORCE_CONSUMER_KEY=YOUR_CONSUMER_KEY
export FORCE_CONSUMER_SECRET=YOUR_CONSUMER_SECRET

./sbt run

Test:

export FORCE_CONSUMER_KEY=YOUR_CONSUMER_KEY
export FORCE_CONSUMER_SECRET=YOUR_CONSUMER_SECRET
export FORCE_USERNAME=YOUR_SALESFORCE_USERNAME
export FORCE_PASSWORD=YOUR_SALESFORCE_PASSWORD

./sbt test

salesforce-webhook-creator's People

Contributors

jamesward avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

salesforce-webhook-creator's Issues

Bug in SObjects and Webhooks

Hello,

I tried to create a webhook today and it has an error that prevents it from working. I have tried circumventing your UI and it still did not work.

Can you please check or point me in the right direction?

Sincerely, xban1x

Oops, an error occured

This exception has been logged with id 6nmngkpo4. I used this utility about a week ago with no issues on the sandbox account, now I'm getting the error above.

SObject drop-down is empty

No dropdown for Objects appears, does that mean my salesforce login does not have the proper permissions?

Does webhook creator work on a live environment?

Great job James! On line 144 in ForceUtil.scala, I noticed that you are using the tooling api to create Apex classes and triggers. The api docs indicate that you'll get an error if you attempt to use those methods on a "live" organization. Does this tool only work for Salesforce developer environments and sandboxes?

https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/intro_crud_operations.htm

PS: I need to dynamically create triggers on objects that user's select at runtime (on a live environment), so I was just looking through your code to see how you pulled it off.

Also - it seems that the Salesforce Streaming API is pretty new. Would you recommend using the Streaming API (over webhooks)? It seems that the benefit of using the streaming API is that you can create push notifications and subscribe / unsubscribe at runtime.

Tests fail on deployment to production

Hey @jamesward

I've created a webhook on my sandbox org and it all works great. I've moved the classes to prod using change sets (successful), but when I do to deploy the changes, it runs the unit tests which result in a failure

System.NullPointerException: Attempt to de-reference a null object 
Stack Trace: Class.Hijinx_Logs_to_StagingWebhookTriggerTest.testTrigger: line 81, column 1

The code at line 81 is:

System.assertEquals(200, response.getStatusCode());

Any idea what might be going on? I've tried running the tests in the sandbox and they pass, where they fail in prod.

System.CalloutException

First of all - great work with this project. It's been amazing so far but it appears that I'm bumping into one of Salesforce's idiosyncrasies.

When I try to run my test in production (not in a sandbox), I get the following test failure in the generated WebhookTriggerTest:

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out 
Stack Trace: Class.Webhook.callout: line 31, column 1

There's a couple of places that mention this error, here's one example: https://success.salesforce.com/issues_view?id=a1p30000000jbNMAAY

And my trigger code is here:

trigger BarkWebhookTrigger on Opportunity (after update,after insert) {

    String url = 'https://goodlord-bark.herokuapp.com/opportunity';

    String content = Webhook.jsonContent(Trigger.new, Trigger.old);

    Webhook.callout(url, content);

}

with everything else about the hook being default.

Please could I get some advice one what to do to work around this issue? I'm not sure how I'd modify the testcase to not perform an insert and callout...

Apex Trigger sends POST or GET?

Hello James, great article about Apex Trigger. I have a question regarding the call to external web service. How Apex Trigger sends the json data?

String url = 'https://echo-webhook.herokuapp.com/updatesite';
String content = Webhook.jsonContent(Trigger.new, Trigger.old);
Webhook.callout(url, content);

is it sending the data on the body by post, using json? or is sending the data using GET?

Thanks!

Empty sobjects list

When I login via salesforce-webhook-creator to my salesforce instance the sobjects list is empty.

Object validation error while trying to create a webhook

Hi there, when I try to create a webook, I get the following error

"System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Contact Type is required: [] && System.DmlException:"

Does it try to validate all objects before creating a webhook?

Not getting webhook notifications for customfields and contact tagging of an opportuntity

I have created a new web-hook for an opportunity. Then i went to my salesforce account and tagged a new product to an existing opportunity and got the webhook notification.
Then i have tagged a new contact to the same opportunity, But didn't receive any notification.
Same with custom-fields also.
We have some custom fields for an opportunity. I have modified those fields but i didn't get any web-hook notification.

Code Coverage

Hello,
When I generate the webhook with the wizard is created a test too but for some reasons when I deploy the trigger seems to have error related with code coverage

triggers have 0% code coverage. Each trigger must have at least 1% code coverage.

If the tool generate the test too why I have code coverage = 0%
Thanks

Attempting to create a webhook on production produces the error "Can not create Apex Class on an active organization."

Hi @jamesward

Have been using this for many years (via the hosted heroku site) and have had great success. I recently tried to set up webhooks on a Salesforce instance. It logged in successfully (to a production site) and allowed me to select the objects and then type in the details.

However, when I attempted to create the webhook, it gave the error "Can not create Apex Class on an active organization.".

Googling this error seems to indicate that you can't change a production site, but I'm not sure how it would apply to using your app. Can you please suggest if there's an issue within the app or a way around this?

Angular ng-repeat duplicate issue for SObjects

Seems the drop-down listing for available Salesforce Objects included duplicates in my test, which resulted in the following error:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: sobject in sobjects, Duplicate key: string:Lease
http://errors.angularjs.org/1.2.17/ngRepeat/dupes?p0=sobject%20in%20sobjects&p1=string%3ALease

Looks like a great resource though, have you come across this issue?

"The requested resource does not exist"

I'm creating the test webhook (with https://echo-webhook.herokuapp.com/) in a Salesforce Sandbox. I'm the admin of the Sandbox, so I should have all necessary permissions.

When I log in, I get the error: [{"message":"sObject type 'ApexTrigger' is not supported.","errorCode":"INVALID_TYPE"}]
Then, when I try to create a webhook, for any object, I get the error, "The requested resource does not exist".

Is this a permissions problem? If so, what permissions do I need? If not, how do I solve this?

Empty sobjects list

After I login via salesforce-webhook-creator to my Salesforce instance, the sobjects list is empty.

I'm using Salesforce Professional Edition, could this be the reason?

Here is the error message in browser console:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

<title>Error</title> <style> html, body, pre { margin: 0; padding: 0; font-family: Monaco, 'Lucida Console', monospace; background: #ECECEC; } h1 { margin: 0; background: #A31012; padding: 20px 45px; color: #fff; text-shadow: 1px 1px 1px rgba(0,0,0,.3); border-bottom: 1px solid #690000; font-size: 28px; } p#detail { margin: 0; padding: 15px 45px; background: #F5A0A0; border-top: 4px solid #D36D6D; color: #730000; text-shadow: 1px 1px 1px rgba(255,255,255,.3); font-size: 14px; border-bottom: 1px solid #BA7A7A; } </style>

Oops, an error occurred

    <p id="detail">
        This exception has been logged with id <strong>71ep04188</strong>.
    </p>

</body>

P.S. I'm aware of the existing similar issue, but it's closed and the details of the problem seem different from the one I'm experiencing.

Tests fail when object has required reference.

I wanted to use this to send a webhook message when a custom object Project was created.

The test failed because Project which is (Child_Opportunity__c) has a required Parent_Opportunity__c field that was not getting properly filled in the mock() apex class function.

Likewise the Parent_Opportunity__c had a required field Contact__c so it couldn't be mocked for the same reason.

I ultimately fixed this by adding these lines to the mock function:

...
else if (f.getType() == DisplayType.REFERENCE) {
   if (f.getName() == 'Parent_Opportunity__c') {
       SObject po = mock('Opportunity');
       insert po;
       o.put(f.getName(), po.Id);
   }
   else if (f.getName() == 'Contact__c') {
       SObject c = mock('Contact');
       insert c;
       o.put(f.getName(), c.Id);
   }
}

This made it so that when I did mock('Child_Opportunity__c') it worked.

Ostensibly this could be generalized but I don't know enough about salesforce to go from Parent_Opportunity__c -> Opportunity or Contact__c -> Contact.

Annoyingly this solution caused another error to show up in the test:
System.CalloutException, "You have uncommitted work pending. Please commit or rollback before calling out"

After much annoying work I found that editing the body of testTrigger() to:

//Test.startTest();
insert o;
update o;
delete o;
Test.startTest();
Test.stopTest();

fixed this exception.

Just thought I'd create this issue in case anyone else was faced with similar problems.

Unable to Proceed once login

Hi James,

I have cloned git hub project and make necessary configuration. After that when I ran application I am able to login into app, but after login I can't get page any other page. Even if I manually making other URL I can't get that page.

Please find below image every time I was getting after salesforce login.

capture

Creating webhooks fails - List has no rows for Assignment sObject

The specific error message is

System.DmlException: Update failed. First exception on row 0 with id 00516000004vpaaAAA; first error: FIELD_INTEGRITY_EXCEPTION, Cannot change profile for current user: [ProfileId] && System.QueryException: List has no rows for assignment to SObject

The only javascript error is a 500 response to "https://salesforce-webhook-creator.herokuapp.com/webhooks", which only contains the previous error message.

salesforce_webhook_creator

Any help would be appreciated.

Failure Due to Expected

Hi James,

Love what you built. It's allowed us to keep data in sync for one of our most important projects.

I'm now trying to set up an additional (similar) webhook call out, but for whatever reason, i'm getting this error. It seems like the code is expecting the webhook address I used earlier, and is failing as a result

Any idea how I can avoid this?


System.AssertException: Assertion Failed: Expected: https://vt9wy02642.execute-api.us-west-2.amazonaws.com/prod/webhook?id=21173308-ab26-47ba-9d21-307c29ff5ab0&action=pull, Actual: https://vt9wy02642.execute-api.us-west-2.amazonaws.com/prod/webhook?id=b40404f9-87d8-406a-b700-e1051f27254b&action=pullStack Trace:

Class.LoveCareGSPullWebhookTriggerTest.testTrigger: line 71, column 1

Crash trying to run locally

When I try to run locally I get the following crash when I try to navigate to the listening http server.

#sbt run
[info] Loading project definition from /home/betterlesson/crap/salesforce-webhook-creator/project
[info] Set current project to salesforce-webhook-creator (in build file:/home/betterlesson/crap/salesforce-webhook-creator/)
[info] Updating {file:/home/betterlesson/crap/salesforce-webhook-creator/}root...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.

--- (Running the application, auto-reloading is enabled) ---

[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Ctrl+D to stop and go back to the console...)

[info] Compiling 15 Scala sources and 1 Java source to /home/betterlesson/crap/salesforce-webhook-creator/target/scala-2.11/classes...
[info] JavaScript linting on 1 source(s)
[error] p.c.s.n.PlayRequestHandler - Exception caught in Netty
java.lang.NoClassDefFoundError: Could not initialize class play.api.http.DefaultHttpErrorHandler$
	at play.core.server.Server$class.logExceptionAndGetResult$1(Server.scala:45)
	at play.core.server.Server$class.getHandlerFor(Server.scala:65)
	at play.core.server.NettyServer.getHandlerFor(NettyServer.scala:47)
	at play.core.server.netty.PlayRequestHandler.handle(PlayRequestHandler.scala:82)
	at play.core.server.netty.PlayRequestHandler.channelRead(PlayRequestHandler.scala:163)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278)
	at com.typesafe.netty.http.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:129)
	at com.typesafe.netty.http.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:96)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)

Timeouts on Heroku

Hi James,

First off thanks for this app! I was able to get this up and running on Heroku connected to a sandbox Salesforce instance. When creating a new webhook the app seems to be hitting Heroku's 30 second request limit. Is this something you have seen with your app? It seems to be timing out for me in the call to ForceUtil.deployZip. Is the perhaps a sandbox thing? Any tips for digging deeper?

System.AsyncException: Future method cannot be called from a future or batch method: Webhook.callout(String, String)

Thanks for creating this webhook.

I've installed it and it seems to be mostly working, except sometimes I run into this error:

NodeWebhookOpportunitiesTrigger: execution of AfterUpdate

caused by: System.AsyncException: Future method cannot be called from a future or batch method: Webhook.callout(String, String)

It sounds like Salesforce doesn't allow a future method to be called from another future method or a batch job.

I'm going to try implementing this "defensive apex" pattern, but wondering if there's a better way.

public void defensiveFutureCall{
    if(System.isFuture() || System.isBatch()){
        regularSyncCall();
    } else {
        if(Limits.getFutureCalls() < Limits.getLimitFutureCalls()){
            doFutureCall();
        } else {
            // Do some explicit notification so that you know your @future call was denied
        }
    }
}

@future
public void doFutureCall(){
    regularSyncCall();
}

public void regularSyncCall(){
    // Put the code, that you'd otherwise put in your @future method, in here
}

https://salesforce.stackexchange.com/a/102200/121206

Sandbox oauth fails

When I click "Login via Salesforce" and try to login in my sandbox (even when I chose to "connect to a custom domain") it doesn't work and I am back to the salesforce-webhook-creator login page.

README.md file

Just a suggestion: a README would be nice, detailing how to install this and set it up.

Cannot delete the created webbhook

Hello, i have created webhook using the link https://salesforce-webhook-creator.herokuapp.com/app in my sandbox account. Since, i have created 3 of them for testing purpose, now i want to keep only one webhook. But i do not see the option from where i can delete the other two webhooks which are created.
image

Apex Test Failures

Hi,

I'm trying to create a Outgoing Change Set and when I run the Apex tests for the webhook class I get the following:

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out Stack Trace: Class.Webhook.callout: line 31, column 1

screen shot 2016-12-06 at 2 03 48 am

Any ideas?

Set environment variable on the apex trigger

Thanks for the work on this project!

Is there a way to set a different endpoint url when it's triggered from a production vs sandbox environment?

At the moment, i need to go and set the url in the trigger to be the production webhook endpoint before deploying the change set, and then reverting it back to sandbox for our staging environment setup with our salesforce sandbox.

Open-source License

Is this project open-source for use, modification and redistribution according to my personal requirements? I need to add delete webhook functionality

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.