Dineshpopuri commited on
Commit
0d855c4
·
verified ·
1 Parent(s): 40ed91d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -76,9 +76,12 @@ def init_salesforce():
76
  instance_url=SF_INSTANCE_URL
77
  )
78
  logging.info("Salesforce connected successfully")
79
- # Test a simple query to verify permissions
80
  test_query = sf.query("SELECT Id FROM Project_Closure_Handover__c LIMIT 1")
81
- logging.info(f"Test query result: {test_query}")
 
 
 
82
  return sf, "Salesforce connected successfully"
83
  except SalesforceError as e:
84
  logging.error(f"Salesforce authentication failed: {str(e)}")
@@ -137,7 +140,7 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status,
137
  punch_list_text = str(punch_list_text) if punch_list_text else ""
138
  missing_documents = len(missing_summary.split(", ")) if missing_summary and missing_summary != "None" else 0
139
  open_punch_items = int(open_punch_items) if open_punch_items is not None else 0
140
- evaluated_at = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") # Salesforce Date/Time format
141
  alert_sent = escalated # Set Alert_Sent__c based on escalation flag
142
 
143
  # Create a record in the custom object Project_Closure_Handover__c
@@ -162,10 +165,14 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status,
162
  result = sf.Project_Closure_Handover__c.create(record)
163
  logging.info(f"Successfully created Salesforce record: {result}")
164
  logging.info(f"Record ID: {result.get('id')}")
165
- return "Record created successfully"
166
  except SalesforceError as e:
167
  logging.error(f"Salesforce error while creating Project_Closure_Handover__c record: {str(e)}")
168
- logging.error("Possible issues: Object permissions, field-level security, or validation rules.")
 
 
 
 
169
  return f"Salesforce error: {str(e)}"
170
  except Exception as e:
171
  logging.error(f"Failed to create Salesforce Project_Closure_Handover__c record: {str(e)}")
@@ -365,6 +372,7 @@ with gr.Blocks(css="""
365
  missing_output = gr.Textbox(label="Missing Items")
366
  pdf_output = gr.File(label="Download PDF Report", type="filepath", interactive=False) # Output only, no auto-download
367
  pdf_debug = gr.Textbox(label="PDF Debug Output") # Temporary debug output
 
368
 
369
  # Chain the evaluation, PDF generation, and Salesforce record creation
370
  submit_btn.click(
@@ -379,7 +387,7 @@ with gr.Blocks(css="""
379
  ).then(
380
  fn=create_salesforce_record,
381
  inputs=[score_output, checklist_output, missing_output, status_output, gr.State(), gr.State(), gr.State(), gr.State(), gr.State(), pdf_output],
382
- outputs=None # No UI output for Salesforce status
383
  )
384
  demo.launch()
385
 
 
76
  instance_url=SF_INSTANCE_URL
77
  )
78
  logging.info("Salesforce connected successfully")
79
+ # Test read access on Project_Closure_Handover__c
80
  test_query = sf.query("SELECT Id FROM Project_Closure_Handover__c LIMIT 1")
81
+ logging.info(f"Test query result (read access): {test_query}")
82
+ # Test create access by attempting to describe the object and check permissions
83
+ object_description = sf.Project_Closure_Handover__c.describe()
84
+ logging.info(f"Object description: {object_description}")
85
  return sf, "Salesforce connected successfully"
86
  except SalesforceError as e:
87
  logging.error(f"Salesforce authentication failed: {str(e)}")
 
140
  punch_list_text = str(punch_list_text) if punch_list_text else ""
141
  missing_documents = len(missing_summary.split(", ")) if missing_summary and missing_summary != "None" else 0
142
  open_punch_items = int(open_punch_items) if open_punch_items is not None else 0
143
+ evaluated_at = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") # Salesforce Date/Time format (e.g., 2025-05-19T05:08:00Z for 10:38 AM IST)
144
  alert_sent = escalated # Set Alert_Sent__c based on escalation flag
145
 
146
  # Create a record in the custom object Project_Closure_Handover__c
 
165
  result = sf.Project_Closure_Handover__c.create(record)
166
  logging.info(f"Successfully created Salesforce record: {result}")
167
  logging.info(f"Record ID: {result.get('id')}")
168
+ return f"Record created successfully. Record ID: {result.get('id')}"
169
  except SalesforceError as e:
170
  logging.error(f"Salesforce error while creating Project_Closure_Handover__c record: {str(e)}")
171
+ logging.error("Possible issues: Object permissions, field-level security, validation rules, or required fields.")
172
+ logging.error("Check the following in your Salesforce org:")
173
+ logging.error("- Ensure the user has Create permission on Project_Closure_Handover__c.")
174
+ logging.error("- Verify field-level security for all fields in the record.")
175
+ logging.error("- Check for validation rules or required fields that might be failing.")
176
  return f"Salesforce error: {str(e)}"
177
  except Exception as e:
178
  logging.error(f"Failed to create Salesforce Project_Closure_Handover__c record: {str(e)}")
 
372
  missing_output = gr.Textbox(label="Missing Items")
373
  pdf_output = gr.File(label="Download PDF Report", type="filepath", interactive=False) # Output only, no auto-download
374
  pdf_debug = gr.Textbox(label="PDF Debug Output") # Temporary debug output
375
+ salesforce_status = gr.Textbox(label="Salesforce Record Creation Status (Temporary for Debugging)") # Temporary for debugging
376
 
377
  # Chain the evaluation, PDF generation, and Salesforce record creation
378
  submit_btn.click(
 
387
  ).then(
388
  fn=create_salesforce_record,
389
  inputs=[score_output, checklist_output, missing_output, status_output, gr.State(), gr.State(), gr.State(), gr.State(), gr.State(), pdf_output],
390
+ outputs=salesforce_status # Temporary output for debugging
391
  )
392
  demo.launch()
393