Skip to content

Commit 74987eb

Browse files
authored
Merge pull request yatish27#65 from neanias/patch-1
Use GitHub's syntax highlighting in README
2 parents 299b118 + 9c5e7c5 commit 74987eb

File tree

1 file changed

+71
-59
lines changed

1 file changed

+71
-59
lines changed

README.md

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,84 +28,96 @@ Please check out the entire documentation of the gem you decide to use to learn
2828
You can use username password combo, OmniAuth, Oauth2
2929
You can use as many records possible in the Array. Governor limits are taken care of inside the gem.
3030

31+
```ruby
32+
require 'salesforce_bulk_api'
33+
client = Databasedotcom::Client.new :client_id => SFDC_APP_CONFIG["client_id"], :client_secret => SFDC_APP_CONFIG["client_secret"] #client_id and client_secret respectively
34+
client.authenticate :token => "my-oauth-token", :instance_url => "http://na1.salesforce.com" #=> "my-oauth-token"
3135

32-
require 'salesforce_bulk_api'
33-
client = Databasedotcom::Client.new :client_id => SFDC_APP_CONFIG["client_id"], :client_secret => SFDC_APP_CONFIG["client_secret"] #client_id and client_secret respectively
34-
client.authenticate :token => "my-oauth-token", :instance_url => "http://na1.salesforce.com" #=> "my-oauth-token"
35-
36-
salesforce = SalesforceBulkApi::Api.new(client)
36+
salesforce = SalesforceBulkApi::Api.new(client)
37+
```
3738

3839
OR
3940

40-
require 'salesforce_bulk_api'
41-
client = Restforce.new(
42-
username: SFDC_APP_CONFIG['SFDC_USERNAME'],
43-
password: SFDC_APP_CONFIG['SFDC_PASSWORD'],
44-
security_token: SFDC_APP_CONFIG['SFDC_SECURITY_TOKEN'],
45-
client_id: SFDC_APP_CONFIG['SFDC_CLIENT_ID'],
46-
client_secret: SFDC_APP_CONFIG['SFDC_CLIENT_SECRET'].to_i,
47-
host: SFDC_APP_CONFIG['SFDC_HOST']
48-
)
49-
client.authenticate!
50-
salesforce = SalesforceBulkApi::Api.new(client)
51-
41+
```ruby
42+
require 'salesforce_bulk_api'
43+
client = Restforce.new(
44+
username: SFDC_APP_CONFIG['SFDC_USERNAME'],
45+
password: SFDC_APP_CONFIG['SFDC_PASSWORD'],
46+
security_token: SFDC_APP_CONFIG['SFDC_SECURITY_TOKEN'],
47+
client_id: SFDC_APP_CONFIG['SFDC_CLIENT_ID'],
48+
client_secret: SFDC_APP_CONFIG['SFDC_CLIENT_SECRET'].to_i,
49+
host: SFDC_APP_CONFIG['SFDC_HOST']
50+
)
51+
client.authenticate!
52+
salesforce = SalesforceBulkApi::Api.new(client)
53+
```
5254

5355
### Sample operations:
5456

55-
# Insert/Create
56-
# Add as many fields per record as needed.
57-
new_account = Hash["name" => "Test Account", "type" => "Other"]
58-
records_to_insert = Array.new
59-
# 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
57+
```ruby
58+
# Insert/Create
59+
# Add as many fields per record as needed.
60+
new_account = Hash["name" => "Test Account", "type" => "Other"]
61+
records_to_insert = Array.new
62+
# 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+
```
8488

8589
### Helpful methods:
8690

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+
```
9096

9197
### Listening to events:
9298

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+
```
99107

100108
### Throttling API calls:
101109

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
114+
```
105115

106116
## Installation
107117

108-
sudo gem install salesforce_bulk_api
118+
```bash
119+
sudo gem install salesforce_bulk_api
120+
```
109121

110122
## Contribute
111123

0 commit comments

Comments
 (0)