sf_cli 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9416d015ec2952621fe3525a9ed7177a68b98a86d3bced475eacf19d3ad88ce0
4
- data.tar.gz: 545bb5c54d345c194c5b62e8599492a45b13ba156b6ce195d3fb1fe38bb0d656
3
+ metadata.gz: c53d056727e589cb48d79aced7900a9419015ad0840e59b5f4d25361a31468ad
4
+ data.tar.gz: 491d45e9ce3907f931d07526eb37f9698e8c5b4cd95ffb3f38317244d99ea656
5
5
  SHA512:
6
- metadata.gz: bf7e32d0d73b0af136d8153b16b05cf837977f37bd2b95c0ab0cecd8fe23bef9cfcb64bda1a1b16dc1ae5ce92fbf239670c4282fd65df28ff0f4bd835f3810cc
7
- data.tar.gz: 835a95c35ef507c44d5108b613f7300bd8723428fd897ffc64ce8b0d14d0837929dc416c8259e12b713814903f1e5d59e1832e5d57bb9785f3c9bc397d111f8a
6
+ metadata.gz: a49220a708a8cab60b8ae22f09b4ac805c6b405c3ae0821809012d0cb4d3b34bfd66f69a3429ae4ed70799a0a6cd793c9edcd52e71b2811aaf7a887bdb8db075
7
+ data.tar.gz: dc8d5efe8ea8001212d448ca71fe874b61625960a6daea6163d459d9603c0d5ccbbf1b8c4795694495e4b1b963100113dd02e9dba56160322e3ab27ebcada2b3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 0.0.5 - 2024-09-08
2
+ - target CLI version is changed: from 2.54.6 to 2.56.7
3
+ - sf data:
4
+ - add `--bulk` option to query
5
+ - add query resume
6
+ - add upsert bulk
7
+ - add upsert resume
8
+ - add delete bulk
9
+ - add delete resume
10
+ - add resume
11
+ - add search
12
+ - sf org:
13
+ - add list
14
+ - add login access-token
15
+ - add `--browser` option to login web
16
+
1
17
  ## 0.0.4 - 2024-09-02
2
18
  - breaking change:
3
19
  - Sf class doesn't exist anymore. You can not write like `sf = SfCli::Sf.new`. Instead of that, global `sf` method is introduced. You can directly type like `sf.org.display`, which is as almost same usability as the original command.
@@ -5,8 +21,8 @@
5
21
  - support child-parent relationship
6
22
  - support parent-children relationship
7
23
  - add `--result-format` option
8
- - auto generation of Object Model (experimental)
9
- - generates SF Object Classes automatically
24
+ - auto generation of \Object Model (experimental)
25
+ - generates SF \Object Classes automatically
10
26
  - relationship is supported
11
27
 
12
28
  ## 0.0.3 - 2024-08-25
data/README.rdoc CHANGED
@@ -7,7 +7,7 @@ Currently only *sf* command is the target of development.
7
7
 
8
8
  == prerequisite
9
9
  Salesforce CLI must be installed.<br>
10
- As of as of August in 2024, ver.2.54.6 is the development target.
10
+ As of as of September in 2024, ver.2.56.7 is the development target.
11
11
 
12
12
  == install
13
13
  === Rubygem
@@ -23,35 +23,15 @@ then,
23
23
  == Examples
24
24
  === Since 0.0.4
25
25
  require 'sf_cli'
26
- #
26
+
27
27
  # login to org
28
- #
29
28
  sf.org.login_web
30
- sf.org.login_web target_org: :dev # if the org you login isn't the default one, you should give it alias name for later use.
31
29
 
32
- #
33
30
  # get records
34
- #
35
31
  sf.data.query 'SELECT Id, Name FROM Account LIMIT 1' # => [{Id: "abc", Name: "account name"}]
36
32
 
37
- Account = Struct.new(:Id, :Name) # you can manually prepare the object model
38
- sf.data.query('SELECT Id, Name From Account Limit 3', model_class: Account) # returns an array of Account
39
-
40
- # child-parent relationship is supported
41
- sf.data.query 'SELECT Id, Name, Account.Name From Contact Limit 1' # [{Id: "abc", Name: "contact name", Account: {Name: "account name"}}]
42
-
43
- # parent-children relationship is supported
44
- sf.data.query 'SELECT Id, Name, (SELECT Name From Contacts) FROM Account Limit 1' # [{Id: "abc", Name: "account name", Contacts: [{Name: "contact name"}]}]
45
-
46
- #
47
- # get sobject schema
48
- #
49
- sf.sobject.describe :Case # get Case Object schema information
50
-
51
- #
52
- # generate a Salesforce DX project with manifest generation option
53
- #
54
- sf.project.generate 'MyProject', manifest: true
33
+ # generate a Salesforce DX project
34
+ sf.project.generate 'MyProject'
55
35
 
56
36
  === Before 0.0.3
57
37
  require 'sf_cli/sf'
@@ -60,14 +40,10 @@ then,
60
40
 
61
41
  # login to org
62
42
  sf.org.login_web
63
- sf.org.login_web target_org: :dev # name an alias to the org, which you're going to log in, for later use. This is needed when you don't use the default org.
64
43
 
65
44
  # get Account records
66
45
  sf.data.query 'SELECT Id, Name FROM Account LIMIT 3' # => returns an array containing 3 records
67
46
 
68
- Account = Struct.new(:Id, :Name)
69
- sf.data.query('SELECT Id, Name From Account Limit 3', model_class: Account) # returns an array of Account struct object
70
-
71
47
  # generate a Salesforce DX project
72
48
  sf.project.generate 'MyProject'
73
49
 
@@ -75,14 +51,14 @@ then,
75
51
  require 'sf_cli'
76
52
  require 'sf_cli/sf/model'
77
53
 
78
- # generates Model Class for Contact and Account, accessing the org aliased as 'dev'
79
- SfCli::Sf::Model.generate %w[Contact Account], target_org: :dev
54
+ # generates Model Class for Contact and Account
55
+ SfCli::Sf::Model.generate %w[Contact Account]
80
56
 
81
57
  c = Contact.new(:Name => "John Smith")
82
58
  c.Name # => "John Smith"
83
59
 
84
- rows = sf.data.query 'SELECT Id, Name, Account.Name From Contact Limit 1', model_class: Contact
85
- rows.size # => 1
60
+ rows = sf.data.query 'SELECT Id, Name, Account.Name From Contact Limit 3', model_class: Contact
61
+ rows.size # => 3
86
62
  rows.first.Name # => Name of the Contact
87
63
  rows.first.Account.Name # => Name of the Account
88
64
 
@@ -0,0 +1,77 @@
1
+ module SfCli
2
+ module Sf
3
+ module Data
4
+ #
5
+ # Bulk Job information.
6
+ #
7
+ # You can check the job status using the following method:
8
+ # - opened?
9
+ # - upload_completed?
10
+ # - in_progress?
11
+ # - completed?
12
+ # ==== example:
13
+ # result = sf.data.delete_resume job_id: jobinfo.id
14
+ # puts 'yey!' if result.job_info.completed? # the job has completed
15
+ #
16
+ # For more details, see {the guide document}[https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/bulk_api_2_job_states.htm]
17
+ #
18
+ JobInfo = Struct.new(
19
+ :id,
20
+ :operation,
21
+ :object,
22
+ :createdById,
23
+ :createdDate,
24
+ :systemModstamp,
25
+ :state,
26
+ :externalIdFieldName,
27
+ :concurrencyMode,
28
+ :contentType,
29
+ :apiVersion,
30
+ :jobType,
31
+ :lineEnding,
32
+ :columnDelimiter,
33
+ :numberRecordsProcessed,
34
+ :numberRecordsFailed,
35
+ :retries,
36
+ :totalProcessingTime,
37
+ :apiActiveProcessingTime,
38
+ :apexProcessingTime,
39
+ :isPkChunkingSupported
40
+ ) do
41
+ def opened?
42
+ state == 'Open'
43
+ end
44
+
45
+ def upload_completed?
46
+ state == 'UploadComplete'
47
+ end
48
+
49
+ def in_progress?
50
+ state == 'InProgress'
51
+ end
52
+
53
+ def completed?
54
+ state == 'JobComplete'
55
+ end
56
+
57
+ def failed?
58
+ state == 'Failed'
59
+ end
60
+
61
+ def aborted?
62
+ state == 'Aborted'
63
+ end
64
+ end
65
+
66
+ #
67
+ # Records processed by Bulk API
68
+ #
69
+ BulkRecordsV2 = Struct.new(:successfulResults, :failedResults, :unprocessedRecords)
70
+
71
+ #
72
+ # Bulk Result information that contains JobInfo and BulkRecordsV2
73
+ #
74
+ BulkResultV2 = Struct.new(:job_info, :records)
75
+ end
76
+ end
77
+ end
@@ -1,5 +1,15 @@
1
1
  require_relative '../core/base'
2
- require_relative './helper_methods'
2
+ require_relative './query'
3
+ require_relative './get_record'
4
+ require_relative './update_record'
5
+ require_relative './create_record'
6
+ require_relative './delete_record'
7
+ require_relative './delete_bulk'
8
+ require_relative './delete_resume'
9
+ require_relative './upsert_bulk'
10
+ require_relative './upsert_resume'
11
+ require_relative './resume'
12
+ require_relative './search'
3
13
 
4
14
  module SfCli
5
15
  module Sf
@@ -12,167 +22,17 @@ module SfCli
12
22
  #
13
23
  class Core
14
24
  include ::SfCli::Sf::Core::Base
15
- include ::SfCli::Sf::Data::HelperMethods
16
-
17
- # get object records using SQOL. (eqivalent to *sf* *data* *query*)
18
- #
19
- # *soql* --- SOQL<br>
20
- # *target_org* --- an alias of paticular org, not default one<br>
21
- # *model_class* --- the object model class<br>
22
- #
23
- # == examples
24
- # sf.data.query 'SELECT Id, Name FROM Account LIMIT 1' # => [{Id: "abc", Name: "account name"}]
25
- #
26
- # Account = Struct.new(:Id, :Name)
27
- # sf.data.query('SELECT Id, Name From Account Limit 3', model_class: Account) # returns an array of Account struct object
28
- #
29
- # # child-parent relationship is supported
30
- # sf.data.query 'SELECT Id, Name, Account.Name From Contact Limit 1' # [{Id: "abc", Name: "contact name", Account: {Name: "account name"}}]
31
- #
32
- # # parent-children relationship is supported
33
- # sf.data.query 'SELECT Id, Name, (SELECT Name From Contacts) FROM Account Limit 1' # [{Id: "abc", Name: "account name", Contacts: [{Name: "contact name"}]}]
34
- #
35
- # Account = Struct.new(:Id, :Name) # you can manually prepare the object model
36
- # sf.data.query('SELECT Id, Name From Account Limit 3', model_class: Account) # returns an array of Account
37
- #
38
- # 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_query_unified]
39
- #
40
- # About querying with auto generated object model, see the section {"Object Model support"}[link://files/README_rdoc.html#label-Object+Model+support+-28experimental-2C+since+0.0.4-29] in README.
41
- #
42
- def query(soql, target_org: nil, format: nil, model_class: nil)
43
- flags = {
44
- :"query" => %("#{soql}"),
45
- :"target-org" => target_org,
46
- :"result-format" => format,
47
- }
48
-
49
- raw_output = format ? true : false
50
- format = format || :json
51
-
52
- result = exec(__method__, flags: flags, redirection: :null_stderr, raw_output: raw_output, format: format)
53
- return result if raw_output
54
-
55
- result['result']['records'].each_with_object([]) do |h, a|
56
- record = prepare_record(h)
57
- a << (model_class ? model_class.new(**record) : record)
58
- end
59
- end
60
-
61
- # get a object record. (eqivalent to *sf* *data* *get* *record*)
62
- #
63
- # *object_type* --- \Object Type (ex. Account)<br>
64
- # *record_id* --- id of the object<br>
65
- # *where* --- hash object that is used to identify a record<br>
66
- # *target_org* --- an alias of paticular org, not default one<br>
67
- # *model_class* --- the object model class<br>
68
- #
69
- # ==== examples
70
- # sf.data.get_record :Account, record_id: 'xxxxxxx'
71
- # sf.data.get_record :Account, where: {Name: 'Jonny B.Good', Country: 'USA'}
72
- #
73
- # CustomObject = Struct.new(:Id, :Name)
74
- # sf.data.get_record :TheCustomObject__c, record_id: 'xxxxx', model_class: CustomObject # returns a CustomObject struct object
75
- #
76
- # 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_get_record_unified]
77
- #
78
- def get_record(object_type, record_id: nil, where: nil, target_org: nil, model_class: nil)
79
- where_conditions = field_value_pairs(where)
80
- flags = {
81
- :"sobject" => object_type,
82
- :"record-id" => record_id,
83
- :"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
84
- :"target-org" => target_org,
85
- }
86
- action = __method__.to_s.tr('_', ' ')
87
- json = exec(action, flags: flags, redirection: :null_stderr)
88
-
89
- result = json['result']
90
- result.delete 'attributes'
91
-
92
- model_class ? model_class.new(**result) : result
93
- end
94
-
95
- # update a object record. (eqivalent to *sf* *data* *update* *record*)
96
- #
97
- # *object_type* --- \Object Type (ex. Account)<br>
98
- # *record_id* --- id of the object<br>
99
- # *where* --- field values that is used to identify a record<br>
100
- # *values* --- field values for update<br>
101
- # *target_org* --- an alias of paticular org, not default one<br>
102
- #
103
- # ==== examples
104
- # sf.data.update_record :Account, record_id: 'xxxxxxx', values: {Name: 'New Account Name'}
105
- # sf.data.update_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}, values: {Phone: 'xxxxx', bar: 2000}
106
- #
107
- # 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_update_record_unified]
108
- #
109
- def update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil)
110
- where_conditions = field_value_pairs(where)
111
- field_values = field_value_pairs(values)
112
- flags = {
113
- :"sobject" => object_type,
114
- :"record-id" => record_id,
115
- :"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
116
- :"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
117
- :"target-org" => target_org,
118
- }
119
- action = __method__.to_s.tr('_', ' ')
120
- json = exec(action, flags: flags, redirection: :null_stderr)
121
-
122
- json['result']['id']
123
- end
124
-
125
- # create a object record. (eqivalent to *sf* *data* *create* *record*)
126
- #
127
- # *object_type* --- \Object Type (ex. Account)<br>
128
- # *values* --- field values to be assigned<br>
129
- # *target_org* --- an alias of paticular org, not default one<br>
130
- #
131
- # ==== examples
132
- #
133
- # sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33} # creating a TheCustomObject record with name and age
134
- #
135
- # 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_create_record_unified]
136
- #
137
- def create_record(object_type, values: {}, target_org: nil)
138
- field_values = field_value_pairs(values)
139
- flags = {
140
- :"sobject" => object_type,
141
- :"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
142
- :"target-org" => target_org,
143
- }
144
- action = __method__.to_s.tr('_', ' ')
145
- json = exec(action, flags: flags, redirection: :null_stderr)
146
-
147
- json['result']['id']
148
- end
149
-
150
- # delete a object record. (eqivalent to *sf* *data* *delete* *record*)
151
- #
152
- # *object_type* --- \Object Type (ex. Account)<br>
153
- # *record_id* --- id of the object<br>
154
- # *where* --- hash object that is used to identify a record<br>
155
- # *target_org* --- an alias of paticular org, not default one<br>
156
- #
157
- # ==== examples
158
- # sf.data.delete_record :Hoge__c, record_id: 'xxxxxxx'
159
- # sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
160
- #
161
- # 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_record_unified]
162
- #
163
- def delete_record(object_type, record_id: nil, where: nil, target_org: nil)
164
- where_conditions = field_value_pairs(where)
165
- flags = {
166
- :"sobject" => object_type,
167
- :"record-id" => record_id,
168
- :"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
169
- :"target-org" => target_org,
170
- }
171
- action = __method__.to_s.tr('_', ' ')
172
- json = exec(action, flags: flags, redirection: :null_stderr)
173
-
174
- json['result']['id']
175
- end
25
+ include Query
26
+ include GetRecord
27
+ include UpdateRecord
28
+ include CreateRecord
29
+ include DeleteRecord
30
+ include DeleteBulk
31
+ include DeleteResume
32
+ include UpsertBulk
33
+ include UpsertResume
34
+ include Resume
35
+ include Search
176
36
  end
177
37
  end
178
38
  end
@@ -0,0 +1,30 @@
1
+ module SfCli::Sf::Data
2
+ module CreateRecord
3
+ # create a object record.
4
+ #
5
+ # *object_type* --- \Object Type (ex. Account)<br>
6
+ #
7
+ # *values* --- field values to be assigned<br>
8
+ #
9
+ # *target_org* --- an alias of paticular org, or username can be used<br>
10
+ #
11
+ # ======
12
+ # # create a TheCustomObject record with name and age
13
+ # sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33}
14
+ #
15
+ # 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_create_record_unified]
16
+ #
17
+ def create_record(object_type, values: {}, target_org: nil)
18
+ field_values = field_value_pairs(values)
19
+ flags = {
20
+ :"sobject" => object_type,
21
+ :"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
22
+ :"target-org" => target_org,
23
+ }
24
+ action = __method__.to_s.tr('_', ' ')
25
+ json = exec(action, flags: flags, redirection: :null_stderr)
26
+
27
+ json['result']['id']
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,47 @@
1
+ require_relative './bulk_result_v2'
2
+
3
+ module SfCli::Sf::Data
4
+ module DeleteBulk
5
+ # delete records using Bulk API 2.0
6
+ #
7
+ # *file* --- a CSV file, which is written record IDs to delete<br>
8
+ #
9
+ # *sobject* --- \Object Type (ex. Account)<br>
10
+ #
11
+ # *timeout* --- max minutes to wait for the job complete the task.<br>
12
+ #
13
+ # *target_org* --- an alias of paticular org, or username can be used<br>
14
+ #
15
+ # ======
16
+ # # start a delete job
17
+ # jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv' # this returns immediately
18
+ # jobinfo.id # => "750J4000003g1OaIAI" it's job ID
19
+ #
20
+ # # you can check if the delete job completed
21
+ # sf.data.delete_resume job_id: jobinfo.id
22
+ #
23
+ # # Or, you can wait for the job completion with one try.
24
+ # result = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv', timeout: 5 # wait within 5 minutes
25
+ #
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
+ #
28
+ def delete_bulk(file:, sobject:, timeout: nil, target_org: nil)
29
+ flags = {
30
+ :"file" => file,
31
+ :"sobject" => sobject,
32
+ :"wait" => timeout,
33
+ :"target-org" => target_org,
34
+ }
35
+ action = __method__.to_s.tr('_', ' ')
36
+ json = exec(action, flags: flags, redirection: :null_stderr)
37
+
38
+ job_info = ::SfCli::Sf::Data::JobInfo.new(**json['result']['jobInfo'])
39
+ return job_info unless json['result']['records']
40
+
41
+ ::SfCli::Sf::Data::BulkResultV2.new(
42
+ job_info: job_info,
43
+ records: ::SfCli::Sf::Data::BulkRecordsV2.new(**json['result']['records'])
44
+ )
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ module SfCli::Sf::Data
2
+ module DeleteRecord
3
+ # delete a object record.
4
+ #
5
+ # *object_type* --- \Object Type (ex. Account)<br>
6
+ #
7
+ # *record_id* --- id of the object<br>
8
+ #
9
+ # *where* --- hash object that is used to identify a record<br>
10
+ #
11
+ # *target_org* --- an alias of paticular org, or username can be used<br>
12
+ #
13
+ # ======
14
+ # sf.data.delete_record :Hoge__c, record_id: 'xxxxxxx'
15
+ # sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
16
+ #
17
+ # 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_record_unified]
18
+ #
19
+ def delete_record(object_type, record_id: nil, where: nil, target_org: nil)
20
+ where_conditions = field_value_pairs(where)
21
+ flags = {
22
+ :"sobject" => object_type,
23
+ :"record-id" => record_id,
24
+ :"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
25
+ :"target-org" => target_org,
26
+ }
27
+ action = __method__.to_s.tr('_', ' ')
28
+ json = exec(action, flags: flags, redirection: :null_stderr)
29
+
30
+ json['result']['id']
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,47 @@
1
+ require_relative './bulk_result_v2'
2
+
3
+ module SfCli::Sf::Data
4
+ module DeleteResume
5
+ # resume a bulk delete job you previously started with Bulk API 2.0 and return a bulk result object.
6
+ #
7
+ # *job_id* --- job ID you want to resume<br>
8
+ #
9
+ # *timeout* --- max minutes to wait for the job complete the task.<br>
10
+ #
11
+ # *target_org* --- an alias of paticular org, or username can be used<br>
12
+ #
13
+ # ======
14
+ # # start a delete job
15
+ # jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv' # this returns immediately
16
+ # jobinfo.id # => "750J4000003g1OaIAI" it's job ID
17
+ #
18
+ # # the job has already started asynchronously.
19
+ # # So you should check its progress.
20
+ # # if you want to wait for the job complete the task, try 'timeout' option.
21
+ # result = sf.data.delete_resume job_id: jobinfo.id
22
+ #
23
+ # puts 'yey!' if result.job_info.completed? # the job has completed
24
+ #
25
+ # To know more about a job result, take a look at SfCli::Sf::Data module
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]
28
+ #
29
+ def delete_resume(job_id:, timeout: nil, target_org: nil)
30
+ flags = {
31
+ :"job-id" => job_id,
32
+ :"wait" => timeout,
33
+ :"target-org" => target_org,
34
+ }
35
+ action = __method__.to_s.tr('_', ' ')
36
+ json = exec(action, flags: flags, redirection: :null_stderr)
37
+
38
+ job_info = ::SfCli::Sf::Data::JobInfo.new(**json['result']['jobInfo'])
39
+ return job_info unless json['result']['records']
40
+
41
+ ::SfCli::Sf::Data::BulkResultV2.new(
42
+ job_info: job_info,
43
+ records: ::SfCli::Sf::Data::BulkRecordsV2.new(**json['result']['records'])
44
+ )
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,42 @@
1
+ module SfCli::Sf::Data
2
+ module GetRecord
3
+
4
+ # get a object record. (eqivalent to *sf* *data* *get* *record*)
5
+ #
6
+ # *object_type* --- \Object Type (ex. Account)<br>
7
+ #
8
+ # *record_id* --- id of the object<br>
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
+ # ======
17
+ # sf.data.get_record :Account, record_id: 'xxxxxxx'
18
+ # sf.data.get_record :Account, where: {Name: 'Jonny B.Good', Country: 'USA'}
19
+ #
20
+ # CustomObject = Struct.new(:Id, :Name)
21
+ # sf.data.get_record :TheCustomObject__c, record_id: 'xxxxx', model_class: CustomObject # returns a CustomObject instance
22
+ #
23
+ # 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_get_record_unified]
24
+ #
25
+ def get_record(object_type, record_id: nil, where: nil, target_org: nil, model_class: nil)
26
+ where_conditions = field_value_pairs(where)
27
+ flags = {
28
+ :"sobject" => object_type,
29
+ :"record-id" => record_id,
30
+ :"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
31
+ :"target-org" => target_org,
32
+ }
33
+ action = __method__.to_s.tr('_', ' ')
34
+ json = exec(action, flags: flags, redirection: :null_stderr)
35
+
36
+ result = json['result']
37
+ result.delete 'attributes'
38
+
39
+ model_class ? model_class.new(**result) : result
40
+ end
41
+ end
42
+ end
@@ -16,6 +16,18 @@ module SfCli
16
16
  hash
17
17
  end
18
18
 
19
+ def prepare_record_in_bulk_mode(hash) # :doc:
20
+ hash.keys.each do |k|
21
+ match_result = /(.*)\.(.*)/.match(k)
22
+ if match_result
23
+ hash[match_result[1]] = {match_result[2] => hash[k]}
24
+ hash.delete k
25
+ end
26
+ end
27
+
28
+ hash
29
+ end
30
+
19
31
  def children?(h)
20
32
  return false unless h.instance_of?(Hash)
21
33