Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {"$return_value":{"message":"Request failed with status code 500","name":"Error","stack":" at null.e.exports (/tmp/__pdg__/dist/code/4ef9e919b114da15d1f9c2bb4e9a4bf4ed93f5ae57f6f3df7ac4818ad961f84f/node_modules/.pnpm/[email protected]/node_modules/salesforce-webhooks/dist/index.js:1:6999)\n at null.e.exports (/tmp/__pdg__/dist/code/4ef9e919b114da15d1f9c2bb4e9a4bf4ed93f5ae57f6f3df7ac4818ad961f84f/node_modules/.pnpm/[email protected]/node_modules/salesforce-webhooks/dist/index.js:1:7822)\n at IncomingMessage.null (/tmp/__pdg__/dist/code/4ef9e919b114da15d1f9c2bb4e9a4bf4ed93f5ae57f6f3df7ac4818ad961f84f/node_modules/.pnpm/[email protected]/node_modules/salesforce-webhooks/dist/index.js:1:38018)\n at IncomingMessage.emit (events.js:412:35)\n at null.endReadableNT (internal/streams/readable.js:1333:12)\n at process.processTicksAndRejections (internal/process/task_queues.js:82:21)\n","config":{"url":"https://welcome.my.salesforce.com/services/Soap/s/50.0","method":"post","data":"<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n <env:Header>\n <urn:SessionHeader xmlns:urn=\"http://soap.sforce.com/2006/08/apex\">\n <urn:sessionId>00D3t000004iBCU!ARUAQBFoGodB5fyYPTh7jpmiey46DtKGpmqy3GBZEGdehKGoj3Fh7ik7O8JX3PXHNqITCU9ublA84f4Ksi.ZSNu5k5oQSZZF</urn:sessionId>\n </urn:SessionHeader>\n </env:Header>\n <env:Body>\n <compileAndTest xmlns=\"http://soap.sforce.com/2006/08/apex\">\n <CompileAndTestRequest>\n <classes>/**\n Copyright 2011 Mavens Consulting, Inc.\n\n Licensed under the Apache License, Version 2.0 (the "License");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an "AS IS" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n@isTest\npublic with sharing class SW_SObjectFactory_68096e24a3ddbdb6212a78 {\n public static Boolean FillAllFields = false;\n\n // Key : SobjectAPIName For ex. Account\n // Value : Map<String, Schema.SObjectField>, field map (k:fieldname, v:Schema.Sobjectfield)\n public static Profile userProfile = [\n SELECT Id\n FROM Profile\n WHERE Name = 'System Administrator'\n ];\n\n private static final Map<String, Map<String, Schema.SObjectField>> FieldMapCache =\n new Map<String, Map<String, Schema.SObjectField>>();\n\n private static final Map<String, Schema.SObjectType> GlobalDescribe =\n Schema.getGlobalDescribe();\n\n private static final Map<String, SObject> SObjectCache =\n new Map<String, SObject>();\n\n // Default Country and State\n // When Country and State Picklists are enabled, cannot dynamically resolve which States are within a Country\n public static string DefaultCountry = 'United States';\n public static string DefaultCountryCode = 'US';\n public static string DefaultState = 'Pennsylvania';\n public static string DefaultStateCode = 'PA';\n\n // Key: sobject.field\n // Value: first picklist value\n private static final Map<String, String> DefaultPicklistValue =\n new Map<String, String>();\n\n // can't map by Schema.sObjectType, use object name String instead\n public static Map<String, Set<String>> ExcludedFields = new Map<String, Set<String>> {\n 'All' => new Set<String> {\n 'CreatedById',\n 'CreatedDate',\n 'LastModifiedById',\n 'LastModifiedDate',\n 'OwnerId'\n },\n 'Account' => new Set<String> {\n 'FirstName',\n 'LastName'\n },\n 'User' => new Set<String> {\n 'CallCenterId',\n 'ContactId',\n 'DelegatedApproverId',\n 'FederationIdentifier',\n 'IsActive',\n 'ManagerId',\n 'UserRoleId'\n }\n };\n\n // include nillable fields\n public static Map<String, Set<String>> IncludedFields = new Map<String, Set<String>> {\n 'ContentVersion' => new Set<String> {\n 'ContentUrl'\n }\n };\n\n public static SObject createSObject(String objectType) {\n return createSObject(objectType, false);\n }\n\n public static List<SObject> createSObjectList(\n String objectType,\n Boolean cascade,\n Integer numberOfObjects\n ) {\n return createSObjectList(objectType, cascade, 0, numberOfObjects);\n }\n\n public static List<SObject> createSObjectList(\n String objectType,\n Boolean cascade,\n Integer initialCounter,\n Integer numberOfObjects\n ) {\n List<SObject> sos = new List<SObject>();\n for( Integer i = 0; i < numberOfObjects; i++ ) {\n SObjectCache.clear();\n Integer counter = i + initialCounter;\n sos.add(createSObject(objectType, cascade, counter));\n }\n return sos;\n }\n\n private static SObject newInstance(String objectType) {\n final Schema.sObjectType token = GlobalDescribe.get(objectType);\n if (token == null) {\n throw new IllegalArgumentException('Unsupported ObjectType ' + objectType);\n } else if (!token.getDescribe().isCreateable()) {\n System.debug(String.format(\n 'Type "{0}" is not createable, setting to "null"',\n new List<String> {\n objectType\n }\n ));\n return null;\n }\n return token.newSObject();\n }\n\n private static SObject getSObjectFromCache(String objectType, Boolean isRoot) {\n if (!SObjectCache.containsKey(objectType)) {\n final SObject obj = newInstance(objectType);\n SObjectCache.put(objectType, obj);\n return obj;\n }\n\n System.debug(String.format(\n 'Retrieving cached instance of type {0}',\n new List<String> {\n objectType\n }\n ));\n\n final SObject obj = SObjectCache.get(objectType);\n if (obj != null && obj.Id == null && !isRoot) {\n System.debug(String.format(\n 'Persisting cached object of type "{0}" since ' +\n 'it\\'s only in memory and doesn\\'t have an ID yet',\n new List<String> {\n objectType\n }\n ));\n insert obj;\n SObjectCache.put(objectType, obj);\n }\n\n return obj;\n }\n\n public static SObject createSObject(String objectType, Boolean cascade, Integer counter) {\n return createSObject(objectType, cascade, counter, true);\n }\n\n public static SObject createSObject(\n String objectType,\n Boolean cascade,\n Integer counter,\n Boolean isRoot\n ) {\n final SObject obj = getSObjectFromCache(objectType, isRoot);\n if (obj == null || obj.Id != null) {\n return obj;\n }\n\n for (Schema.SObjectField field : fieldMapFor(objectType).values()) {\n setFieldValue(obj, field, cascade, counter);\n }\n\n if (obj.Id == null && !isRoot) {\n System.debug('Inserting child node ' + obj);\n insert obj;\n }\n\n SObjectCache.put(objectType, obj);\n return obj;\n }\n\n public static SObject createSObject(String objectType, Boolean cascade) {\n return createSObject(objectType, cascade, 1);\n }\n\n /**\n Returns a field map for a given sobject.\n\n Note : this method is kept public for Test cases to share the same field map info, without requiring a field desribe.\n\n @param objectType sobject api name for ex. Account\n @returns FieldMap [Key:FieldName,Value:Schema.SObjectField]\n */\n public static Map<String, Schema.SObjectField> fieldMapFor(String objectType) {\n Map<String, Schema.SObjectField> fieldMap = null;\n String normalizedObjectType = objectType.toLowerCase();\n\n if (FieldMapCache.containsKey(normalizedObjectType)) {\n fieldMap = FieldMapCache.get(normalizedObjectType);\n } else {\n fieldMap = GlobalDescribe.get(objectType).getDescribe().fields.getMap();\n // cache it for next use\n FieldMapCache.put(normalizedObjectType, fieldMap);\n }\n\n return fieldMap;\n }\n\n static String getDefaultPicklistValue(SObject obj, Schema.DescribeFieldResult fieldDescribe) {\n String key = obj.getSObjectType() + '.' + fieldDescribe.getName();\n\n if (!DefaultPicklistValue.containsKey(key)) {\n List<Schema.PicklistEntry> entries = fieldDescribe.getPicklistValues();\n String value = entries.size() > 0 ? entries[0].getValue() : null;\n DefaultPicklistValue.put(key, value);\n }\n\n return DefaultPicklistValue.get(key);\n }\n\n static Boolean isExcludedField(Schema.DescribeFieldResult fieldDescribe) {\n return ExcludedFields.get('All').contains(fieldDescribe.getName());\n }\n\n static Boolean isExcludedField(SObject obj, Schema.DescribeFieldResult fieldDescribe) {\n Set<String> fields = ExcludedFields.get(obj.getSObjectType().getDescribe().getName());\n return fields == null ? false : fields.contains(fieldDescribe.getName());\n }\n\n static Boolean isIncludedField(SObject obj, Schema.DescribeFieldResult fieldDescribe) {\n Set<String> fields = includedFields.get(obj.getSObjectType().getDescribe().getName());\n return fields == null ? false : fields.contains(fieldDescribe.getName());\n }\n\n static Boolean isPersonAccountField(Schema.DescribeFieldResult fieldDescribe) {\n Boolean isPersonAccountEnabled = fieldMapFor('Account').get('IsPersonAccount') != null;\n Set<string> skipPersonAccountFields = new Set<string>{ 'Salutation' };\n\n Boolean CustomPerson = fieldDescribe.isCustom() && fieldDescribe.getName().endsWith('pc');\n Boolean StandardPerson = !fieldDescribe.isCustom() && fieldDescribe.getName().startsWith('Person');\n\n return (\n CustomPerson ||\n StandardPerson ||\n (isPersonAccountEnabled && skipPersonAccountFields.contains(fieldDescribe.getName()))\n );\n }\n\n static void setFieldValue(SObject obj, Schema.SObjectField field, Boolean cascade) {\n setFieldValue(obj, field, cascade, 0);\n }\n\n private static Boolean shouldIncludeField(\n Schema.DescribeFieldResult fieldDescribe,\n SObject obj,\n Boolean cascade\n ) {\n return (\n fieldDescribe.getName() == 'IsActive' ||\n (\n fieldDescribe.isCreateable() &&\n !fieldDescribe.isDefaultedOnCreate() &&\n (\n isIncludedField(obj, fieldDescribe) ||\n (\n (\n FillAllFields ||\n !fieldDescribe.isNillable() ||\n (\n // Always fill references with cascade if they are not nillable\n cascade &&\n fieldDescribe.getType() == Schema.DisplayType.Reference\n )\n ) &&\n !isExcludedField(fieldDescribe) &&\n !isExcludedField(obj, fieldDescribe) &&\n !isPersonAccountField(fieldDescribe)\n )\n )\n )\n );\n }\n\n static void setFieldValue(\n SObject obj,\n Schema.SObjectField field,\n Boolean cascade,\n Integer counter\n ) {\n Schema.DescribeFieldResult fieldDescribe = field.getDescribe();\n if (shouldIncludeField(fieldDescribe, obj, cascade)) {\n if (fieldDescribe.getType() == Schema.DisplayType.Picklist) {\n // Picklist goes first, since we potential values are ready to be grabbed,\n // and we can't really use any other value anyways.\n obj.put(field, getDefaultPicklistValue(obj, fieldDescribe));\n } else if (fieldDescribe.getName().endsWith('Country')) {\n obj.put(field, DefaultCountry);\n } else if (fieldDescribe.getName().endsWith('State')) {\n obj.put(field, DefaultState);\n } else if (fieldDescribe.getName().endsWith('CountryCode')) {\n obj.put(field, DefaultCountryCode);\n } else if (fieldDescribe.getName().endsWith('StateCode')) {\n obj.put(field, DefaultStateCode);\n } else if (\n fieldDescribe.getType() == Schema.DisplayType.URL ||\n fieldDescribe.getName().endsWith('Url')\n ) {\n String value = String.format(\n 'http://test{0}.com',\n new List<String> {\n counter.format()\n }\n );\n obj.put(field, value);\n } else if (fieldDescribe.getType() == Schema.DisplayType.base64) {\n Integer randomComponent = (Integer) (Math.random() * 1000);\n String value = String.format(\n '{0}-{1}',\n new List<String> {\n counter.format(),\n randomComponent.format()\n }\n );\n obj.put(field, Blob.valueOf(value));\n } else if (fieldDescribe.getType() == Schema.DisplayType.Boolean) {\n obj.put(field, true);\n } else if (fieldDescribe.getType() == Schema.DisplayType.Combobox) {\n obj.put(field, counter.format());\n } else if (fieldDescribe.getType() == Schema.DisplayType.Currency) {\n obj.put(field, counter);\n } else if (fieldDescribe.getType() == Schema.DisplayType.Date) {\n obj.put(field, Date.today());\n } else if (fieldDescribe.getType() == Schema.DisplayType.DateTime) {\n obj.put(field, DateTime.now());\n } else if (fieldDescribe.getType() == Schema.DisplayType.Double) {\n obj.put(field, counter);\n } else if (\n fieldDescribe.getName() == 'Username' ||\n fieldDescribe.getType() == Schema.DisplayType.Email\n ) {\n Long randomComponent = Math.roundToLong(Math.random() * 1000);\n String dateComponent = String.valueOf(Datetime.now().getTime());\n String value = String.format(\n 'test{0}{1}@test.com',\n new List<String> {\n randomComponent.format(),\n dateComponent\n }\n );\n obj.put(field, value);\n } else if (fieldDescribe.getType() == Schema.DisplayType.EncryptedString) {\n obj.put(field, 's');\n } else if (fieldDescribe.getType() == Schema.DisplayType.Id) {\n // Ignore, we don't specify ID's when creating objects.\n } else if (fieldDescribe.getType() == Schema.DisplayType.Integer) {\n Integer value = (Integer) (Math.random() * 30);\n obj.put(field, value);\n } else if (fieldDescribe.getType() == Schema.DisplayType.MultiPicklist) {\n obj.put(field, getDefaultPicklistValue(obj, fieldDescribe));\n } else if (fieldDescribe.getType() == Schema.DisplayType.Percent) {\n obj.put(field, counter);\n } else if (fieldDescribe.getType() == Schema.DisplayType.Phone) {\n obj.put(field, '123-456-7890');\n } else if (\n fieldDescribe.getName() == 'CommunityNickname' &&\n fieldDescribe.getType() == Schema.DisplayType.String\n ) {\n Long randomComponent = Math.roundToLong(Math.random() * 1000);\n String value = String.format(\n 'test{0}',\n new List<String> {\n randomComponent.format()\n }\n );\n obj.put(field, value);\n } else if (fieldDescribe.getType() == Schema.DisplayType.String) {\n Long randomComponent = Math.roundToLong(Math.random() * 1000);\n Integer maxLength = fieldDescribe.getLength();\n String preliminaryValue = String.format(\n 'a{0}{1}',\n new List<String> {\n counter.format(),\n randomComponent.format()\n }\n );\n Integer valueLength = Math.min(maxLength, preliminaryValue.length());\n String value = preliminaryValue.substring(0, valueLength);\n obj.put(field, value);\n } else if (fieldDescribe.getType() == Schema.DisplayType.Reference) {\n String referenceObjectType = fieldDescribe.getReferenceTo()[0].getDescribe().getName();\n\n if (referenceObjectType == 'RecordType') {\n setRecordType(obj);\n } else if (referenceObjectType == 'Profile') {\n obj.put(field,userProfile.Id);\n } else if (\n cascade &&\n referenceObjectType != obj.getSObjectType().getDescribe().getName() &&\n referenceObjectType != 'BusinessHours'\n ) {\n System.debug(\n String.format(\n 'Creating reference to {0} for field {1}.{2}',\n new List<String> {\n referenceObjectType,\n obj.getSObjectType().getDescribe().getName(),\n fieldDescribe.getName()\n }\n )\n );\n SObject reference = createSObject(referenceObjectType, cascade, counter + 1, false);\n if (reference == null) {\n System.debug('Skipping instance of type ' + referenceObjectType);\n obj.put(field, null);\n return;\n }\n\n obj.put(field, reference.Id);\n }\n } else if (fieldDescribe.getType() == Schema.DisplayType.TextArea) {\n obj.put(field, counter.format());\n } else if (fieldDescribe.getType() == Schema.DisplayType.Time) {\n obj.put(field, Time.newInstance(0, 0, 0, 0));\n } else {\n System.debug('Unhandled field type ' + fieldDescribe.getType());\n }\n }\n }\n\n static void setRecordType(SObject obj) {\n List<Schema.RecordTypeInfo> recordTypes = obj.getSObjectType().getDescribe().getRecordTypeInfos();\n if (recordTypes.size() > 1) { // All objects have default Master type\n for (Schema.RecordTypeInfo recordType : recordTypes) {\n if (recordType.isAvailable() && recordType.isDefaultRecordTypeMapping()) {\n obj.put('RecordTypeId', recordType.getRecordTypeId());\n }\n }\n }\n }\n}\n</classes>\n <classes>public abstract class SW_Callout_b49c07ec26f0c217c9a33fd1796c {\n\n public static String jsonContent(final Map<String, Object> eventContent) {\n final Map<String, Object> content = new Map<String, Object>(eventContent);\n content.put('UserId', UserInfo.getUserId());\n return JSON.serialize(content);\n }\n\n @future(callout=true)\n public static void callout(final String url, final String content) {\n final HttpRequest request = new HttpRequest();\n request.setEndpoint(url);\n request.setMethod('POST');\n request.setHeader('Content-Type', 'application/json');\n request.setHeader('X-Webhook-Token', 'secret');\n request.setBody(content);\n\n final Http http = new Http();\n http.send(request);\n }\n\n}\n</classes>\n <classes>@isTest\nglobal class SW_CalloutMock_6f12a05b60982152ddf5f330 implements HttpCalloutMock {\n private String endpointUrl;\n\n global SW_CalloutMock_6f12a05b60982152ddf5f330(String endpointUrl) {\n this.endpointUrl = endpointUrl;\n }\n\n global HTTPResponse respond(HTTPRequest req) {\n System.assertEquals('POST', req.getMethod());\n\n HttpResponse res = new HttpResponse();\n res.setHeader('Content-Type', 'application/json');\n res.setBody('{"example": "test"}');\n res.setStatusCode(200);\n return res;\n }\n}\n</classes>\n <classes>@isTest\npublic class SW_Test_f020bfc24f991495af4e28ff6cae171b {\n @isTest\n static void testBatch() {\n Test.enableChangeDataCapture();\n\n Test.setMock(HttpCalloutMock.class, new SW_CalloutMock_6f12a05b60982152ddf5f330('https://www.unexistent-endpoint-10845209472.com'));\n List<User> a =\n (List<User>) SW_SObjectFactory_68096e24a3ddbdb6212a78.createSObjectList('User', true, 4);\n insert a;\n\n Test.getEventBus().deliver();\n }\n @isTest\n static void testSingle() {\n Test.enableChangeDataCapture();\n\n Test.setMock(HttpCalloutMock.class, new SW_CalloutMock_6f12a05b60982152ddf5f330('https://www.unexistent-endpoint-10845209472.com'));\n User a = (User) SW_SObjectFactory_68096e24a3ddbdb6212a78.createSObject('User', true);\n insert a;\n\n Test.getEventBus().deliver();\n }\n}\n</classes>\n\n <triggers>trigger SW_Trigger_f35f8655a60e2cf72e0abc26174e on User (after insert) {\n final List<SObjectField> fields = User.getSObjectType()\n .getDescribe()\n .fields\n .getMap()\n .values();\n final List<String> fieldNames = new List<String>();\n for (SObjectField f : fields) {\n final String fieldName = f.getDescribe().getName();\n fieldNames.add(fieldName);\n }\n final String joinedFieldNames = String.join(fieldNames, ', ');\n for (SObject item : Trigger.New) {\n final String query = String.format(\n 'SELECT {0} FROM User WHERE Id = \\'\\'{1}\\'\\'',\n new List<String> {\n joinedFieldNames,\n String.valueOf(item.Id)\n }\n );\n final User itemFull = (User) Database.query(query);\n\n final Map<String, User> eventData = new Map<String, User>();\n eventData.put('New', itemFull);\n\n final String content = SW_Callout_b49c07ec26f0c217c9a33fd1796c.jsonContent(eventData);\n SW_Callout_b49c07ec26f0c217c9a33fd1796c.callout('https://www.unexistent-endpoint-10845209472.com', content);\n }\n}\n</triggers>\n\n <runTestsRequest>\n <allTests>true</allTests>\n </runTestsRequest>\n </CompileAndTestRequest>\n </compileAndTest>\n </env:Body>\n</env:Envelope>\n","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"text/xml","Authorization":"Bearer 00D3t000004iBCU!ARUAQBFoGodB5fyYPTh7jpmiey46DtKGpmqy3GBZEGdehKGoj3Fh7ik7O8JX3PXHNqITCU9ublA84f4Ksi.ZSNu5k5oQSZZF","SOAPAction":"compileAndTest","User-Agent":"axios/0.21.4","Content-Length":24281},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false}}}}
Add Comment
Please, Sign In to add comment