sf_cli 0.0.8 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +2 -2
- data/lib/sf_cli/console/commands.rb +17 -1
- data/lib/sf_cli/sf/apex/run.rb +22 -35
- data/lib/sf_cli/sf/core/base.rb +7 -0
- data/lib/sf_cli/sf/data/create_record.rb +3 -1
- data/lib/sf_cli/sf/data/delete_bulk.rb +25 -8
- data/lib/sf_cli/sf/data/delete_record.rb +3 -1
- data/lib/sf_cli/sf/data/delete_resume.rb +10 -8
- data/lib/sf_cli/sf/data/query.rb +11 -7
- data/lib/sf_cli/sf/data/resume.rb +5 -3
- data/lib/sf_cli/sf/data/search.rb +6 -4
- data/lib/sf_cli/sf/data/update_record.rb +8 -6
- data/lib/sf_cli/sf/data/upsert_bulk.rb +27 -10
- data/lib/sf_cli/sf/data/upsert_resume.rb +8 -6
- data/lib/sf_cli/sf/model/query_condition.rb +114 -61
- data/lib/sf_cli/sf/model/query_methods.rb +29 -4
- data/lib/sf_cli/sf/model/sf_command_connection.rb +4 -4
- data/lib/sf_cli/sf/org/display.rb +3 -2
- data/lib/sf_cli/sf/sobject/describe.rb +7 -5
- data/lib/sf_cli/sf/sobject/list.rb +5 -3
- data/lib/sf_cli/sf/sobject/schema.rb +452 -16
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3e5833449ce9819bd4c28f92d21d2719cfac0bd9b6a0917f61de212b3b1a485
|
4
|
+
data.tar.gz: 34c71983f1f8feae1dec31b965e9ef1102ea1b4340eb0ebaffa376df8c1cc699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62d251ef5a3411ec98a835de03f686e45551eb783d6504772ba56abc8eff986b95d0d70f37257479934a670e279656b047326faf623845879cc7f4e797bdae80
|
7
|
+
data.tar.gz: 25b30fd9cc789d55be2d8f15903b72e16d7bcf03447402782be48f738a8d00bf71270972c47a776df0ce2c59d801bea880ffc1c46e557d8837cc67e32b216406
|
data/README.rdoc
CHANGED
@@ -50,12 +50,12 @@ Delete a record
|
|
50
50
|
sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
51
51
|
|
52
52
|
Using Bulk API 2.0
|
53
|
-
sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv',
|
53
|
+
sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv', wait: 5 # waiting for 5 minutes at maximum
|
54
54
|
|
55
55
|
Run Apex
|
56
56
|
sf.apex.run file: 'path/to/file'
|
57
57
|
sf.apex.run file: StringIO.new("System.debug('Hello World')")
|
58
|
-
== Object Model Support
|
58
|
+
== Object Model Support
|
59
59
|
With sf command:
|
60
60
|
rows = sf.data.query "SELECT Id, Name FROM Contact WHERE Name = 'Akin Kristen'", model_class: Contact
|
61
61
|
rows.first # <Contact: @Id="0035j00001RW3xbAAD", @Name="Akin Kristen">
|
@@ -4,7 +4,21 @@ require 'sf_cli/sf/model/sf_command_connection'
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
module SfCli
|
7
|
+
# @private :nodoc: just for developers
|
7
8
|
module Console
|
9
|
+
#
|
10
|
+
# Developer Console commands
|
11
|
+
# @example
|
12
|
+
# $ bundle exec rake irb[your_target_org]
|
13
|
+
# irb(main):001> gen :Account, :Contact # generate Account and Contact class
|
14
|
+
# => [:Account, :Contact]
|
15
|
+
#
|
16
|
+
# irb(main):002> Account.describe.label
|
17
|
+
# => "Account"
|
18
|
+
#
|
19
|
+
# irb(main):003> apex "System.debug('abc');" # execute Apex code
|
20
|
+
# => returns the result
|
21
|
+
#
|
8
22
|
module Commands
|
9
23
|
def use(_target_org)
|
10
24
|
target_org = _target_org.to_sym == :default ? nil : _target_org
|
@@ -25,7 +39,9 @@ module SfCli
|
|
25
39
|
connection.target_org
|
26
40
|
end
|
27
41
|
|
28
|
-
def apex(apex_code)
|
42
|
+
def apex(apex_code = nil)
|
43
|
+
return sf.apex.run target_org: target_org if apex_code.nil?
|
44
|
+
|
29
45
|
sf.apex.run target_org: target_org, file: StringIO.new(apex_code)
|
30
46
|
end
|
31
47
|
|
data/lib/sf_cli/sf/apex/run.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'tempfile'
|
2
|
-
require 'stringio'
|
3
2
|
|
4
3
|
module SfCli::Sf::Apex
|
5
4
|
module Run
|
@@ -10,10 +9,11 @@ module SfCli::Sf::Apex
|
|
10
9
|
#
|
11
10
|
# @param target_org [Symbol,String]
|
12
11
|
# an alias of paticular org, or username can be used.
|
13
|
-
#
|
14
|
-
# @param file [String,StringIO]
|
12
|
+
# @param file [String,#read]
|
15
13
|
# (1) path to a local file that contains Apex code.
|
16
|
-
# (2)
|
14
|
+
# (2) object that has #read method
|
15
|
+
# @param api_version [Numeric]
|
16
|
+
# override the api version used for api requests made by this command
|
17
17
|
#
|
18
18
|
# @return [ApexResult] Apex execution result.
|
19
19
|
#
|
@@ -53,46 +53,33 @@ module SfCli::Sf::Apex
|
|
53
53
|
# "Execute Anonymous: System.debug(acc.Name);",
|
54
54
|
# ....]
|
55
55
|
#
|
56
|
-
def run(target_org: nil, file: nil)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
return unless file.is_a? String
|
61
|
-
|
62
|
-
flags = {:"target-org" => target_org, :"file" => file}
|
56
|
+
def run(target_org: nil, file: nil, api_version: nil)
|
57
|
+
_file = crate_tmpfile(file)
|
58
|
+
path = _file&.path || file
|
59
|
+
flags = {:"target-org" => target_org, :"file" => path, :"api-version" => api_version}
|
63
60
|
|
64
61
|
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
65
62
|
ApexResult.new(json['result'])
|
63
|
+
ensure
|
64
|
+
_file&.close!
|
66
65
|
end
|
67
66
|
|
68
67
|
private
|
69
68
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
flags = {:"target-org" => target_org, :"file" => file.path}
|
74
|
-
json = exec(:run, flags: flags, redirection: :null_stderr)
|
75
|
-
ApexResult.new(json['result'])
|
76
|
-
ensure
|
77
|
-
file&.close!
|
69
|
+
def crate_tmpfile(path_or_io)
|
70
|
+
return create_tmpfile_by_user_input if path_or_io.nil?
|
71
|
+
create_tmpfile_by_io(path_or_io)
|
78
72
|
end
|
79
73
|
|
80
|
-
def
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
flags = {:"target-org" => target_org, :"file" => file.path}
|
91
|
-
|
92
|
-
json = exec(:run, flags: flags, redirection: :null_stderr)
|
93
|
-
ApexResult.new(json['result'])
|
94
|
-
ensure
|
95
|
-
file&.close!
|
74
|
+
def create_tmpfile_by_user_input
|
75
|
+
Tempfile.open(%w[sf apex]) do |f|
|
76
|
+
s = $stdin.gets
|
77
|
+
while s
|
78
|
+
f.puts(s)
|
79
|
+
s = $stdin.gets
|
80
|
+
end
|
81
|
+
f
|
82
|
+
end
|
96
83
|
end
|
97
84
|
|
98
85
|
class ApexResult
|
data/lib/sf_cli/sf/core/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
module SfCli
|
4
5
|
module Sf
|
@@ -77,6 +78,12 @@ module SfCli
|
|
77
78
|
' 2> /dev/null'
|
78
79
|
end
|
79
80
|
end
|
81
|
+
|
82
|
+
def create_tmpfile_by_io(io)
|
83
|
+
return nil unless io.respond_to? :read
|
84
|
+
|
85
|
+
Tempfile.open(%w[sf]){|f| f.write(io.read); f}
|
86
|
+
end
|
80
87
|
end
|
81
88
|
end
|
82
89
|
end
|
@@ -5,6 +5,7 @@ module SfCli::Sf::Data
|
|
5
5
|
# @param object_type [Symbol, String] object type(ex. Account)
|
6
6
|
# @param values [Hash] field values to be assigned
|
7
7
|
# @param target_org [Symbol, String] an alias of paticular org, or username can be used
|
8
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
8
9
|
#
|
9
10
|
# @return [String] record ID
|
10
11
|
#
|
@@ -12,12 +13,13 @@ module SfCli::Sf::Data
|
|
12
13
|
# # create a TheCustomObject record with name and age
|
13
14
|
# sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33}
|
14
15
|
#
|
15
|
-
def create_record(object_type, values: {}, target_org: nil)
|
16
|
+
def create_record(object_type, values: {}, target_org: nil, api_version: nil)
|
16
17
|
field_values = field_value_pairs(values)
|
17
18
|
flags = {
|
18
19
|
:"sobject" => object_type,
|
19
20
|
:"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
|
20
21
|
:"target-org" => target_org,
|
22
|
+
:"api-version" => api_version,
|
21
23
|
}
|
22
24
|
action = __method__.to_s.tr('_', ' ')
|
23
25
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -3,10 +3,13 @@ require_relative './bulk_result_v2'
|
|
3
3
|
module SfCli::Sf::Data
|
4
4
|
module DeleteBulk
|
5
5
|
# Delete records using Bulk API 2.0
|
6
|
-
# @param file
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# @param
|
6
|
+
# @param file [String,#read]
|
7
|
+
# (1)path of a CSV file, which is written record IDs to delete.
|
8
|
+
# (2) IO-like object, which has #read method
|
9
|
+
# @param sobject [Symbol, String] object type (ex. Account)
|
10
|
+
# @param wait [Integer] max minutes to wait for the job complete the task.
|
11
|
+
# @param target_org [Symbol, String] an alias of paticular org, or username can be used
|
12
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
10
13
|
#
|
11
14
|
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
12
15
|
#
|
@@ -19,17 +22,29 @@ module SfCli::Sf::Data
|
|
19
22
|
# sf.data.delete_resume job_id: jobinfo.id
|
20
23
|
#
|
21
24
|
# # Or, you can wait for the job completion with one try.
|
22
|
-
# result = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv',
|
25
|
+
# result = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv', wait: 5 # wait within 5 minutes
|
26
|
+
#
|
27
|
+
# # you can use IO-like object, which has #read, to `file` keyword:
|
28
|
+
# require 'stringio'
|
29
|
+
# csv = StringIO.new <<CSV
|
30
|
+
# Id
|
31
|
+
# 001J400000Ki61uIAB
|
32
|
+
# 001J400000Ki3WRIAZ
|
33
|
+
# CSV
|
34
|
+
# jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: csv
|
23
35
|
#
|
24
36
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_delete_bulk_unified command reference
|
25
37
|
#
|
26
38
|
#
|
27
|
-
def delete_bulk(file:, sobject:,
|
39
|
+
def delete_bulk(file:, sobject:, wait: nil, target_org: nil, api_version: nil)
|
40
|
+
_file = create_tmpfile_by_io(file)
|
41
|
+
path = _file&.path || file
|
28
42
|
flags = {
|
29
|
-
:"file" =>
|
43
|
+
:"file" => path,
|
30
44
|
:"sobject" => sobject,
|
31
|
-
:"wait" =>
|
45
|
+
:"wait" => wait,
|
32
46
|
:"target-org" => target_org,
|
47
|
+
:"api-version" => api_version,
|
33
48
|
}
|
34
49
|
action = __method__.to_s.tr('_', ' ')
|
35
50
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -41,6 +56,8 @@ module SfCli::Sf::Data
|
|
41
56
|
job_info: job_info,
|
42
57
|
records: ::SfCli::Sf::Data::BulkRecordsV2.new(**json['result']['records'])
|
43
58
|
)
|
59
|
+
ensure
|
60
|
+
_file&.close!
|
44
61
|
end
|
45
62
|
end
|
46
63
|
end
|
@@ -6,6 +6,7 @@ module SfCli::Sf::Data
|
|
6
6
|
# @param record_id [String] Id of the object
|
7
7
|
# @param where [Hash] conditions to identify a record
|
8
8
|
# @param target_org [Symbol, String] an alias of paticular org, or username can be used
|
9
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
9
10
|
#
|
10
11
|
# @return [String] ID that is deleted.
|
11
12
|
#
|
@@ -15,13 +16,14 @@ module SfCli::Sf::Data
|
|
15
16
|
#
|
16
17
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_delete_record_unified the command reference
|
17
18
|
#
|
18
|
-
def delete_record(object_type, record_id: nil, where: nil, target_org: nil)
|
19
|
+
def delete_record(object_type, record_id: nil, where: nil, target_org: nil, api_version: nil)
|
19
20
|
where_conditions = field_value_pairs(where)
|
20
21
|
flags = {
|
21
22
|
:"sobject" => object_type,
|
22
23
|
:"record-id" => record_id,
|
23
24
|
:"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
|
24
25
|
:"target-org" => target_org,
|
26
|
+
:"api-version" => api_version,
|
25
27
|
}
|
26
28
|
action = __method__.to_s.tr('_', ' ')
|
27
29
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -4,9 +4,10 @@ module SfCli::Sf::Data
|
|
4
4
|
module DeleteResume
|
5
5
|
# Resume a bulk delete job you previously started with Bulk API 2.0 and return a bulk result object.
|
6
6
|
#
|
7
|
-
# @param job_id
|
8
|
-
# @param
|
9
|
-
# @param target_org
|
7
|
+
# @param job_id [String] job ID you want to resume<br>
|
8
|
+
# @param wait [Integer] max minutes to wait for the job complete the task.<br>
|
9
|
+
# @param target_org [Symbol, String] an alias of paticular org, or username can be used<br>
|
10
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
10
11
|
#
|
11
12
|
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
12
13
|
#
|
@@ -17,18 +18,19 @@ module SfCli::Sf::Data
|
|
17
18
|
#
|
18
19
|
# # the job has already started asynchronously.
|
19
20
|
# # So you should check its progress.
|
20
|
-
# # if you want to wait for the job complete the task, try '
|
21
|
+
# # if you want to wait for the job complete the task, try 'wait' option.
|
21
22
|
# result = sf.data.delete_resume job_id: jobinfo.id
|
22
23
|
#
|
23
24
|
# puts 'yey!' if result.job_info.completed? # the job has completed
|
24
25
|
#
|
25
26
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_delete_resume_unified the command reference
|
26
27
|
#
|
27
|
-
def delete_resume(job_id:,
|
28
|
+
def delete_resume(job_id:, wait: nil, target_org: nil, api_version: nil)
|
28
29
|
flags = {
|
29
|
-
:"job-id"
|
30
|
-
:"wait"
|
31
|
-
:"target-org"
|
30
|
+
:"job-id" => job_id,
|
31
|
+
:"wait" => wait,
|
32
|
+
:"target-org" => target_org,
|
33
|
+
:"api-version" => api_version,
|
32
34
|
}
|
33
35
|
action = __method__.to_s.tr('_', ' ')
|
34
36
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
data/lib/sf_cli/sf/data/query.rb
CHANGED
@@ -9,7 +9,8 @@ module SfCli::Sf::Data
|
|
9
9
|
# @param format [Symbol,String] get the command's raw output. human, csv, json can be available
|
10
10
|
# @param model_class [Class] the object model class
|
11
11
|
# @param bulk [Boolean] use Bulk API
|
12
|
-
# @param
|
12
|
+
# @param wait [Integer] max minutes to wait for the job complete in Bulk API mode
|
13
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
13
14
|
#
|
14
15
|
# @return [Array,[String,Array]] records or a tuple containing a flag and records
|
15
16
|
#
|
@@ -30,20 +31,21 @@ module SfCli::Sf::Data
|
|
30
31
|
#
|
31
32
|
# @example
|
32
33
|
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true # max wait 1 min to get result (default)
|
33
|
-
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true,
|
34
|
-
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true,
|
34
|
+
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, wait: 5 # max wait 5 min to get result
|
35
|
+
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, wait: 0 # returns immediately
|
35
36
|
#
|
36
37
|
# rows = result if done # if job is completed, the result is an array of record
|
37
38
|
# job_id = result unless done # if job hasn't completed or it has aborted, the result is the job ID
|
38
39
|
#
|
39
40
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_query_unified command reference
|
40
41
|
#
|
41
|
-
def query(soql, target_org: nil, format: nil, bulk: false,
|
42
|
+
def query(soql, target_org: nil, format: nil, bulk: false, wait: nil, api_version: nil, model_class: nil)
|
42
43
|
flags = {
|
43
44
|
:"query" => %("#{soql}"),
|
44
45
|
:"target-org" => target_org,
|
45
46
|
:"result-format" => format,
|
46
|
-
:"wait" => (bulk ?
|
47
|
+
:"wait" => (bulk ? wait : nil),
|
48
|
+
:"api-version" => api_version,
|
47
49
|
}
|
48
50
|
switches = {
|
49
51
|
bulk: bulk,
|
@@ -61,12 +63,13 @@ module SfCli::Sf::Data
|
|
61
63
|
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
62
64
|
# @param format [Symbol,String] get the command's raw output. human, csv, json can be available
|
63
65
|
# @param model_class [Class] the object model class
|
66
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
64
67
|
#
|
65
68
|
# @return [Array,[String,Array]] records or a tuple containing a flag and records
|
66
69
|
#
|
67
70
|
# @example
|
68
71
|
# # start a query job
|
69
|
-
# result1 = sf.data.query 'SELECT Id, Name FROM Account', bulk: true,
|
72
|
+
# result1 = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, wait: 0 # returns immediately
|
70
73
|
#
|
71
74
|
# result1 # => [false, "<job id>"]
|
72
75
|
#
|
@@ -80,11 +83,12 @@ module SfCli::Sf::Data
|
|
80
83
|
#
|
81
84
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_query_resume_unified command reference
|
82
85
|
#
|
83
|
-
def query_resume(job_id:, target_org: nil, format: nil, model_class: nil)
|
86
|
+
def query_resume(job_id:, target_org: nil, format: nil, api_version: nil, model_class: nil)
|
84
87
|
flags = {
|
85
88
|
:"bulk-query-id" => job_id,
|
86
89
|
:"target-org" => target_org,
|
87
90
|
:"result-format" => format,
|
91
|
+
:"api-version" => api_version,
|
88
92
|
}
|
89
93
|
raw_output = format ? true : false
|
90
94
|
format = format || :json
|
@@ -49,8 +49,9 @@ module SfCli::Sf::Data
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# View the status of a bulk job.
|
52
|
-
# @param job_id
|
53
|
-
# @param target_org
|
52
|
+
# @param job_id [String] job ID you want to resume
|
53
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
54
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
54
55
|
#
|
55
56
|
# @return [JobInfo] job information
|
56
57
|
#
|
@@ -73,10 +74,11 @@ module SfCli::Sf::Data
|
|
73
74
|
#
|
74
75
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_resume_unified command reference
|
75
76
|
#
|
76
|
-
def resume(job_id:, target_org: nil)
|
77
|
+
def resume(job_id:, target_org: nil, api_version: nil)
|
77
78
|
flags = {
|
78
79
|
:"job-id" => job_id,
|
79
80
|
:"target-org" => target_org,
|
81
|
+
:"api-version" => api_version,
|
80
82
|
}
|
81
83
|
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
82
84
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module SfCli::Sf::Data
|
2
2
|
module Search
|
3
3
|
# Search objects using SOSL.
|
4
|
-
# @param sosl
|
5
|
-
# @param target_org
|
6
|
-
# @param format
|
4
|
+
# @param sosl [String] SOSL
|
5
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
6
|
+
# @param format [Symbol,String] get the command's raw output. human, csv, json can be available.
|
7
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
7
8
|
#
|
8
9
|
# @return [Hash] the search result
|
9
10
|
# @note if you choose csv as format, csv files are downloaded in current directory
|
@@ -25,11 +26,12 @@ module SfCli::Sf::Data
|
|
25
26
|
#
|
26
27
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_search_unified command reference
|
27
28
|
#
|
28
|
-
def search(sosl, target_org: nil, format: nil)
|
29
|
+
def search(sosl, target_org: nil, format: nil, api_version: nil)
|
29
30
|
flags = {
|
30
31
|
:"query" => %|"#{sosl}"|,
|
31
32
|
:"target-org" => target_org,
|
32
33
|
:"result-format" => format,
|
34
|
+
:"api-version" => api_version,
|
33
35
|
}
|
34
36
|
raw_output = format ? true : false
|
35
37
|
format = format&.to_sym || :json
|
@@ -7,6 +7,7 @@ module SfCli::Sf::Data
|
|
7
7
|
# @param where [Hash] field values to identify a record
|
8
8
|
# @param values [Hash] field values for update
|
9
9
|
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
10
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
10
11
|
#
|
11
12
|
# @return [String] ID of the record updated
|
12
13
|
#
|
@@ -16,15 +17,16 @@ module SfCli::Sf::Data
|
|
16
17
|
#
|
17
18
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_update_record_unified command reference
|
18
19
|
#
|
19
|
-
def update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil)
|
20
|
+
def update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil, api_version: nil)
|
20
21
|
where_conditions = field_value_pairs(where)
|
21
22
|
field_values = field_value_pairs(values)
|
22
23
|
flags = {
|
23
|
-
:"sobject"
|
24
|
-
:"record-id"
|
25
|
-
:"where"
|
26
|
-
:"values"
|
27
|
-
:"target-org"
|
24
|
+
:"sobject" => object_type,
|
25
|
+
:"record-id" => record_id,
|
26
|
+
:"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
|
27
|
+
:"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
|
28
|
+
:"target-org" => target_org,
|
29
|
+
:"api-version" => api_version,
|
28
30
|
}
|
29
31
|
action = __method__.to_s.tr('_', ' ')
|
30
32
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -3,11 +3,14 @@ require_relative './bulk_result_v2'
|
|
3
3
|
module SfCli::Sf::Data
|
4
4
|
module UpsertBulk
|
5
5
|
# Update records using Bulk API 2.0
|
6
|
-
# @param file
|
6
|
+
# @param file [String,#read]
|
7
|
+
# (1)path of a CSV file, which is written record IDs to delete.
|
8
|
+
# (2) IO-like object, which has #read method
|
7
9
|
# @param sobject [Symbol,String] object type(ex. Account)
|
8
10
|
# @param external_id [String] name of the external ID field.Otherwise it must be Id
|
9
|
-
# @param
|
10
|
-
# @param target_org
|
11
|
+
# @param wait [Integer] max minutes to wait for the job complete the task
|
12
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
13
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
11
14
|
#
|
12
15
|
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
13
16
|
#
|
@@ -20,17 +23,29 @@ module SfCli::Sf::Data
|
|
20
23
|
# sf.data.upsert_resume job_id: jobinfo.id
|
21
24
|
#
|
22
25
|
# # Or, you can wait for the job completion with one try.
|
23
|
-
# result = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv',
|
26
|
+
# result = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv', wait: 5 # wait within 5 minutes
|
27
|
+
#
|
28
|
+
# # you can use IO-like object, which has #read, to `file` keyword:
|
29
|
+
# require 'stringio'
|
30
|
+
# csv = StringIO.new <<CSV
|
31
|
+
# Id,Name
|
32
|
+
# 001J400000Ki61uIAB,John Smith
|
33
|
+
# 001J400000Ki3WRIAZ,Foo Baz Bar
|
34
|
+
# CSV
|
35
|
+
# jobinfo = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: csv
|
24
36
|
#
|
25
37
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_upsert_bulk_unified command reference
|
26
38
|
#
|
27
|
-
def upsert_bulk(file:, sobject:, external_id:,
|
39
|
+
def upsert_bulk(file:, sobject:, external_id:, wait: nil, target_org: nil, api_version: nil)
|
40
|
+
_file = create_tmpfile_by_io(file)
|
41
|
+
path = _file&.path || file
|
28
42
|
flags = {
|
29
|
-
:"file"
|
30
|
-
:"sobject"
|
31
|
-
:"external-id"
|
32
|
-
:"wait"
|
33
|
-
:"target-org"
|
43
|
+
:"file" => path,
|
44
|
+
:"sobject" => sobject,
|
45
|
+
:"external-id" => external_id,
|
46
|
+
:"wait" => wait,
|
47
|
+
:"target-org" => target_org,
|
48
|
+
:"api-version" => api_version,
|
34
49
|
}
|
35
50
|
action = __method__.to_s.tr('_', ' ')
|
36
51
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -42,6 +57,8 @@ module SfCli::Sf::Data
|
|
42
57
|
job_info: job_info,
|
43
58
|
records: ::SfCli::Sf::Data::BulkRecordsV2.new(**json['result']['records'])
|
44
59
|
)
|
60
|
+
ensure
|
61
|
+
_file&.close!
|
45
62
|
end
|
46
63
|
end
|
47
64
|
end
|
@@ -3,9 +3,10 @@ require_relative './bulk_result_v2'
|
|
3
3
|
module SfCli::Sf::Data
|
4
4
|
module UpsertResume
|
5
5
|
# Resume a bulk upsert job you previously started with Bulk API 2.0 and return a bulk result object.
|
6
|
-
# @param job_id
|
7
|
-
# @param
|
8
|
-
# @param target_org
|
6
|
+
# @param job_id [String] job ID you want to resume
|
7
|
+
# @param wait [Integer] max minutes to wait for the job complete the task
|
8
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
9
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
9
10
|
#
|
10
11
|
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
11
12
|
#
|
@@ -16,18 +17,19 @@ module SfCli::Sf::Data
|
|
16
17
|
#
|
17
18
|
# # the job has already started asynchronously.
|
18
19
|
# # So you should check its progress.
|
19
|
-
# # if you want to wait for the job complete the task, try '
|
20
|
+
# # if you want to wait for the job complete the task, try 'wait' option.
|
20
21
|
# result = sf.data.upsert_resume job_id: jobinfo.id
|
21
22
|
#
|
22
23
|
# puts 'yey!' if result.job_info.completed? # the job has completed
|
23
24
|
#
|
24
25
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_upsert_resume_unified command reference
|
25
26
|
#
|
26
|
-
def upsert_resume(job_id:,
|
27
|
+
def upsert_resume(job_id:, wait: nil, target_org: nil, api_version: nil)
|
27
28
|
flags = {
|
28
29
|
:"job-id" => job_id,
|
29
|
-
:"wait" =>
|
30
|
+
:"wait" => wait,
|
30
31
|
:"target-org" => target_org,
|
32
|
+
:"api-version" => api_version,
|
31
33
|
}
|
32
34
|
action = __method__.to_s.tr('_', ' ')
|
33
35
|
json = exec(action, flags: flags, redirection: :null_stderr)
|