prudhviLatha commited on
Commit
e7cfd45
·
verified ·
1 Parent(s): 135ee0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -74,10 +74,21 @@ def get_required_fields(sf):
74
 
75
  def create_contract_document(sf, name, status='Draft', document_url='https://example.com/contract.pdf'):
76
  """
77
- Create a Contract_Document__c record with the given name, status, and document URL.
78
- Includes required fields Document_URL__c and Upload_Date__c.
79
  """
80
- logger.info("Creating Contract_Document__c record")
 
 
 
 
 
 
 
 
 
 
 
81
  valid_statuses = get_valid_status_values(sf)
82
 
83
  if status not in valid_statuses:
@@ -151,7 +162,7 @@ def main():
151
  sys.exit(1)
152
 
153
  logger.info("Application completed successfully")
154
- sys.exit(0) # Explicitly exit with success code
155
 
156
  except SalesforceError as e:
157
  logger.error(f"Error initializing Salesforce connection: {e}")
@@ -162,4 +173,5 @@ def main():
162
 
163
  if __name__ == "__main__":
164
  logger.info("Application entry point")
165
- main()
 
 
74
 
75
  def create_contract_document(sf, name, status='Draft', document_url='https://example.com/contract.pdf'):
76
  """
77
+ Create a Contract_Document__c record if it doesn't exist.
78
+ Checks for existing records by Name to prevent duplicates.
79
  """
80
+ logger.info("Checking for existing Contract_Document__c record")
81
+ try:
82
+ query = f"SELECT Id, Name, Status__c, Document_URL__c, Upload_Date__c FROM Contract_Document__c WHERE Name = '{name}' LIMIT 1"
83
+ result = sf.query(query)
84
+ if result['totalSize'] > 0:
85
+ logger.info(f"Record with Name '{name}' already exists: {result['records'][0]['Id']}")
86
+ return result['records'][0]
87
+ except SalesforceError as e:
88
+ logger.error(f"Error checking for existing record: {e}")
89
+ return None
90
+
91
+ logger.info("Creating new Contract_Document__c record")
92
  valid_statuses = get_valid_status_values(sf)
93
 
94
  if status not in valid_statuses:
 
162
  sys.exit(1)
163
 
164
  logger.info("Application completed successfully")
165
+ sys.exit(0)
166
 
167
  except SalesforceError as e:
168
  logger.error(f"Error initializing Salesforce connection: {e}")
 
173
 
174
  if __name__ == "__main__":
175
  logger.info("Application entry point")
176
+ main()
177
+