Skip to content

Commit

Permalink
Add support for actionIfNoExistingObject=create
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Sep 19, 2023
1 parent 7463130 commit e48d2cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/jazkarta/easyformplugin/salesforce/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ def onSuccess(self, fields, request):
raise Exception(u"Failed to create {} in Salesforce: {}".format(sobject_name, result["errors"]))
elif op_name == "update":
sf_id = request.cookies.get("sf_id")
if not sf_id:
raise Exception(u"No Salesforce object matched for update")
result = sobject.update(sf_id, data)
if sf_id:
result = sobject.update(sf_id, data)
else:
if operation.get("action_if_no_existing_object") == "create":
result = sobject.create(data)
sf_id = result["Id"]
else:
raise Exception(u"No Salesforce object matched for update")
if result == 204:
request.response.expireCookie("sf_id", path=form.absolute_url_path())
logger.info(u"Updated {} {} in Salesforce".format(sobject_name, sf_id))
Expand Down
1 change: 1 addition & 0 deletions src/jazkarta/easyformplugin/salesforce/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ISaveToSalesforce(IAction):
"sobject": {"type": "string"},
"operation": {"type": "string", "enum": ["create", "update"]},
"match_expression": {"type": "string"},
"action_if_no_existing_object": {"type": "string", "enum": ["abort", "create"]},
"fields": {
"type": "object",
"additionalProperties": {
Expand Down
3 changes: 2 additions & 1 deletion src/jazkarta/easyformplugin/salesforce/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ def append_sf_action(schema, type_, name, properties):
}
if creation_mode == "update":
op["match_expression"] = properties["updateMatchExpression"]
if properties["actionIfNoExistingObject"] != "abort":
if properties["actionIfNoExistingObject"] not in ("abort", "create"):
raise NotImplementedError(
"Unsupported actionIfNoExistingObject: {}".format(
properties['actionIfNoExistingObject'])
)
op["action_if_no_existing_object"] = properties["actionIfNoExistingObject"]
if properties["dependencyMap"]:
raise NotImplementedError(
"Unsupported: dependencyMap (jazkarta.easyformplugins.salesforce "
Expand Down

0 comments on commit e48d2cd

Please sign in to comment.