sf_cli 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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_methods.rb +5 -0
- data/lib/sf_cli/sf/model/sf_command_connection.rb +2 -2
- data/lib/sf_cli/sf/org/display.rb +3 -2
- data/lib/sf_cli/sf/sobject/describe.rb +5 -3
- data/lib/sf_cli/sf/sobject/list.rb +5 -3
- 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: 64f11658c0b90ce494643c625b80f6826ec42597723315fd52690aefc6d97c8c
|
4
|
+
data.tar.gz: e0318c64547346287a378766a3441249cf2906539693bc982e486d6bca4b7836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57c9f53f54298b2bcb7e566bceb48704012154c6a160e08402eb48d998cd2dc361d1f021bedb7866fade1beecfddab30affb0dcffa812cdfb20b7b6417c69df5
|
7
|
+
data.tar.gz: 875b18097589d7f4df8a212a078bbaf98e35de738782a8d4522f2a198861f280457ed23828838a77c645d170305423985edc16ee4e23ef77bd0afaeb8f0986af
|
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)
|
@@ -26,6 +26,11 @@ module SfCli
|
|
26
26
|
connection.find(name.to_sym, id, Object.const_get(name.to_sym))
|
27
27
|
end
|
28
28
|
|
29
|
+
def find_by(*find_condition)
|
30
|
+
qc = QueryCondition.new(connection, self.name, self.field_names)
|
31
|
+
qc.where(*find_condition).take
|
32
|
+
end
|
33
|
+
|
29
34
|
def limit(num)
|
30
35
|
qc = QueryCondition.new(connection, self.name, self.field_names)
|
31
36
|
qc.limit(num)
|
@@ -37,8 +37,8 @@ module SfCli
|
|
37
37
|
#
|
38
38
|
# For query details, see {SfCli::Sf::Data::Query sf data query}
|
39
39
|
#
|
40
|
-
def exec_query(soql, format: nil, bulk: false,
|
41
|
-
sf_data.query(soql, target_org: target_org, format: format, bulk: bulk,
|
40
|
+
def exec_query(soql, format: nil, bulk: false, wait: nil, model_class: nil)
|
41
|
+
sf_data.query(soql, target_org: target_org, format: format, bulk: bulk, wait: wait, model_class: model_class)
|
42
42
|
end
|
43
43
|
|
44
44
|
# @private :nodoc: just for developers
|
@@ -5,6 +5,7 @@ module SfCli::Sf::Org
|
|
5
5
|
#
|
6
6
|
# Returns the org's connection information
|
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
|
# @note this function returns the org information including security sensitive things such as access token, username and so on.
|
10
11
|
# @return [ConnectionInfo] the org's connection information
|
@@ -24,8 +25,8 @@ module SfCli::Sf::Org
|
|
24
25
|
#
|
25
26
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_display_unified command reference
|
26
27
|
#
|
27
|
-
def display(target_org: nil)
|
28
|
-
flags = {:"target-org" => target_org}
|
28
|
+
def display(target_org: nil, api_version: nil)
|
29
|
+
flags = {:"target-org" => target_org, :"api-version" => api_version}
|
29
30
|
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
30
31
|
|
31
32
|
ConnectionInfo.new(
|
@@ -5,6 +5,7 @@ module SfCli::Sf::Sobject
|
|
5
5
|
# Returns a schema object containing the Salesforce object schema
|
6
6
|
# @param object_type [Symbol,String] object type(ex: Account)
|
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 [Schema] a schema object that represents the object schema
|
10
11
|
#
|
@@ -17,10 +18,11 @@ module SfCli::Sf::Sobject
|
|
17
18
|
#
|
18
19
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_describe_unified command reference
|
19
20
|
#
|
20
|
-
def describe(object_type, target_org: nil)
|
21
|
+
def describe(object_type, target_org: nil, api_version: nil)
|
21
22
|
flags = {
|
22
|
-
:"sobject"
|
23
|
-
:"target-org"
|
23
|
+
:"sobject" => object_type,
|
24
|
+
:"target-org" => target_org,
|
25
|
+
:"api-version" => api_version,
|
24
26
|
}
|
25
27
|
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
26
28
|
Schema.new(json['result'])
|
@@ -3,13 +3,15 @@ module SfCli::Sf::Sobject
|
|
3
3
|
# Returns a list of Salesforce object name
|
4
4
|
# @param object_type [Symbol,String] 'all' or 'custom'
|
5
5
|
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
6
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
6
7
|
#
|
7
8
|
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_list_unified command reference
|
8
9
|
#
|
9
|
-
def list(object_type, target_org: nil)
|
10
|
+
def list(object_type, target_org: nil, api_version: nil)
|
10
11
|
flags = {
|
11
|
-
:"sobject"
|
12
|
-
:"target-org"
|
12
|
+
:"sobject" => (object_type.to_sym == :custom ? :custom : :all),
|
13
|
+
:"target-org" => target_org,
|
14
|
+
:"api-version" => api_version,
|
13
15
|
}
|
14
16
|
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
15
17
|
json['result']
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sf_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takanobu Maekawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
13
|
+
description: A class library for introducing Salesforce CLI to Ruby scripting. Currenty
|
14
|
+
only sf command is the target of development.
|
15
15
|
email:
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
@@ -84,5 +84,5 @@ requirements:
|
|
84
84
|
rubygems_version: 3.5.11
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
|
-
summary: A library for
|
87
|
+
summary: A library for Salesforce CLI in Ruby
|
88
88
|
test_files: []
|