sf_cli 0.0.7 → 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/{rdoc/README.rdoc → README.rdoc} +25 -39
- data/lib/sf_cli/console/commands.rb +52 -0
- data/lib/sf_cli/console.rb +5 -0
- data/lib/sf_cli/sf/apex/core.rb +5 -6
- data/lib/sf_cli/sf/apex/run.rb +32 -42
- data/lib/sf_cli/sf/core/base.rb +8 -0
- data/lib/sf_cli/sf/data/bulk_result_v2.rb +2 -3
- data/lib/sf_cli/sf/data/core.rb +5 -6
- data/lib/sf_cli/sf/data/create_record.rb +9 -9
- data/lib/sf_cli/sf/data/delete_bulk.rb +32 -16
- data/lib/sf_cli/sf/data/delete_record.rb +11 -10
- data/lib/sf_cli/sf/data/delete_resume.rb +14 -14
- data/lib/sf_cli/sf/data/get_record.rb +11 -13
- data/lib/sf_cli/sf/data/helper_methods.rb +1 -0
- data/lib/sf_cli/sf/data/query.rb +32 -35
- data/lib/sf_cli/sf/data/query_helper.rb +3 -0
- data/lib/sf_cli/sf/data/resume.rb +9 -7
- data/lib/sf_cli/sf/data/search.rb +12 -11
- data/lib/sf_cli/sf/data/update_record.rb +19 -20
- data/lib/sf_cli/sf/data/upsert_bulk.rb +33 -19
- data/lib/sf_cli/sf/data/upsert_resume.rb +12 -13
- data/lib/sf_cli/sf/main.rb +7 -3
- data/lib/sf_cli/sf/model/base_methods.rb +1 -0
- data/lib/sf_cli/sf/model/class_definition.rb +1 -0
- data/lib/sf_cli/sf/model/dml_methods.rb +1 -0
- data/lib/sf_cli/sf/model/generator.rb +2 -1
- data/lib/sf_cli/sf/model/query_condition.rb +1 -0
- data/lib/sf_cli/sf/model/query_methods.rb +6 -0
- data/lib/sf_cli/sf/model/sf_command_connection.rb +24 -5
- data/lib/sf_cli/sf/model.rb +6 -4
- data/lib/sf_cli/sf/org/core.rb +6 -6
- data/lib/sf_cli/sf/org/display.rb +10 -8
- data/lib/sf_cli/sf/org/list.rb +12 -13
- data/lib/sf_cli/sf/org/login.rb +22 -28
- data/lib/sf_cli/sf/project/core.rb +10 -72
- data/lib/sf_cli/sf/project/generate.rb +35 -0
- data/lib/sf_cli/sf/project/generate_manifest.rb +31 -0
- data/lib/sf_cli/sf/sobject/core.rb +10 -47
- data/lib/sf_cli/sf/sobject/describe.rb +31 -0
- data/lib/sf_cli/sf/sobject/list.rb +20 -0
- data/lib/sf_cli.rb +5 -12
- metadata +13 -12
- data/CHANGELOG.md +0 -57
- data/lib/sf_cli/sf/console.rb +0 -33
- data/rdoc/ObjectModel.rdoc +0 -83
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
|
@@ -5,75 +5,61 @@ This is a class library for introducing {Salesforce CLI}[https://developer.sales
|
|
5
5
|
It is designed to be similar usability to the original command.<br>
|
6
6
|
Currently only *sf* command is the target of development.
|
7
7
|
|
8
|
+
[rubygems] https://rubygems.org/gems/sf_cli
|
9
|
+
[official document] https://tmkw.github.io/sf_cli/
|
10
|
+
|
8
11
|
== prerequisite
|
9
|
-
Salesforce CLI must be installed.<br>
|
12
|
+
{Salesforce CLI}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_top.htm] must be installed.<br>
|
10
13
|
As of as of September in 2024, ver.2.56.7 is the development target.
|
11
14
|
|
12
15
|
== install
|
13
16
|
Rubygem::
|
14
|
-
|
15
|
-
|
17
|
+
the simplest way:
|
18
|
+
$ gem install sf_cli
|
16
19
|
Bundler::
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
==
|
22
|
-
|
23
|
-
{Online document}[https://www.rubydoc.info/gems/sf_cli/0.0.7] at rubygems.org
|
24
|
-
|
25
|
-
Or,
|
26
|
-
Generate locally:
|
27
|
-
$ git clone https://github.com/tmkw/sf_cli.git
|
28
|
-
$ cd sf_cli
|
29
|
-
$ bundle install
|
30
|
-
$ bundle exec rake rdoc
|
31
|
-
*As* *of* *0.0.7*, *this* *may* *be* *better* *to* *know* *what* *it* *is* *exactly*.
|
32
|
-
Salesforce CLI and Sf command::
|
33
|
-
1. {Salesforce CLI reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_top.htm]
|
34
|
-
2. {sf command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_unified.htm]
|
35
|
-
|
36
|
-
== Short Examples
|
20
|
+
in Gemfile:
|
21
|
+
gem 'sf_cli'
|
22
|
+
then,
|
23
|
+
$ bundle install
|
24
|
+
== Usage
|
25
|
+
Load module
|
37
26
|
require 'sf_cli'
|
38
27
|
|
39
|
-
|
28
|
+
Login to org
|
40
29
|
sf.org.login_web
|
41
30
|
|
42
|
-
|
31
|
+
Get Salesforce Object schema
|
43
32
|
sf.sobject.describe :Account
|
44
33
|
|
45
|
-
|
34
|
+
Get a record
|
46
35
|
sf.data.get_record :Account, record_id: 'xxxxxxx'
|
47
36
|
sf.data.get_record :Account, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
48
37
|
|
49
|
-
|
38
|
+
Execute SOQL
|
50
39
|
sf.data.query "SELECT Id, Name FROM Account LIMIT 1" # => [{Id: "abc", Name: "account name"}]
|
51
40
|
|
52
|
-
|
41
|
+
Create a record
|
53
42
|
sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33}
|
54
43
|
|
55
|
-
|
44
|
+
Update a record
|
56
45
|
sf.data.update_record :Account, record_id: 'xxxxxxx', values: {Name: 'New Account Name'}
|
57
46
|
sf.data.update_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}, values: {Phone: 'xxxxx', bar: 2000}
|
58
47
|
|
59
|
-
|
48
|
+
Delete a record
|
60
49
|
sf.data.delete_record :Hoge__c, record_id: 'xxxxxxx'
|
61
50
|
sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
62
51
|
|
63
|
-
|
64
|
-
sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv',
|
52
|
+
Using Bulk API 2.0
|
53
|
+
sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv', wait: 5 # waiting for 5 minutes at maximum
|
65
54
|
|
66
|
-
|
55
|
+
Run Apex
|
67
56
|
sf.apex.run file: 'path/to/file'
|
68
57
|
sf.apex.run file: StringIO.new("System.debug('Hello World')")
|
69
|
-
==
|
70
|
-
|
71
|
-
=== Short examples
|
72
|
-
===== With sf command:
|
58
|
+
== Object Model Support
|
59
|
+
With sf command:
|
73
60
|
rows = sf.data.query "SELECT Id, Name FROM Contact WHERE Name = 'Akin Kristen'", model_class: Contact
|
74
61
|
rows.first # <Contact: @Id="0035j00001RW3xbAAD", @Name="Akin Kristen">
|
75
62
|
rows.first.Name # Akin Kristen
|
76
|
-
|
63
|
+
Doing the same thing independently:
|
77
64
|
contact = Contact.select(:Id, :Name).where(Name: 'Akin Kristen').take
|
78
65
|
contact.Name # Akin Kristen
|
79
|
-
For more details, take a look at {the object model section}[link://files/rdoc/ObjectModel_rdoc.html]
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'sf_cli'
|
2
|
+
require 'sf_cli/sf/model'
|
3
|
+
require 'sf_cli/sf/model/sf_command_connection'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
module SfCli
|
7
|
+
# @private :nodoc: just for developers
|
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
|
+
#
|
22
|
+
module Commands
|
23
|
+
def use(_target_org)
|
24
|
+
target_org = _target_org.to_sym == :default ? nil : _target_org
|
25
|
+
org_info = sf.org.display target_org: target_org
|
26
|
+
conn = SfCli::Sf::Model::SfCommandConnection.new target_org: target_org, instance_url: org_info.instance_url
|
27
|
+
SfCli::Sf::Model.set_connection conn
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate(*object_types)
|
31
|
+
SfCli::Sf::Model.generate object_types
|
32
|
+
end
|
33
|
+
|
34
|
+
def connection
|
35
|
+
SfCli::Sf::Model.connection
|
36
|
+
end
|
37
|
+
|
38
|
+
def target_org
|
39
|
+
connection.target_org
|
40
|
+
end
|
41
|
+
|
42
|
+
def apex(apex_code = nil)
|
43
|
+
return sf.apex.run target_org: target_org if apex_code.nil?
|
44
|
+
|
45
|
+
sf.apex.run target_org: target_org, file: StringIO.new(apex_code)
|
46
|
+
end
|
47
|
+
|
48
|
+
alias :gen :generate
|
49
|
+
alias :conn :connection
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/sf_cli/sf/apex/core.rb
CHANGED
@@ -3,13 +3,12 @@ require_relative './run'
|
|
3
3
|
|
4
4
|
module SfCli
|
5
5
|
module Sf
|
6
|
+
# Apex Commands
|
7
|
+
#
|
8
|
+
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm command reference
|
9
|
+
#
|
6
10
|
module Apex
|
7
|
-
#
|
8
|
-
# ==== description
|
9
|
-
# The class representing *sf* *apex*.
|
10
|
-
#
|
11
|
-
# https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm
|
12
|
-
#
|
11
|
+
# @private :nodoc: just for developers
|
13
12
|
class Core
|
14
13
|
include ::SfCli::Sf::Core::Base
|
15
14
|
include Run
|
data/lib/sf_cli/sf/apex/run.rb
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
require 'tempfile'
|
2
|
-
require 'stringio'
|
3
2
|
|
4
3
|
module SfCli::Sf::Apex
|
5
4
|
module Run
|
6
5
|
#
|
7
|
-
#
|
6
|
+
# Run apex code and returns its result.
|
7
|
+
# If you don't specify the script file, it starts interactive mode.
|
8
|
+
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm#cli_reference_apex_run_unified CLI reference
|
8
9
|
#
|
9
|
-
#
|
10
|
+
# @param target_org [Symbol,String]
|
11
|
+
# an alias of paticular org, or username can be used.
|
12
|
+
# @param file [String,#read]
|
13
|
+
# (1) path to a local file that contains Apex code.
|
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
|
10
17
|
#
|
11
|
-
#
|
18
|
+
# @return [ApexResult] Apex execution result.
|
12
19
|
#
|
13
|
-
#
|
14
|
-
# Execute apex code in a file
|
20
|
+
# @example Execute apex code in a file
|
15
21
|
# result = sf.apex.run file: "path/to/apex"
|
16
22
|
# result.success # true if the execution succeeds
|
17
23
|
# result.logs # execution log
|
18
24
|
#
|
19
|
-
# StringIO is usable instead of file path
|
25
|
+
# @example StringIO is usable instead of file path
|
20
26
|
# require 'stringio'
|
21
27
|
#
|
22
28
|
# pseudo_file = StringIO.new <<~EOS
|
@@ -26,9 +32,7 @@ module SfCli::Sf::Apex
|
|
26
32
|
#
|
27
33
|
# sf.apex.run target_org: :dev, file: pseudo_file
|
28
34
|
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# If you don't specify *file* argument, it starts interactive mode that may be helpful in IRB environment.
|
35
|
+
# @example Interactive Mode
|
32
36
|
# irb(main:) > sf.apex.run target_org: :dev
|
33
37
|
#
|
34
38
|
# Account acc = [SELECT Id, Name FROM Account LIMIT 1];
|
@@ -48,48 +52,34 @@ module SfCli::Sf::Apex
|
|
48
52
|
# "Execute Anonymous: Account acc = [SELECT Id, Name FROM Account LIMIT 1];",
|
49
53
|
# "Execute Anonymous: System.debug(acc.Name);",
|
50
54
|
# ....]
|
51
|
-
# For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm#cli_reference_apex_run_unified]
|
52
55
|
#
|
53
|
-
def run(target_org: nil, file: nil)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
return unless file.is_a? String
|
58
|
-
|
59
|
-
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}
|
60
60
|
|
61
61
|
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
62
62
|
ApexResult.new(json['result'])
|
63
|
+
ensure
|
64
|
+
_file&.close!
|
63
65
|
end
|
64
66
|
|
65
67
|
private
|
66
68
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
flags = {:"target-org" => target_org, :"file" => file.path}
|
71
|
-
json = exec(:run, flags: flags, redirection: :null_stderr)
|
72
|
-
ApexResult.new(json['result'])
|
73
|
-
ensure
|
74
|
-
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)
|
75
72
|
end
|
76
73
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
flags = {:"target-org" => target_org, :"file" => file.path}
|
88
|
-
|
89
|
-
json = exec(:run, flags: flags, redirection: :null_stderr)
|
90
|
-
ApexResult.new(json['result'])
|
91
|
-
ensure
|
92
|
-
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
|
93
83
|
end
|
94
84
|
|
95
85
|
class ApexResult
|
data/lib/sf_cli/sf/core/base.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
module SfCli
|
4
5
|
module Sf
|
6
|
+
# @private :nodoc: just for developers
|
5
7
|
module Core
|
6
8
|
module Base
|
7
9
|
attr_reader :varbose
|
@@ -76,6 +78,12 @@ module SfCli
|
|
76
78
|
' 2> /dev/null'
|
77
79
|
end
|
78
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
|
79
87
|
end
|
80
88
|
end
|
81
89
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module SfCli
|
2
2
|
module Sf
|
3
3
|
module Data
|
4
|
-
#
|
5
4
|
# Bulk Job information.
|
6
5
|
#
|
7
6
|
# You can check the job status using the following method:
|
@@ -9,11 +8,11 @@ module SfCli
|
|
9
8
|
# - upload_completed?
|
10
9
|
# - in_progress?
|
11
10
|
# - completed?
|
12
|
-
#
|
11
|
+
# @example
|
13
12
|
# result = sf.data.delete_resume job_id: jobinfo.id
|
14
13
|
# puts 'yey!' if result.job_info.completed? # the job has completed
|
15
14
|
#
|
16
|
-
#
|
15
|
+
# See Also: {https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/bulk_api_2_job_states.htm the guide document}
|
17
16
|
#
|
18
17
|
JobInfo = Struct.new(
|
19
18
|
:id,
|
data/lib/sf_cli/sf/data/core.rb
CHANGED
@@ -13,13 +13,12 @@ require_relative './search'
|
|
13
13
|
|
14
14
|
module SfCli
|
15
15
|
module Sf
|
16
|
+
#
|
17
|
+
# Data Command
|
18
|
+
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm command reference
|
19
|
+
#
|
16
20
|
module Data
|
17
|
-
#
|
18
|
-
# ==== description
|
19
|
-
# The class representing *sf* *data*
|
20
|
-
#
|
21
|
-
# https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm
|
22
|
-
#
|
21
|
+
# @private :nodoc: just for developers
|
23
22
|
class Core
|
24
23
|
include ::SfCli::Sf::Core::Base
|
25
24
|
include Query
|
@@ -1,25 +1,25 @@
|
|
1
1
|
module SfCli::Sf::Data
|
2
2
|
module CreateRecord
|
3
3
|
# create a object record.
|
4
|
+
# @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_create_record_unified command reference
|
5
|
+
# @param object_type [Symbol, String] object type(ex. Account)
|
6
|
+
# @param values [Hash] field values to be assigned
|
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
|
4
9
|
#
|
5
|
-
#
|
10
|
+
# @return [String] record ID
|
6
11
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# *target_org* --- an alias of paticular org, or username can be used<br>
|
10
|
-
#
|
11
|
-
# ======
|
12
|
+
# @example
|
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
|
-
|
16
|
-
#
|
17
|
-
def create_record(object_type, values: {}, target_org: nil)
|
16
|
+
def create_record(object_type, values: {}, target_org: nil, api_version: nil)
|
18
17
|
field_values = field_value_pairs(values)
|
19
18
|
flags = {
|
20
19
|
:"sobject" => object_type,
|
21
20
|
:"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
|
22
21
|
:"target-org" => target_org,
|
22
|
+
:"api-version" => api_version,
|
23
23
|
}
|
24
24
|
action = __method__.to_s.tr('_', ' ')
|
25
25
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -2,17 +2,18 @@ require_relative './bulk_result_v2'
|
|
2
2
|
|
3
3
|
module SfCli::Sf::Data
|
4
4
|
module DeleteBulk
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
5
|
+
# Delete records using Bulk API 2.0
|
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
|
13
|
+
#
|
14
|
+
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
15
|
+
#
|
16
|
+
# @example
|
16
17
|
# # start a delete job
|
17
18
|
# jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv' # this returns immediately
|
18
19
|
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
@@ -21,16 +22,29 @@ module SfCli::Sf::Data
|
|
21
22
|
# sf.data.delete_resume job_id: jobinfo.id
|
22
23
|
#
|
23
24
|
# # Or, you can wait for the job completion with one try.
|
24
|
-
# 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
|
35
|
+
#
|
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
|
-
# For more command details, see {the command reference}[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]
|
27
38
|
#
|
28
|
-
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
|
29
42
|
flags = {
|
30
|
-
:"file" =>
|
43
|
+
:"file" => path,
|
31
44
|
:"sobject" => sobject,
|
32
|
-
:"wait" =>
|
45
|
+
:"wait" => wait,
|
33
46
|
:"target-org" => target_org,
|
47
|
+
:"api-version" => api_version,
|
34
48
|
}
|
35
49
|
action = __method__.to_s.tr('_', ' ')
|
36
50
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -42,6 +56,8 @@ module SfCli::Sf::Data
|
|
42
56
|
job_info: job_info,
|
43
57
|
records: ::SfCli::Sf::Data::BulkRecordsV2.new(**json['result']['records'])
|
44
58
|
)
|
59
|
+
ensure
|
60
|
+
_file&.close!
|
45
61
|
end
|
46
62
|
end
|
47
63
|
end
|
@@ -1,28 +1,29 @@
|
|
1
1
|
module SfCli::Sf::Data
|
2
2
|
module DeleteRecord
|
3
|
-
#
|
3
|
+
# Delete a object record.
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# @param object_type [Symbol, String] Object Type (ex. Account)
|
6
|
+
# @param record_id [String] Id of the object
|
7
|
+
# @param where [Hash] conditions to identify a record
|
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
|
6
10
|
#
|
7
|
-
#
|
11
|
+
# @return [String] ID that is deleted.
|
8
12
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# *target_org* --- an alias of paticular org, or username can be used<br>
|
12
|
-
#
|
13
|
-
# ======
|
13
|
+
# @example
|
14
14
|
# sf.data.delete_record :Hoge__c, record_id: 'xxxxxxx'
|
15
15
|
# sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
16
16
|
#
|
17
|
-
#
|
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
|
18
18
|
#
|
19
|
-
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)
|
20
20
|
where_conditions = field_value_pairs(where)
|
21
21
|
flags = {
|
22
22
|
:"sobject" => object_type,
|
23
23
|
:"record-id" => record_id,
|
24
24
|
:"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
|
25
25
|
:"target-org" => target_org,
|
26
|
+
:"api-version" => api_version,
|
26
27
|
}
|
27
28
|
action = __method__.to_s.tr('_', ' ')
|
28
29
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -2,35 +2,35 @@ require_relative './bulk_result_v2'
|
|
2
2
|
|
3
3
|
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
|
-
#
|
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
|
8
11
|
#
|
9
|
-
#
|
12
|
+
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
10
13
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# ======
|
14
|
+
# @example
|
14
15
|
# # start a delete job
|
15
16
|
# jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv' # this returns immediately
|
16
17
|
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
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
|
-
#
|
27
|
-
# For more command details, see {the command reference}[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]
|
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
|
28
27
|
#
|
29
|
-
def delete_resume(job_id:,
|
28
|
+
def delete_resume(job_id:, wait: nil, target_org: nil, api_version: nil)
|
30
29
|
flags = {
|
31
|
-
:"job-id"
|
32
|
-
:"wait"
|
33
|
-
:"target-org"
|
30
|
+
:"job-id" => job_id,
|
31
|
+
:"wait" => wait,
|
32
|
+
:"target-org" => target_org,
|
33
|
+
:"api-version" => api_version,
|
34
34
|
}
|
35
35
|
action = __method__.to_s.tr('_', ' ')
|
36
36
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -1,26 +1,24 @@
|
|
1
1
|
module SfCli::Sf::Data
|
2
2
|
module GetRecord
|
3
3
|
|
4
|
-
#
|
4
|
+
# Get a object record.
|
5
|
+
# @param object_type [Symbol,String] object type(ex. Account)
|
6
|
+
# @param record_id [String] id of the object
|
7
|
+
# @param where [Hash] conditions to identify a record
|
8
|
+
# @param target_org [Symbol,String] an alias of paticular org, not default one
|
9
|
+
# @param model_class [Class] the object model class
|
5
10
|
#
|
6
|
-
#
|
11
|
+
# @return [Hash,Class] if proper model class is specified, the return value is the instance of the class. Otherwise, it's a Hash object.
|
7
12
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# *where* --- hash object that is used to identify a record<br>
|
11
|
-
#
|
12
|
-
# *target_org* --- an alias of paticular org, not default one<br>
|
13
|
-
#
|
14
|
-
# *model_class* --- the object model class<br>
|
15
|
-
#
|
16
|
-
# ======
|
13
|
+
# @example
|
17
14
|
# sf.data.get_record :Account, record_id: 'xxxxxxx'
|
18
15
|
# sf.data.get_record :Account, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
19
16
|
#
|
20
17
|
# CustomObject = Struct.new(:Id, :Name)
|
21
|
-
# sf.data.get_record :TheCustomObject__c, record_id: 'xxxxx', model_class: CustomObject
|
18
|
+
# obj = sf.data.get_record :TheCustomObject__c, record_id: 'xxxxx', model_class: CustomObject # returns a CustomObject instance
|
19
|
+
# obj.Name # Name field of the record
|
22
20
|
#
|
23
|
-
#
|
21
|
+
# @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_get_record_unified command reference
|
24
22
|
#
|
25
23
|
def get_record(object_type, record_id: nil, where: nil, target_org: nil, model_class: nil)
|
26
24
|
where_conditions = field_value_pairs(where)
|