restforce 4.2.1 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/unhandled-salesforce-error.md +17 -0
  3. data/.github/dependabot.yml +10 -0
  4. data/.github/funding.yml +1 -0
  5. data/.github/workflows/build.yml +23 -0
  6. data/.github/workflows/faraday.yml +27 -0
  7. data/.rubocop.yml +5 -4
  8. data/CHANGELOG.md +115 -0
  9. data/CONTRIBUTING.md +21 -1
  10. data/Dockerfile +31 -0
  11. data/Gemfile +15 -7
  12. data/README.md +102 -24
  13. data/UPGRADING.md +67 -0
  14. data/docker-compose.yml +7 -0
  15. data/lib/restforce/abstract_client.rb +1 -0
  16. data/lib/restforce/collection.rb +27 -4
  17. data/lib/restforce/concerns/api.rb +3 -2
  18. data/lib/restforce/concerns/base.rb +2 -2
  19. data/lib/restforce/concerns/caching.rb +7 -0
  20. data/lib/restforce/concerns/composite_api.rb +104 -0
  21. data/lib/restforce/concerns/connection.rb +1 -1
  22. data/lib/restforce/concerns/picklists.rb +2 -2
  23. data/lib/restforce/concerns/streaming.rb +1 -3
  24. data/lib/restforce/config.rb +14 -9
  25. data/lib/restforce/error_code.rb +650 -0
  26. data/lib/restforce/file_part.rb +32 -0
  27. data/lib/restforce/mash.rb +8 -3
  28. data/lib/restforce/middleware/authentication.rb +1 -0
  29. data/lib/restforce/middleware/caching.rb +140 -15
  30. data/lib/restforce/middleware/json_request.rb +90 -0
  31. data/lib/restforce/middleware/json_response.rb +85 -0
  32. data/lib/restforce/middleware/logger.rb +14 -9
  33. data/lib/restforce/middleware/raise_error.rb +13 -5
  34. data/lib/restforce/middleware.rb +2 -0
  35. data/lib/restforce/version.rb +1 -1
  36. data/lib/restforce.rb +15 -14
  37. data/restforce.gemspec +13 -21
  38. data/spec/fixtures/sobject/list_view_results_success_response.json +151 -0
  39. data/spec/integration/abstract_client_spec.rb +56 -35
  40. data/spec/integration/data/client_spec.rb +6 -2
  41. data/spec/spec_helper.rb +24 -1
  42. data/spec/support/client_integration.rb +7 -7
  43. data/spec/support/concerns.rb +1 -1
  44. data/spec/support/fixture_helpers.rb +1 -3
  45. data/spec/support/middleware.rb +1 -2
  46. data/spec/unit/collection_spec.rb +38 -2
  47. data/spec/unit/concerns/api_spec.rb +22 -15
  48. data/spec/unit/concerns/authentication_spec.rb +6 -6
  49. data/spec/unit/concerns/caching_spec.rb +26 -0
  50. data/spec/unit/concerns/composite_api_spec.rb +143 -0
  51. data/spec/unit/concerns/connection_spec.rb +2 -2
  52. data/spec/unit/concerns/streaming_spec.rb +4 -4
  53. data/spec/unit/config_spec.rb +2 -2
  54. data/spec/unit/error_code_spec.rb +61 -0
  55. data/spec/unit/mash_spec.rb +5 -0
  56. data/spec/unit/middleware/authentication/jwt_bearer_spec.rb +24 -8
  57. data/spec/unit/middleware/authentication/password_spec.rb +12 -4
  58. data/spec/unit/middleware/authentication/token_spec.rb +12 -4
  59. data/spec/unit/middleware/authentication_spec.rb +14 -8
  60. data/spec/unit/middleware/gzip_spec.rb +2 -2
  61. data/spec/unit/middleware/raise_error_spec.rb +29 -10
  62. data/spec/unit/signed_request_spec.rb +1 -1
  63. metadata +64 -187
  64. data/.circleci/config.yml +0 -56
  65. data/lib/restforce/upload_io.rb +0 -9
@@ -0,0 +1,650 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Restforce
4
+ module ErrorCode
5
+ GITHUB_ISSUE_URL = "https://github.com/restforce/restforce/issues/new?template=" \
6
+ "unhandled-salesforce-error.md&title=Unhandled+Salesforce+error" \
7
+ "%3A+%3Cinsert+error+code+here%3E"
8
+
9
+ # We define all of the known errors returned by Salesforce based on the
10
+ # documentation at
11
+ # https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm#statuscode
12
+ # Previously, these were defined dynamically at runtime using `Module.const_set`. Now
13
+ # we define them up-front.
14
+ # It is possible that we will be missing some errors, so we will handle this in
15
+ # at least a semi-graceful manner.
16
+ class AllOrNoneOperationRolledBack < ResponseError; end
17
+
18
+ class AlreadyInProcess < ResponseError; end
19
+
20
+ class ApexError < ResponseError; end
21
+
22
+ class ApiCurrentlyDisabled < ResponseError; end
23
+
24
+ class ApiDisabledForOrg < ResponseError; end
25
+
26
+ class AssigneeTypeRequired < ResponseError; end
27
+
28
+ class BadCustomEntityParentDomain < ResponseError; end
29
+
30
+ class BccNotAllowedIfBccComplianceEnabled < ResponseError; end
31
+
32
+ class BccSelfNotAllowedIfBccComplianceEnabled < ResponseError; end
33
+
34
+ class BigObjectUnsupportedOperation < ResponseError; end
35
+
36
+ class CannotCascadeProductActive < ResponseError; end
37
+
38
+ class CannotChangeFieldTypeOfApexReferencedField < ResponseError; end
39
+
40
+ class CannotCreateAnotherManagedPackage < ResponseError; end
41
+
42
+ class CannotDeactivateDivision < ResponseError; end
43
+
44
+ class CannotDeleteLastDatedConversionRate < ResponseError; end
45
+
46
+ class CannotDeleteManagedObject < ResponseError; end
47
+
48
+ class CannotDisableLastAdmin < ResponseError; end
49
+
50
+ class CannotEnableIpRestrictRequests < ResponseError; end
51
+
52
+ class CannotExecuteFlowTrigger < ResponseError; end
53
+
54
+ class CannotInsertUpdateActivateEntity < ResponseError; end
55
+
56
+ class CannotModifyManagedObject < ResponseError; end
57
+
58
+ class CannotRenameApexReferencedField < ResponseError; end
59
+
60
+ class CannotRenameApexReferencedObject < ResponseError; end
61
+
62
+ class CannotReparentRecord < ResponseError; end
63
+
64
+ class CannotResolveName < ResponseError; end
65
+
66
+ class CannotUpdateConvertedLead < ResponseError; end
67
+
68
+ class CantDisableCorpCurrency < ResponseError; end
69
+
70
+ class CantUnsetCorpCurrency < ResponseError; end
71
+
72
+ class ChildShareFailsParent < ResponseError; end
73
+
74
+ class CircularDependency < ResponseError; end
75
+
76
+ class CommunityNotAccessible < ResponseError; end
77
+
78
+ class CustomClobFieldLimitExceeded < ResponseError; end
79
+
80
+ class CustomEntityOrFieldLimit < ResponseError; end
81
+
82
+ class CustomFieldIndexLimitExceeded < ResponseError; end
83
+
84
+ class CustomIndexExists < ResponseError; end
85
+
86
+ class CustomLinkLimitExceeded < ResponseError; end
87
+
88
+ class CustomMetadataLimitExceeded < ResponseError; end
89
+
90
+ class CustomSettingsLimitExceeded < ResponseError; end
91
+
92
+ class CustomTabLimitExceeded < ResponseError; end
93
+
94
+ class DeleteFailed < ResponseError; end
95
+
96
+ class DependencyExists < ResponseError; end
97
+
98
+ class DuplicateCaseSolution < ResponseError; end
99
+
100
+ class DuplicateCustomEntityDefinition < ResponseError; end
101
+
102
+ class DuplicateCustomTabMotif < ResponseError; end
103
+
104
+ class DuplicateDeveloperName < ResponseError; end
105
+
106
+ class DuplicatesDetected < ResponseError; end
107
+
108
+ class DuplicateExternalId < ResponseError; end
109
+
110
+ class DuplicateMasterLabel < ResponseError; end
111
+
112
+ class DuplicateSenderDisplayName < ResponseError; end
113
+
114
+ class DuplicateUsername < ResponseError; end
115
+
116
+ class DuplicateValue < ResponseError; end
117
+
118
+ class EmailAddressBounced < ResponseError; end
119
+
120
+ class EmailNotProcessedDueToPriorError < ResponseError; end
121
+
122
+ class EmailOptedOut < ResponseError; end
123
+
124
+ class EmailTemplateFormulaError < ResponseError; end
125
+
126
+ class EmailTemplateMergefieldAccessError < ResponseError; end
127
+
128
+ class EmailTemplateMergefieldError < ResponseError; end
129
+
130
+ class EmailTemplateMergefieldValueError < ResponseError; end
131
+
132
+ class EmailTemplateProcessingError < ResponseError; end
133
+
134
+ class EmptyScontrolFileName < ResponseError; end
135
+
136
+ class EntityFailedIflastmodifiedOnUpdate < ResponseError; end
137
+
138
+ class EntityIsArchived < ResponseError; end
139
+
140
+ class EntityIsDeleted < ResponseError; end
141
+
142
+ class EntityIsLocked < ResponseError; end
143
+
144
+ class EnvironmentHubMembershipConflict < ResponseError; end
145
+
146
+ class ErrorInMailer < ResponseError; end
147
+
148
+ class ExceededIdLimit < ResponseError; end
149
+
150
+ class ExceededMaxSemijoinSubselects < ResponseError; end
151
+
152
+ class FailedActivation < ResponseError; end
153
+
154
+ class FieldCustomValidationException < ResponseError; end
155
+
156
+ class FieldFilterValidationException < ResponseError; end
157
+
158
+ class FieldIntegrityException < ResponseError; end
159
+
160
+ class FilteredLookupLimitExceeded < ResponseError; end
161
+
162
+ class Forbidden < ResponseError; end
163
+
164
+ class HtmlFileUploadNotAllowed < ResponseError; end
165
+
166
+ class IllegalQueryParameterValue < ResponseError; end
167
+
168
+ class ImageTooLarge < ResponseError; end
169
+
170
+ class InactiveOwnerOrUser < ResponseError; end
171
+
172
+ class InsertUpdateDeleteNotAllowedDuringMaintenance < ResponseError; end
173
+
174
+ class InsufficientAccessOnCrossReferenceEntity < ResponseError; end
175
+
176
+ class InsufficientAccessOrReadonly < ResponseError; end
177
+
178
+ class InvalidAccessLevel < ResponseError; end
179
+
180
+ class InvalidArgumentType < ResponseError; end
181
+
182
+ class InvalidAssigneeType < ResponseError; end
183
+
184
+ class InvalidAssignmentRule < ResponseError; end
185
+
186
+ class InvalidBatchOperation < ResponseError; end
187
+
188
+ class InvalidContentType < ResponseError; end
189
+
190
+ class InvalidCreditCardInfo < ResponseError; end
191
+
192
+ class InvalidCrossReferenceKey < ResponseError; end
193
+
194
+ class InvalidCrossReferenceTypeForField < ResponseError; end
195
+
196
+ class InvalidCurrencyConvRate < ResponseError; end
197
+
198
+ class InvalidCurrencyCorpRate < ResponseError; end
199
+
200
+ class InvalidCurrencyIso < ResponseError; end
201
+
202
+ class InvalidEmailAddress < ResponseError; end
203
+
204
+ class InvalidEmptyKeyOwner < ResponseError; end
205
+
206
+ class InvalidEventSubscription < ResponseError; end
207
+
208
+ class InvalidField < ResponseError; end
209
+
210
+ class InvalidFieldForInsertUpdate < ResponseError; end
211
+
212
+ class InvalidFieldWhenUsingTemplate < ResponseError; end
213
+
214
+ class InvalidFilterAction < ResponseError; end
215
+
216
+ class InvalidIdField < ResponseError; end
217
+
218
+ class InvalidInetAddress < ResponseError; end
219
+
220
+ class InvalidLineitemCloneState < ResponseError; end
221
+
222
+ class InvalidMasterOrTranslatedSolution < ResponseError; end
223
+
224
+ class InvalidMessageIdReference < ResponseError; end
225
+
226
+ class InvalidOperation < ResponseError; end
227
+
228
+ class InvalidOperationWithExpiredPassword < ResponseError; end
229
+
230
+ class InvalidOperator < ResponseError; end
231
+
232
+ class InvalidOrNullForRestrictedPicklist < ResponseError; end
233
+
234
+ class InvalidQueryFilterOperator < ResponseError; end
235
+
236
+ class InvalidQueryLocator < ResponseError; end
237
+
238
+ class InvalidPartnerNetworkStatus < ResponseError; end
239
+
240
+ class InvalidPersonAccountOperation < ResponseError; end
241
+
242
+ class InvalidReadOnlyUserDml < ResponseError; end
243
+
244
+ class InvalidReplicationDate < ResponseError; end
245
+
246
+ class InvalidSaveAsActivityFlag < ResponseError; end
247
+
248
+ class InvalidSessionId < ResponseError; end
249
+
250
+ class InvalidSignupCountry < ResponseError; end
251
+
252
+ class InvalidStatus < ResponseError; end
253
+
254
+ class InvalidType < ResponseError; end
255
+
256
+ class InvalidTypeForOperation < ResponseError; end
257
+
258
+ class InvalidTypeOnFieldInRecord < ResponseError; end
259
+
260
+ class IpRangeLimitExceeded < ResponseError; end
261
+
262
+ class JigsawImportLimitExceeded < ResponseError; end
263
+
264
+ class JsonParserError < ResponseError; end
265
+
266
+ class LicenseLimitExceeded < ResponseError; end
267
+
268
+ class LightPortalUserException < ResponseError; end
269
+
270
+ class LimitExceeded < ResponseError; end
271
+
272
+ class LoginChallengeIssued < ResponseError; end
273
+
274
+ class LoginChallengePending < ResponseError; end
275
+
276
+ class LoginMustUseSecurityToken < ResponseError; end
277
+
278
+ class MalformedId < ResponseError; end
279
+
280
+ class MalformedQuery < ResponseError; end
281
+
282
+ class MalformedSearch < ResponseError; end
283
+
284
+ class ManagerNotDefined < ResponseError; end
285
+
286
+ class MassmailRetryLimitExceeded < ResponseError; end
287
+
288
+ class MassMailLimitExceeded < ResponseError; end
289
+
290
+ class MaximumCcemailsExceeded < ResponseError; end
291
+
292
+ class MaximumDashboardComponentsExceeded < ResponseError; end
293
+
294
+ class MaximumHierarchyLevelsReached < ResponseError; end
295
+
296
+ class MaximumSizeOfAttachment < ResponseError; end
297
+
298
+ class MaximumSizeOfDocument < ResponseError; end
299
+
300
+ class MaxActionsPerRuleExceeded < ResponseError; end
301
+
302
+ class MaxActiveRulesExceeded < ResponseError; end
303
+
304
+ class MaxApprovalStepsExceeded < ResponseError; end
305
+
306
+ class MaxFormulasPerRuleExceeded < ResponseError; end
307
+
308
+ class MaxRulesExceeded < ResponseError; end
309
+
310
+ class MaxRuleEntriesExceeded < ResponseError; end
311
+
312
+ class MaxTaskDescriptionExceeded < ResponseError; end
313
+
314
+ class MaxTmRulesExceeded < ResponseError; end
315
+
316
+ class MaxTmRuleItemsExceeded < ResponseError; end
317
+
318
+ class MergeFailed < ResponseError; end
319
+
320
+ class MethodNotAllowed < ResponseError; end
321
+
322
+ class MissingArgument < ResponseError; end
323
+
324
+ class NonuniqueShippingAddress < ResponseError; end
325
+
326
+ class NoApplicableProcess < ResponseError; end
327
+
328
+ class NoAttachmentPermission < ResponseError; end
329
+
330
+ class NoInactiveDivisionMembers < ResponseError; end
331
+
332
+ class NoMassMailPermission < ResponseError; end
333
+
334
+ class NumberOutsideValidRange < ResponseError; end
335
+
336
+ class NumHistoryFieldsBySobjectExceeded < ResponseError; end
337
+
338
+ class OpWithInvalidUserTypeException < ResponseError; end
339
+
340
+ class OperationTooLarge < ResponseError; end
341
+
342
+ class OptedOutOfMassMail < ResponseError; end
343
+
344
+ class PackageLicenseRequired < ResponseError; end
345
+
346
+ class PlatformEventEncryptionError < ResponseError; end
347
+
348
+ class PlatformEventPublishingUnavailable < ResponseError; end
349
+
350
+ class PlatformEventPublishFailed < ResponseError; end
351
+
352
+ class PortalUserAlreadyExistsForContact < ResponseError; end
353
+
354
+ class PrivateContactOnAsset < ResponseError; end
355
+
356
+ class QueryTimeout < ResponseError; end
357
+
358
+ class RecordInUseByWorkflow < ResponseError; end
359
+
360
+ class RequestLimitExceeded < ResponseError; end
361
+
362
+ class RequestRunningTooLong < ResponseError; end
363
+
364
+ class RequiredFieldMissing < ResponseError; end
365
+
366
+ class SelfReferenceFromTrigger < ResponseError; end
367
+
368
+ class ServerUnavailable < ResponseError; end
369
+
370
+ class ShareNeededForChildOwner < ResponseError; end
371
+
372
+ class SingleEmailLimitExceeded < ResponseError; end
373
+
374
+ class StandardPriceNotDefined < ResponseError; end
375
+
376
+ class StorageLimitExceeded < ResponseError; end
377
+
378
+ class StringTooLong < ResponseError; end
379
+
380
+ class TabsetLimitExceeded < ResponseError; end
381
+
382
+ class TemplateNotActive < ResponseError; end
383
+
384
+ class TerritoryRealignInProgress < ResponseError; end
385
+
386
+ class TextDataOutsideSupportedCharset < ResponseError; end
387
+
388
+ class TooManyApexRequests < ResponseError; end
389
+
390
+ class TooManyEnumValue < ResponseError; end
391
+
392
+ class TransferRequiresRead < ResponseError; end
393
+
394
+ class UnableToLockRow < ResponseError; end
395
+
396
+ class UnavailableRecordtypeException < ResponseError; end
397
+
398
+ class UndeleteFailed < ResponseError; end
399
+
400
+ class UnknownException < ResponseError; end
401
+
402
+ class UnspecifiedEmailAddress < ResponseError; end
403
+
404
+ class UnsupportedApexTriggerOperation < ResponseError; end
405
+
406
+ class UnverifiedSenderAddress < ResponseError; end
407
+
408
+ class WeblinkSizeLimitExceeded < ResponseError; end
409
+
410
+ class WeblinkUrlInvalid < ResponseError; end
411
+
412
+ class WrongControllerType < ResponseError; end
413
+
414
+ # Maps `errorCode`s returned from Salesforce to the exception class
415
+ # to be used for these errors
416
+ ERROR_EXCEPTION_CLASSES = {
417
+ "ALL_OR_NONE_OPERATION_ROLLED_BACK" => AllOrNoneOperationRolledBack,
418
+ "ALREADY_IN_PROCESS" => AlreadyInProcess,
419
+ "APEX_ERROR" => ApexError,
420
+ "API_CURRENTLY_DISABLED" => ApiCurrentlyDisabled,
421
+ "API_DISABLED_FOR_ORG" => ApiDisabledForOrg,
422
+ "ASSIGNEE_TYPE_REQUIRED" => AssigneeTypeRequired,
423
+ "BAD_CUSTOM_ENTITY_PARENT_DOMAIN" => BadCustomEntityParentDomain,
424
+ "BCC_NOT_ALLOWED_IF_BCC_COMPLIANCE_ENABLED" =>
425
+ BccNotAllowedIfBccComplianceEnabled,
426
+ "BCC_SELF_NOT_ALLOWED_IF_BCC_COMPLIANCE_ENABLED" =>
427
+ BccSelfNotAllowedIfBccComplianceEnabled,
428
+ "BIG_OBJECT_UNSUPPORTED_OPERATION" => BigObjectUnsupportedOperation,
429
+ "CANNOT_CASCADE_PRODUCT_ACTIVE" => CannotCascadeProductActive,
430
+ "CANNOT_CHANGE_FIELD_TYPE_OF_APEX_REFERENCED_FIELD" =>
431
+ CannotChangeFieldTypeOfApexReferencedField,
432
+ "CANNOT_CREATE_ANOTHER_MANAGED_PACKAGE" => CannotCreateAnotherManagedPackage,
433
+ "CANNOT_DEACTIVATE_DIVISION" => CannotDeactivateDivision,
434
+ "CANNOT_DELETE_LAST_DATED_CONVERSION_RATE" =>
435
+ CannotDeleteLastDatedConversionRate,
436
+ "CANNOT_DELETE_MANAGED_OBJECT" => CannotDeleteManagedObject,
437
+ "CANNOT_DISABLE_LAST_ADMIN" => CannotDisableLastAdmin,
438
+ "CANNOT_ENABLE_IP_RESTRICT_REQUESTS" => CannotEnableIpRestrictRequests,
439
+ "CANNOT_EXECUTE_FLOW_TRIGGER" => CannotExecuteFlowTrigger,
440
+ "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY" => CannotInsertUpdateActivateEntity,
441
+ "CANNOT_MODIFY_MANAGED_OBJECT" => CannotModifyManagedObject,
442
+ "CANNOT_RENAME_APEX_REFERENCED_FIELD" => CannotRenameApexReferencedField,
443
+ "CANNOT_RENAME_APEX_REFERENCED_OBJECT" => CannotRenameApexReferencedObject,
444
+ "CANNOT_REPARENT_RECORD" => CannotReparentRecord,
445
+ "CANNOT_RESOLVE_NAME" => CannotResolveName,
446
+ "CANNOT_UPDATE_CONVERTED_LEAD" => CannotUpdateConvertedLead,
447
+ "CANT_DISABLE_CORP_CURRENCY" => CantDisableCorpCurrency,
448
+ "CANT_UNSET_CORP_CURRENCY" => CantUnsetCorpCurrency,
449
+ "CHILD_SHARE_FAILS_PARENT" => ChildShareFailsParent,
450
+ "CIRCULAR_DEPENDENCY" => CircularDependency,
451
+ "COMMUNITY_NOT_ACCESSIBLE" => CommunityNotAccessible,
452
+ "CUSTOM_CLOB_FIELD_LIMIT_EXCEEDED" => CustomClobFieldLimitExceeded,
453
+ "CUSTOM_ENTITY_OR_FIELD_LIMIT" => CustomEntityOrFieldLimit,
454
+ "CUSTOM_FIELD_INDEX_LIMIT_EXCEEDED" => CustomFieldIndexLimitExceeded,
455
+ "CUSTOM_INDEX_EXISTS" => CustomIndexExists,
456
+ "CUSTOM_LINK_LIMIT_EXCEEDED" => CustomLinkLimitExceeded,
457
+ "CUSTOM_METADATA_LIMIT_EXCEEDED" => CustomMetadataLimitExceeded,
458
+ "CUSTOM_SETTINGS_LIMIT_EXCEEDED" => CustomSettingsLimitExceeded,
459
+ "CUSTOM_TAB_LIMIT_EXCEEDED" => CustomTabLimitExceeded,
460
+ "DELETE_FAILED" => DeleteFailed,
461
+ "DEPENDENCY_EXISTS" => DependencyExists,
462
+ "DUPLICATE_CASE_SOLUTION" => DuplicateCaseSolution,
463
+ "DUPLICATE_CUSTOM_ENTITY_DEFINITION" => DuplicateCustomEntityDefinition,
464
+ "DUPLICATE_CUSTOM_TAB_MOTIF" => DuplicateCustomTabMotif,
465
+ "DUPLICATE_DEVELOPER_NAME" => DuplicateDeveloperName,
466
+ "DUPLICATES_DETECTED" => DuplicatesDetected,
467
+ "DUPLICATE_EXTERNAL_ID" => DuplicateExternalId,
468
+ "DUPLICATE_MASTER_LABEL" => DuplicateMasterLabel,
469
+ "DUPLICATE_SENDER_DISPLAY_NAME" => DuplicateSenderDisplayName,
470
+ "DUPLICATE_USERNAME" => DuplicateUsername,
471
+ "DUPLICATE_VALUE" => DuplicateValue,
472
+ "EMAIL_ADDRESS_BOUNCED" => EmailAddressBounced,
473
+ "EMAIL_NOT_PROCESSED_DUE_TO_PRIOR_ERROR" => EmailNotProcessedDueToPriorError,
474
+ "EMAIL_OPTED_OUT" => EmailOptedOut,
475
+ "EMAIL_TEMPLATE_FORMULA_ERROR" => EmailTemplateFormulaError,
476
+ "EMAIL_TEMPLATE_MERGEFIELD_ACCESS_ERROR" =>
477
+ EmailTemplateMergefieldAccessError,
478
+ "EMAIL_TEMPLATE_MERGEFIELD_ERROR" => EmailTemplateMergefieldError,
479
+ "EMAIL_TEMPLATE_MERGEFIELD_VALUE_ERROR" => EmailTemplateMergefieldValueError,
480
+ "EMAIL_TEMPLATE_PROCESSING_ERROR" => EmailTemplateProcessingError,
481
+ "EMPTY_SCONTROL_FILE_NAME" => EmptyScontrolFileName,
482
+ "ENTITY_FAILED_IFLASTMODIFIED_ON_UPDATE" =>
483
+ EntityFailedIflastmodifiedOnUpdate,
484
+ "ENTITY_IS_ARCHIVED" => EntityIsArchived,
485
+ "ENTITY_IS_DELETED" => EntityIsDeleted,
486
+ "ENTITY_IS_LOCKED" => EntityIsLocked,
487
+ "ENVIRONMENT_HUB_MEMBERSHIP_CONFLICT" => EnvironmentHubMembershipConflict,
488
+ "ERROR_IN_MAILER" => ErrorInMailer,
489
+ "EXCEEDED_ID_LIMIT" => ExceededIdLimit,
490
+ "EXCEEDED_MAX_SEMIJOIN_SUBSELECTS" => ExceededMaxSemijoinSubselects,
491
+ "FAILED_ACTIVATION" => FailedActivation,
492
+ "FIELD_CUSTOM_VALIDATION_EXCEPTION" => FieldCustomValidationException,
493
+ "FIELD_FILTER_VALIDATION_EXCEPTION" => FieldFilterValidationException,
494
+ "FIELD_INTEGRITY_EXCEPTION" => FieldIntegrityException,
495
+ "FILTERED_LOOKUP_LIMIT_EXCEEDED" => FilteredLookupLimitExceeded,
496
+ "FORBIDDEN" => Forbidden,
497
+ "HTML_FILE_UPLOAD_NOT_ALLOWED" => HtmlFileUploadNotAllowed,
498
+ "ILLEGAL_QUERY_PARAMETER_VALUE" => IllegalQueryParameterValue,
499
+ "IMAGE_TOO_LARGE" => ImageTooLarge,
500
+ "INACTIVE_OWNER_OR_USER" => InactiveOwnerOrUser,
501
+ "INSERT_UPDATE_DELETE_NOT_ALLOWED_DURING_MAINTENANCE" =>
502
+ InsertUpdateDeleteNotAllowedDuringMaintenance,
503
+ "INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY" =>
504
+ InsufficientAccessOnCrossReferenceEntity,
505
+ "INSUFFICIENT_ACCESS_OR_READONLY" => InsufficientAccessOrReadonly,
506
+ "INVALID_ACCESS_LEVEL" => InvalidAccessLevel,
507
+ "INVALID_ARGUMENT_TYPE" => InvalidArgumentType,
508
+ "INVALID_ASSIGNEE_TYPE" => InvalidAssigneeType,
509
+ "INVALID_ASSIGNMENT_RULE" => InvalidAssignmentRule,
510
+ "INVALID_BATCH_OPERATION" => InvalidBatchOperation,
511
+ "INVALID_CONTENT_TYPE" => InvalidContentType,
512
+ "INVALID_CREDIT_CARD_INFO" => InvalidCreditCardInfo,
513
+ "INVALID_CROSS_REFERENCE_KEY" => InvalidCrossReferenceKey,
514
+ "INVALID_CROSS_REFERENCE_TYPE_FOR_FIELD" => InvalidCrossReferenceTypeForField,
515
+ "INVALID_CURRENCY_CONV_RATE" => InvalidCurrencyConvRate,
516
+ "INVALID_CURRENCY_CORP_RATE" => InvalidCurrencyCorpRate,
517
+ "INVALID_CURRENCY_ISO" => InvalidCurrencyIso,
518
+ "INVALID_EMAIL_ADDRESS" => InvalidEmailAddress,
519
+ "INVALID_EMPTY_KEY_OWNER" => InvalidEmptyKeyOwner,
520
+ "INVALID_EVENT_SUBSCRIPTION" => InvalidEventSubscription,
521
+ "INVALID_FIELD" => InvalidField,
522
+ "INVALID_FIELD_FOR_INSERT_UPDATE" => InvalidFieldForInsertUpdate,
523
+ "INVALID_FIELD_WHEN_USING_TEMPLATE" => InvalidFieldWhenUsingTemplate,
524
+ "INVALID_FILTER_ACTION" => InvalidFilterAction,
525
+ "INVALID_ID_FIELD" => InvalidIdField,
526
+ "INVALID_INET_ADDRESS" => InvalidInetAddress,
527
+ "INVALID_LINEITEM_CLONE_STATE" => InvalidLineitemCloneState,
528
+ "INVALID_MASTER_OR_TRANSLATED_SOLUTION" => InvalidMasterOrTranslatedSolution,
529
+ "INVALID_MESSAGE_ID_REFERENCE" => InvalidMessageIdReference,
530
+ "INVALID_OPERATION" => InvalidOperation,
531
+ "INVALID_OPERATION_WITH_EXPIRED_PASSWORD" => InvalidOperationWithExpiredPassword,
532
+ "INVALID_OPERATOR" => InvalidOperator,
533
+ "INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST" =>
534
+ InvalidOrNullForRestrictedPicklist,
535
+ "INVALID_QUERY_FILTER_OPERATOR" => InvalidQueryFilterOperator,
536
+ "INVALID_QUERY_LOCATOR" => InvalidQueryLocator,
537
+ "INVALID_PARTNER_NETWORK_STATUS" => InvalidPartnerNetworkStatus,
538
+ "INVALID_PERSON_ACCOUNT_OPERATION" => InvalidPersonAccountOperation,
539
+ "INVALID_READ_ONLY_USER_DML" => InvalidReadOnlyUserDml,
540
+ "INVALID_REPLICATION_DATE" => InvalidReplicationDate,
541
+ "INVALID_SAVE_AS_ACTIVITY_FLAG" => InvalidSaveAsActivityFlag,
542
+ "INVALID_SESSION_ID" => InvalidSessionId,
543
+ "INVALID_SIGNUP_COUNTRY" => InvalidSignupCountry,
544
+ "INVALID_STATUS" => InvalidStatus,
545
+ "INVALID_TYPE" => InvalidType,
546
+ "INVALID_TYPE_FOR_OPERATION" => InvalidTypeForOperation,
547
+ "INVALID_TYPE_ON_FIELD_IN_RECORD" => InvalidTypeOnFieldInRecord,
548
+ "IP_RANGE_LIMIT_EXCEEDED" => IpRangeLimitExceeded,
549
+ "JIGSAW_IMPORT_LIMIT_EXCEEDED" => JigsawImportLimitExceeded,
550
+ "JSON_PARSER_ERROR" => JsonParserError,
551
+ "LICENSE_LIMIT_EXCEEDED" => LicenseLimitExceeded,
552
+ "LIGHT_PORTAL_USER_EXCEPTION" => LightPortalUserException,
553
+ "LIMIT_EXCEEDED" => LimitExceeded,
554
+ "LOGIN_CHALLENGE_ISSUED" => LoginChallengeIssued,
555
+ "LOGIN_CHALLENGE_PENDING" => LoginChallengePending,
556
+ "LOGIN_MUST_USE_SECURITY_TOKEN" => LoginMustUseSecurityToken,
557
+ "MALFORMED_ID" => MalformedId,
558
+ "MALFORMED_QUERY" => MalformedQuery,
559
+ "MALFORMED_SEARCH" => MalformedSearch,
560
+ "MANAGER_NOT_DEFINED" => ManagerNotDefined,
561
+ "MASSMAIL_RETRY_LIMIT_EXCEEDED" => MassmailRetryLimitExceeded,
562
+ "MASS_MAIL_LIMIT_EXCEEDED" => MassMailLimitExceeded,
563
+ "MAXIMUM_CCEMAILS_EXCEEDED" => MaximumCcemailsExceeded,
564
+ "MAXIMUM_DASHBOARD_COMPONENTS_EXCEEDED" => MaximumDashboardComponentsExceeded,
565
+ "MAXIMUM_HIERARCHY_LEVELS_REACHED" => MaximumHierarchyLevelsReached,
566
+ "MAXIMUM_SIZE_OF_ATTACHMENT" => MaximumSizeOfAttachment,
567
+ "MAXIMUM_SIZE_OF_DOCUMENT" => MaximumSizeOfDocument,
568
+ "MAX_ACTIONS_PER_RULE_EXCEEDED" => MaxActionsPerRuleExceeded,
569
+ "MAX_ACTIVE_RULES_EXCEEDED" => MaxActiveRulesExceeded,
570
+ "MAX_APPROVAL_STEPS_EXCEEDED" => MaxApprovalStepsExceeded,
571
+ "MAX_FORMULAS_PER_RULE_EXCEEDED" => MaxFormulasPerRuleExceeded,
572
+ "MAX_RULES_EXCEEDED" => MaxRulesExceeded,
573
+ "MAX_RULE_ENTRIES_EXCEEDED" => MaxRuleEntriesExceeded,
574
+ "MAX_TASK_DESCRIPTION_EXCEEDED" => MaxTaskDescriptionExceeded,
575
+ "MAX_TM_RULES_EXCEEDED" => MaxTmRulesExceeded,
576
+ "MAX_TM_RULE_ITEMS_EXCEEDED" => MaxTmRuleItemsExceeded,
577
+ "MERGE_FAILED" => MergeFailed,
578
+ "METHOD_NOT_ALLOWED" => MethodNotAllowed,
579
+ "MISSING_ARGUMENT" => MissingArgument,
580
+ "NONUNIQUE_SHIPPING_ADDRESS" => NonuniqueShippingAddress,
581
+ "NO_APPLICABLE_PROCESS" => NoApplicableProcess,
582
+ "NO_ATTACHMENT_PERMISSION" => NoAttachmentPermission,
583
+ "NO_INACTIVE_DIVISION_MEMBERS" => NoInactiveDivisionMembers,
584
+ "NO_MASS_MAIL_PERMISSION" => NoMassMailPermission,
585
+ "NUMBER_OUTSIDE_VALID_RANGE" => NumberOutsideValidRange,
586
+ "NUM_HISTORY_FIELDS_BY_SOBJECT_EXCEEDED" => NumHistoryFieldsBySobjectExceeded,
587
+ "OP_WITH_INVALID_USER_TYPE_EXCEPTION" => OpWithInvalidUserTypeException,
588
+ "OPERATION_TOO_LARGE" => OperationTooLarge,
589
+ "OPTED_OUT_OF_MASS_MAIL" => OptedOutOfMassMail,
590
+ "PACKAGE_LICENSE_REQUIRED" => PackageLicenseRequired,
591
+ "PLATFORM_EVENT_ENCRYPTION_ERROR" => PlatformEventEncryptionError,
592
+ "PLATFORM_EVENT_PUBLISHING_UNAVAILABLE" => PlatformEventPublishingUnavailable,
593
+ "PLATFORM_EVENT_PUBLISH_FAILED" => PlatformEventPublishFailed,
594
+ "PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT" => PortalUserAlreadyExistsForContact,
595
+ "PRIVATE_CONTACT_ON_ASSET" => PrivateContactOnAsset,
596
+ "QUERY_TIMEOUT" => QueryTimeout,
597
+ "RECORD_IN_USE_BY_WORKFLOW" => RecordInUseByWorkflow,
598
+ "REQUEST_LIMIT_EXCEEDED" => RequestLimitExceeded,
599
+ "REQUEST_RUNNING_TOO_LONG" => RequestRunningTooLong,
600
+ "REQUIRED_FIELD_MISSING" => RequiredFieldMissing,
601
+ "SELF_REFERENCE_FROM_TRIGGER" => SelfReferenceFromTrigger,
602
+ "SERVER_UNAVAILABLE" => ServerUnavailable,
603
+ "SHARE_NEEDED_FOR_CHILD_OWNER" => ShareNeededForChildOwner,
604
+ "SINGLE_EMAIL_LIMIT_EXCEEDED" => SingleEmailLimitExceeded,
605
+ "STANDARD_PRICE_NOT_DEFINED" => StandardPriceNotDefined,
606
+ "STORAGE_LIMIT_EXCEEDED" => StorageLimitExceeded,
607
+ "STRING_TOO_LONG" => StringTooLong,
608
+ "TABSET_LIMIT_EXCEEDED" => TabsetLimitExceeded,
609
+ "TEMPLATE_NOT_ACTIVE" => TemplateNotActive,
610
+ "TERRITORY_REALIGN_IN_PROGRESS" => TerritoryRealignInProgress,
611
+ "TEXT_DATA_OUTSIDE_SUPPORTED_CHARSET" => TextDataOutsideSupportedCharset,
612
+ "TOO_MANY_APEX_REQUESTS" => TooManyApexRequests,
613
+ "TOO_MANY_ENUM_VALUE" => TooManyEnumValue,
614
+ "TRANSFER_REQUIRES_READ" => TransferRequiresRead,
615
+ "UNABLE_TO_LOCK_ROW" => UnableToLockRow,
616
+ "UNAVAILABLE_RECORDTYPE_EXCEPTION" => UnavailableRecordtypeException,
617
+ "UNDELETE_FAILED" => UndeleteFailed,
618
+ "UNKNOWN_EXCEPTION" => UnknownException,
619
+ "UNSPECIFIED_EMAIL_ADDRESS" => UnspecifiedEmailAddress,
620
+ "UNSUPPORTED_APEX_TRIGGER_OPERATION" => UnsupportedApexTriggerOperation,
621
+ "UNVERIFIED_SENDER_ADDRESS" => UnverifiedSenderAddress,
622
+ "WEBLINK_SIZE_LIMIT_EXCEEDED" => WeblinkSizeLimitExceeded,
623
+ "WEBLINK_URL_INVALID" => WeblinkUrlInvalid,
624
+ "WRONG_CONTROLLER_TYPE" => WrongControllerType
625
+ }.freeze
626
+
627
+ def self.get_exception_class(error_code)
628
+ ERROR_EXCEPTION_CLASSES.fetch(error_code) do |_|
629
+ warn "[restforce] An unrecognised error code, `#{error_code}` has been " \
630
+ "received from Salesforce. Instead of raising an error-specific exception" \
631
+ ", we'll raise a generic `ResponseError`. Please report this missing " \
632
+ "error code on GitHub at <#{GITHUB_ISSUE_URL}>."
633
+
634
+ # If we've received an unexpected error where we don't have a specific
635
+ # class defined, we can return a generic ResponseError instead
636
+ ResponseError
637
+ end
638
+ end
639
+
640
+ def self.const_missing(constant_name)
641
+ warn "[restforce] You're referring to a Restforce error that isn't defined, " \
642
+ "`#{name}::#{constant_name}` (for example by trying to `rescue` it). This " \
643
+ "might be our fault - we've recently made some changes to how errors are " \
644
+ "defined. If you're sure that this is a valid Salesforce error, then " \
645
+ "please create an issue on GitHub at <#{GITHUB_ISSUE_URL}>."
646
+
647
+ super(constant_name)
648
+ end
649
+ end
650
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ case Faraday::VERSION
4
+ when /\A1\.[0-8]\./
5
+ # Faraday 1.x versions before 1.9 - not matched by
6
+ # the previous clause - use `FilePart` (which must be explicitly
7
+ # required)
8
+ require 'faraday/file_part'
9
+ when /\A[12]\./
10
+ # Later 1.x versions from 1.9 onwards automatically include the
11
+ # `faraday-multipart` gem, which includes `Faraday::FilePart`
12
+ require 'faraday/multipart'
13
+ else
14
+ raise "Unexpected Faraday version #{Faraday::VERSION} - not sure how to set up " \
15
+ "multipart support"
16
+ end
17
+ module Restforce
18
+ if defined?(::Faraday::FilePart)
19
+ FilePart = Faraday::FilePart
20
+
21
+ # Deprecated
22
+ UploadIO = Faraday::FilePart
23
+ else
24
+ # Handle pre-1.0 versions of faraday
25
+ FilePart = Faraday::UploadIO
26
+ UploadIO = Faraday::UploadIO
27
+ end
28
+ end
29
+
30
+ # This patch is only needed with multipart-post < 2.0.0
31
+ # 2.0.0 was released in 2013.
32
+ require 'restforce/patches/parts' unless Parts::Part.method(:new).arity.abs == 4