+ Start a Discussion
Janek HoltschneiderJanek Holtschneider 

Not able to deploy webhooks(contact)

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
AnudeepAnudeep (Salesforce Developers) 
Please post the trigger and test class code
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'));
       }
   }

}
AnudeepAnudeep (Salesforce Developers) 
Based on the text in the error message, it appears that the second assert statement is failing

https://constacloud.in/CC110020/saunadev.com/panel/api/webhook-salesforce-pricebooks, Actual: https://clapi.clearlight-saunas.com.au/panel/api/webhook-salesforce-pricebooks

Please replace 'https://clapi.clearlight-saunas.com.au/panel/api/webhook-salesforce-pricebooks' with https://constacloud.in/CC110020/saunadev.com/panel/api/webhook-salesforce-pricebooks