+ Start a Discussion
Janek HoltschneiderJanek Holtschneider 

Not able to deploy webhooks for Contacts and Price books

Error -
ystem.AssertException: Assertion Failed: Expected: webhook_url,
Actual: url
Stack Trace: Class.PriceBookWebhookTriggerTest.testTrigger: line 71, column 1   
Best Answer chosen by Janek Holtschneider
Abhishek BansalAbhishek Bansal
Hi Janek,

It seems like the url string is not returned properly from your trigger. If possible please add the trigger code and test class code.

Thanks,
Abhishek Bansal.

All Answers

Abhishek BansalAbhishek Bansal
Hi Janek,

It seems like the url string is not returned properly from your trigger. If possible please add the trigger code and test class code.

Thanks,
Abhishek Bansal.
This was selected as the best answer
Janek HoltschneiderJanek Holtschneider
I'm getting below error
System.AssertException: Assertion Failed: Expected: https://constacloud.in/CC110020/saunadev.com/panel/api/webhook-salesforce-pricebooks, Actual: https://clapi.clearlight-saunas.com.au/panel/api/webhook-salesforce-pricebooks
Stack Trace: Class.PriceBookWebhookTriggerTest.testTrigger: line 71, column 1
Janek HoltschneiderJanek Holtschneider
trigger code


trigger PriceBookSaunasWebhookTrigger on Pricebook2 (after update,after insert,after undelete,after delete) {

   String url = 'https://clapi.clearlight-saunas.com.au/panel/api/webhook-salesforce-pricebooks';

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

   Webhook.callout(url, content);

}

class code


public class PriceBookSaunasWebhookTriggerTest {

   static SObject mock(String sobjectName) {
       SObjectType t = Schema.getGlobalDescribe().get(sobjectName);

       SObject o = t.newSobject();

       Map<String, Schema.SObjectField> m = t.getDescribe().fields.getMap();

       for (String fieldName : m.keySet()) {
           DescribeFieldResult f = m.get(fieldName).getDescribe();
           if (!f.isNillable() && f.isCreateable() && !f.isDefaultedOnCreate()) {
               if (f.getType() == DisplayType.Boolean) {
                   o.put(f.getName(), false);
               }
               else if (f.getType() == DisplayType.Currency) {
                   o.put(f.getName(), 0);
               }
               else if (f.getType() == DisplayType.Date) {
                   o.put(f.getName(), Date.today());
               }
               else if (f.getType() == DisplayType.DateTime) {
                   o.put(f.getName(), System.now());
               }
               else if (f.getType() == DisplayType.Double) {
                   o.put(f.getName(), 0.0);
               }
               else if (f.getType() == DisplayType.Email) {
                   o.put(f.getName(), 'foo@foo.com');
               }
               else if (f.getType() == DisplayType.Integer) {
                   o.put(f.getName(), 0);
               }
               else if (f.getType() == DisplayType.Percent) {
                   o.put(f.getName(), 0);
               }
               else if (f.getType() == DisplayType.Phone) {
                   o.put(f.getName(), '555-555-1212');
               }
               else if (f.getType() == DisplayType.String) {
                   o.put(f.getName(), 'TEST');
               }
               else if (f.getType() == DisplayType.TextArea) {
                   o.put(f.getName(), 'TEST');
               }
               else if (f.getType() == DisplayType.Time) {
                   o.put(f.getName(), System.now().time());
               }
               else if (f.getType() == DisplayType.URL) {
                   o.put(f.getName(), 'http://foo.com');
               }
               else if (f.getType() == DisplayType.PickList) {
                   o.put(f.getName(), f.getPicklistValues()[0].getValue());
               }
           }
       }
       return o;
   }

   @isTest static void testTrigger() {
       SObject o = mock('Pricebook2');

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

       System.assertEquals(200, Webhook.response.getStatusCode());
       System.assertEquals('https://clapi.clearlight-saunas.com.au/panel/api/webhook-salesforce-pricebooks', Webhook.request.getEndpoint());

       if (Webhook.request != null) {
           Map<String, Object> jsonResponse = (Map<String, Object>) JSON.deserializeUntyped(Webhook.request.getBody());
 System.assertNotEquals(null, jsonResponse.get('userId'));
       }
   }

}