Ajay98 commited on
Commit
747050e
·
verified ·
1 Parent(s): 7a24375

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -14
app.py CHANGED
@@ -1,26 +1,24 @@
1
- from simple_salesforce import Salesforce
2
 
3
- # Salesforce credentials (consider using environment variables in practice)
4
- username = 'ajayalways411@gmail.com'
5
- password = 'Anusha@310819' + 'DcroeUKt0Lc4Lpqgzh9dMxEyQ' # Append security token to password
6
- domain = 'login' # Use 'test' if using a sandbox
7
 
8
- # Strip extra whitespace (good practice, but likely not necessary here)
9
- username = username.strip()
10
- password = password.strip()
 
11
 
12
- # Connect to Salesforce
13
- sf = Salesforce(username=username, password=password, domain=domain)
 
14
 
15
- # Define your custom object API names (replace with your actual custom object API names)
16
  custom_object_1 = 'staff__c'
17
- custom_object_2 = 'CustomerDat__c'
18
 
19
  # Retrieve records from the first custom object
20
- records_custom_object_1 = sf.query(f"SELECT Name, AdhardCardPhoto__c, pancardPhoto__c, PhoneNumber__c FROM {custom_object_1}")
21
 
22
  # Retrieve records from the second custom object
23
- records_custom_object_2 = sf.query(f"SELECT name, AdhardCard__c, contactNumber__c, pancard__c FROM {custom_object_2}")
24
 
25
  # Print retrieved records
26
  print("Records from Custom Object 1:")
@@ -30,3 +28,16 @@ for record in records_custom_object_1['records']:
30
  print("\nRecords from Custom Object 2:")
31
  for record in records_custom_object_2['records']:
32
  print(record)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ from simple_salesforce import Salesforce, SalesforceMalformedRequest, SalesforceResourceNotFound
 
 
 
3
 
4
+ # Replace these variables with your Salesforce credentials
5
+ USERNAME = 'alwaysajay411@gmail.com'
6
+ PASSWORD = 'Anusha@310819'
7
+ SECURITY_TOKEN = 'DcroeUKt0Lc4Lpqgzh9dMxEyQ'
8
 
9
+ # Create a connection to Salesforce
10
+ try:
11
+ sf = Salesforce(username=USERNAME, password=PASSWORD, security_token=SECURITY_TOKEN)
12
 
13
+ # Define your custom object API names (replace with your actual custom object API names)
14
  custom_object_1 = 'staff__c'
15
+ custom_object_2 = 'CustomerData__c'
16
 
17
  # Retrieve records from the first custom object
18
+ records_custom_object_1 = sf.query(f"SELECT Name, AdhardCard__c, contactNumber__c, pancard__c FROM {custom_object_1}")
19
 
20
  # Retrieve records from the second custom object
21
+ records_custom_object_2 = sf.query(f"SELECT Name, AdhardCardPhoto__c, pancardPhoto__c, PhoneNumber__c FROM {custom_object_2}")
22
 
23
  # Print retrieved records
24
  print("Records from Custom Object 1:")
 
28
  print("\nRecords from Custom Object 2:")
29
  for record in records_custom_object_2['records']:
30
  print(record)
31
+
32
+
33
+ # Print the retrieved records
34
+ for record in results['records']:
35
+ print(f"Name: {record['Name']}, PhoneNumber: {record['PhoneNumber__c']}, Photo: {record['photo__c']}")
36
+
37
+ except SalesforceMalformedRequest as e:
38
+ print(f"Malformed request: {e}")
39
+ except SalesforceResourceNotFound as e:
40
+ print(f"Resource not found: {e}")
41
+ except Exception as e:
42
+ print(f"An error occurred: {e}")
43
+