You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# You can add as many records as you want here, just keep in mind that Salesforce has governor limits.
60
-
records_to_insert.push(new_account)
61
-
result = salesforce.create("Account", records_to_insert)
62
-
puts "result is: #{result.inspect}"
63
-
64
-
# Update
65
-
updated_account = Hash["name" => "Test Account -- Updated", id => "a00A0001009zA2m"] # Nearly identical to an insert, but we need to pass the salesforce id.
66
-
records_to_update = Array.new
67
-
records_to_update.push(updated_account)
68
-
salesforce.update("Account", records_to_update)
69
-
70
-
# Upsert
71
-
upserted_account = Hash["name" => "Test Account -- Upserted", "External_Field_Name" => "123456"] # Fields to be updated. External field must be included
72
-
records_to_upsert = Array.new
73
-
records_to_upsert.push(upserted_account)
74
-
salesforce.upsert("Account", records_to_upsert, "External_Field_Name") # Note that upsert accepts an extra parameter for the external field name
75
-
76
-
# Delete
77
-
deleted_account = Hash["id" => "a00A0001009zA2m"] # We only specify the id of the records to delete
78
-
records_to_delete = Array.new
79
-
records_to_delete.push(deleted_account)
80
-
salesforce.delete("Account", records_to_delete)
81
-
82
-
# Query
83
-
res = salesforce.query("Account", "select id, name, createddate from Account limit 3") # We just need to pass the sobject name and the query string
# You can add as many records as you want here, just keep in mind that Salesforce has governor limits.
63
+
records_to_insert.push(new_account)
64
+
result = salesforce.create("Account", records_to_insert)
65
+
puts"result is: #{result.inspect}"
66
+
67
+
# Update
68
+
updated_account =Hash["name" => "Test Account -- Updated", id => "a00A0001009zA2m"] # Nearly identical to an insert, but we need to pass the salesforce id.
69
+
records_to_update =Array.new
70
+
records_to_update.push(updated_account)
71
+
salesforce.update("Account", records_to_update)
72
+
73
+
# Upsert
74
+
upserted_account =Hash["name" => "Test Account -- Upserted", "External_Field_Name" => "123456"] # Fields to be updated. External field must be included
75
+
records_to_upsert =Array.new
76
+
records_to_upsert.push(upserted_account)
77
+
salesforce.upsert("Account", records_to_upsert, "External_Field_Name") # Note that upsert accepts an extra parameter for the external field name
78
+
79
+
# Delete
80
+
deleted_account =Hash["id" => "a00A0001009zA2m"] # We only specify the id of the records to delete
81
+
records_to_delete =Array.new
82
+
records_to_delete.push(deleted_account)
83
+
salesforce.delete("Account", records_to_delete)
84
+
85
+
# Query
86
+
res = salesforce.query("Account", "select id, name, createddate from Account limit 3") # We just need to pass the sobject name and the query string
87
+
```
84
88
85
89
### Helpful methods:
86
90
87
-
# Check status of a job via #job_from_id
88
-
job = salesforce.job_from_id('a00A0001009zA2m') # Returns a SalesforceBulkApi::Job instance
89
-
puts "status is: #{job.check_job_status.inspect}"
91
+
```ruby
92
+
# Check status of a job via #job_from_id
93
+
job = salesforce.job_from_id('a00A0001009zA2m') # Returns a SalesforceBulkApi::Job instance
94
+
puts"status is: #{job.check_job_status.inspect}"
95
+
```
90
96
91
97
### Listening to events:
92
98
93
-
# A job is created
94
-
# Useful when you need to store the job_id before any work begins, then if you fail during a complex load scenario, you can wait for your
95
-
# previous job(s) to finish.
96
-
salesforce.on_job_created do |job|
97
-
puts "Job #{job.job_id} created!"
98
-
end
99
+
```ruby
100
+
# A job is created
101
+
# Useful when you need to store the job_id before any work begins, then if you fail during a complex load scenario, you can wait for your
102
+
# previous job(s) to finish.
103
+
salesforce.on_job_created do |job|
104
+
puts"Job #{job.job_id} created!"
105
+
end
106
+
```
99
107
100
108
### Throttling API calls:
101
109
102
-
# By default, this gem (and maybe your app driving it) will query job/batch statuses at an unbounded rate. We
103
-
# can fix that, e.g.:
104
-
salesforce.connection.set_status_throttle(30) # only check status of individual jobs/batches every 30 seconds
110
+
```ruby
111
+
# By default, this gem (and maybe your app driving it) will query job/batch statuses at an unbounded rate. We
112
+
# can fix that, e.g.:
113
+
salesforce.connection.set_status_throttle(30) # only check status of individual jobs/batches every 30 seconds
0 commit comments