AjaykumarPilla commited on
Commit
168c5bf
·
verified ·
1 Parent(s): 7ee1e44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -164,8 +164,15 @@ def save_to_salesforce(input_data, prediction, pdf_buffer):
164
  # Get the ContentVersion ID
165
  content_version_id = cv_result["id"]
166
 
167
- # Construct the correct Salesforce URL for the ContentVersion
168
- pdf_url = f"{os.environ.get('SF_INSTANCE_URL')}/sfc/servlet.shepherd/version/download/{content_version_id}"
 
 
 
 
 
 
 
169
 
170
  # Update the Delay_Predictor__c record with the PDF URL
171
  update_result = sf.Delay_Predictor__c.update(record_id, {"PDF_Report__c": pdf_url})
 
164
  # Get the ContentVersion ID
165
  content_version_id = cv_result["id"]
166
 
167
+ # Query the ContentDocumentId from the ContentVersion
168
+ query = f"SELECT ContentDocumentId FROM ContentVersion WHERE Id = '{content_version_id}'"
169
+ query_result = sf.query(query)
170
+ if query_result["totalSize"] == 0:
171
+ return "Failed to retrieve ContentDocumentId for the ContentVersion"
172
+ content_document_id = query_result["records"][0]["ContentDocumentId"]
173
+
174
+ # Construct the correct Salesforce URL for the ContentDocument
175
+ pdf_url = f"{os.environ.get('SF_INSTANCE_URL')}/sfc/servlet.shepherd/document/download/{content_document_id}"
176
 
177
  # Update the Delay_Predictor__c record with the PDF URL
178
  update_result = sf.Delay_Predictor__c.update(record_id, {"PDF_Report__c": pdf_url})