sf_cli 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -2
- data/README.rdoc +85 -40
- data/lib/sf_cli/sf/core/base.rb +2 -0
- data/lib/sf_cli/sf/data/bulk_result_v2.rb +77 -0
- data/lib/sf_cli/sf/data/core.rb +22 -162
- data/lib/sf_cli/sf/data/create_record.rb +30 -0
- data/lib/sf_cli/sf/data/delete_bulk.rb +47 -0
- data/lib/sf_cli/sf/data/delete_record.rb +33 -0
- data/lib/sf_cli/sf/data/delete_resume.rb +47 -0
- data/lib/sf_cli/sf/data/get_record.rb +42 -0
- data/lib/sf_cli/sf/data/helper_methods.rb +12 -0
- data/lib/sf_cli/sf/data/query.rb +120 -0
- data/lib/sf_cli/sf/data/query_helper.rb +57 -0
- data/lib/sf_cli/sf/data/resume.rb +87 -0
- data/lib/sf_cli/sf/data/search.rb +50 -0
- data/lib/sf_cli/sf/data/update_record.rb +38 -0
- data/lib/sf_cli/sf/data/upsert_bulk.rb +50 -0
- data/lib/sf_cli/sf/data/upsert_resume.rb +47 -0
- data/lib/sf_cli/sf/model/base_methods.rb +62 -0
- data/lib/sf_cli/sf/model/class_definition.rb +34 -43
- data/lib/sf_cli/sf/model/dml_methods.rb +36 -0
- data/lib/sf_cli/sf/model/generator.rb +8 -7
- data/lib/sf_cli/sf/model/query_condition.rb +136 -0
- data/lib/sf_cli/sf/model/query_methods.rb +58 -0
- data/lib/sf_cli/sf/model/sf_command_connection.rb +60 -0
- data/lib/sf_cli/sf/model.rb +10 -2
- data/lib/sf_cli/sf/org/core.rb +6 -44
- data/lib/sf_cli/sf/org/display.rb +41 -0
- data/lib/sf_cli/sf/org/list.rb +67 -0
- data/lib/sf_cli/sf/org/login.rb +64 -0
- data/lib/sf_cli/sf/project/core.rb +10 -3
- data/lib/sf_cli/sf/sobject/core.rb +15 -5
- data/lib/sf_cli/sf/sobject/schema.rb +47 -0
- data/lib/sf_cli.rb +8 -5
- metadata +29 -8
- data/lib/sf_cli/sf/model/schema.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1996a0f93b6d2f48ea8762961526eab00df5601c902f2ec81f21331382973e56
|
4
|
+
data.tar.gz: da4da9fe6855d6f44f7995d932e6f658565b6e41091bd4c908e651a8286ece95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36743c7b02fbdf21626a4dcf7ce299bdce68d99e0281bac62b08180ac48792b112b130402e3b75d589f13e57acdf33b33d139db00237818b784b6ab1cd37aef4
|
7
|
+
data.tar.gz: d4008513bbbf74b24de5c94f0cfc868367b37c9d2d876806e8eb2f546669768db94c5c1f981dbad732214c16ca26ee969eeb7027c59abda23d49a6e7b8e038fa
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## 0.0.6 - 2024-09-16
|
2
|
+
- NEW: Object Model Support renewal;
|
3
|
+
- `SfCli::Sf::Model.connection` represents the connection to Salesforce. It can be set by `set_connection` class method in the module. As of now there is only `SfCommandConnection`, which is based on sf command, as connection adapter. After the connection is set by `set_connection`, it is also automatically set to classes when `SfCli::Sf::Model.generate` method is called.
|
4
|
+
- Each object model class has `create` class method for creating a new record.
|
5
|
+
- Each object model has `#save` and `#delete` instance methods to create, update and delete the record it represents.
|
6
|
+
- Each object class has query interface such as `where`, `select`, `limit` and `order` methods that can be chainable.
|
7
|
+
- Each object class has query interface such as `find`, `all`, `take` and `pluck`.
|
8
|
+
- CHANGE: `sf.sobject.describe` changed to return `schema` object.
|
9
|
+
## 0.0.5 - 2024-09-08
|
10
|
+
- CHANGE: target CLI version is changed: from 2.54.6 to 2.56.7
|
11
|
+
- NEW: new command features are added;
|
12
|
+
- `--bulk` option to `sf.data.query`
|
13
|
+
- `sf.data.query_resume`
|
14
|
+
- `sf.data.upsert_bulk`
|
15
|
+
- `sf.data.upsert_resume`
|
16
|
+
- `sf.data.delete_bulk`
|
17
|
+
- `sf.data.delete_resume`
|
18
|
+
- `sf.data.resume`
|
19
|
+
- `sf.data.search`
|
20
|
+
- `sf.org.list`
|
21
|
+
- `sf.login_access_token`
|
22
|
+
- `--browser` option to `sf.login_web`
|
1
23
|
## 0.0.4 - 2024-09-02
|
2
24
|
- breaking change:
|
3
25
|
- 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 +27,8 @@
|
|
5
27
|
- support child-parent relationship
|
6
28
|
- support parent-children relationship
|
7
29
|
- add `--result-format` option
|
8
|
-
- auto generation of Object Model (experimental)
|
9
|
-
- generates SF Object Classes automatically
|
30
|
+
- auto generation of \Object Model (experimental)
|
31
|
+
- generates SF \Object Classes automatically
|
10
32
|
- relationship is supported
|
11
33
|
|
12
34
|
## 0.0.3 - 2024-08-25
|
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Salesforce CLI library
|
1
|
+
= Salesforce CLI library for Ruby
|
2
2
|
https://badge.fury.io/rb/sf_cli.png
|
3
3
|
|
4
4
|
This is a class library for introducing {Salesforce CLI}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_top.htm] to Ruby scripting.<br>
|
@@ -7,13 +7,13 @@ 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
|
10
|
+
As of as of September in 2024, ver.2.56.7 is the development target.
|
11
11
|
|
12
12
|
== install
|
13
|
-
|
13
|
+
==== Rubygem
|
14
14
|
$ gem install sf_cli
|
15
15
|
|
16
|
-
|
16
|
+
==== Bundler
|
17
17
|
in Gemfile:
|
18
18
|
gem 'sf_cli'
|
19
19
|
|
@@ -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
|
-
|
38
|
-
sf.
|
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,31 +40,96 @@ 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
|
|
74
50
|
== \Object Model support (experimental, since 0.0.4)
|
75
|
-
|
51
|
+
=== generate Models
|
76
52
|
require 'sf_cli/sf/model'
|
53
|
+
require 'sf_cli/sf/model/sf_command_connection'
|
77
54
|
|
78
|
-
#
|
79
|
-
SfCli::Sf::Model.
|
55
|
+
# first, you must prepare the connection
|
56
|
+
conn = SfCli::Sf::Model::SfCommandConnection.new target_org: your_org, instance_url: your_org_url
|
80
57
|
|
81
|
-
|
82
|
-
|
58
|
+
# then set it to Model module
|
59
|
+
SfCli::Sf::Model.set_connection conn
|
83
60
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
rows.
|
61
|
+
# generates some model classes (for example, Account and Contact)
|
62
|
+
SfCli::Sf::Model.generate %w[Account Contact]
|
63
|
+
=== apply to sf command
|
64
|
+
rows = sf.data.query "SELECT Id, Name FROM Contact WHERE Name = 'Akin Kristen'", model_class: Contact
|
65
|
+
|
66
|
+
# the array object contains Contact object instances
|
67
|
+
rows.size # 1
|
68
|
+
rows.first # <Contact: @Id="0035j00001RW3xbAAD", @Name="Akin Kristen">
|
69
|
+
rows.first.Name # Akin Kristen
|
70
|
+
|
71
|
+
=== using models Independently
|
72
|
+
==== initialize and save a record
|
73
|
+
c = Contact.new(:Name => "John Smith")
|
74
|
+
c.Name # "John Smith"
|
75
|
+
c.save
|
76
|
+
|
77
|
+
==== find and update a record
|
78
|
+
# find by record ID and update
|
79
|
+
c2 = Contact.find(c.id)
|
80
|
+
c2.Name = "Johnny Smith"
|
81
|
+
c2.save # update
|
82
|
+
|
83
|
+
==== delete a record
|
84
|
+
c2 = Contact.find(c.id)
|
85
|
+
c2.delete
|
86
|
+
|
87
|
+
==== query and get a record
|
88
|
+
contact = Contact.select(:Id, :Name).where(Name: 'Akin Kristen').take
|
89
|
+
contact # => #<Contact: @Id="0035j00001RW3xbAAD", @Name="Akin Kristen">
|
90
|
+
contact.Name # Akin Kristen
|
91
|
+
|
92
|
+
==== query and get records
|
93
|
+
contacts = Contact.select(:Id, :Name).where(LastModifiedDate: :Yesterday).all # get all records that is modified yesterday
|
94
|
+
|
95
|
+
# these 2 example are the same meaning
|
96
|
+
Contact.select(Name).where(Name: 'John Smith', LastModifiedDate: :Yesterday).take
|
97
|
+
Contact.select(Name).where(Name: 'John Smith').where(LastModifiedDate: :Yesterday).take
|
98
|
+
|
99
|
+
==== child-parent relationship
|
100
|
+
contact = Contact.select(:Id, :Name, "Account.Name").where(Name: 'Akin Kristen').take
|
101
|
+
contact # <Contact: @Id="0035j00001RW3xbAAD", @Name="Akin Kristen", @Account= #<Account @Name="Aethna Home Products">>
|
102
|
+
contact.Account.Name # Aethna Home Products
|
103
|
+
|
104
|
+
==== parent-children relationship
|
105
|
+
account = Account.select(:Id, :Name, "(SELECT Name FROM Contacts)").take
|
106
|
+
account # <Account @Contacts=[#<Contact @Name="Akin Kristen">], @Id="0015j00001dsDuhAAE", @Name="Aethna Home Products">
|
107
|
+
account.Name # Aethna Home Products
|
108
|
+
rows.Contacts # [#<Contact @Name="Akin Kristen">]
|
109
|
+
rows.Contacts.first.Name # Akin Kristen
|
110
|
+
|
111
|
+
==== get all fields in a record
|
112
|
+
# just by not using 'select' method
|
113
|
+
contact = Contact.find(record_id) # <Contact @Id="...", @Name="...", other fields...>
|
114
|
+
|
115
|
+
==== time keywords such as 'yesterday' or 'LAST_N_DAYS:N' with symbol style
|
116
|
+
Contact.select(:Name).where(LastModifiedDate: :Yesterday).take # "SELECT Id, Name FROM Contact WHERE LastModifiedDate = Yesterday"
|
117
|
+
Contact.select(:Name).where(LastModifiedDate: :"LAST_N_DAYS:5").take # "SELECT Id, Name FROM Contact WHERE LastModifiedDate = LAST_N_DAYS:5"
|
118
|
+
|
119
|
+
==== array for 'IN' keyword
|
120
|
+
Contact.select(:Name).where(Name: ['Jonny Good', 'John Smith']).all # same as "SELECT Name FROM Contact WHERE Name IN ('Jonny Good', 'John Smith')"
|
121
|
+
|
122
|
+
==== using partial soql directly
|
123
|
+
Contact.select("Id, Name").where("LastModifiedDate = LAST_N_DAYS:5").all
|
124
|
+
|
125
|
+
==== ternary style
|
126
|
+
Contact.select(:Id, :Name).where(:LastModifiedDate, :>=, :"LAST_N_DAYS:5").all # SELECT Id, Name FROM Contact WHERE LastModifiedDate >= LAST_N_DAYS:5
|
127
|
+
Account.select(:Id, :Name).where(:Name, :LIKE, "%OIL%").all # SELECT Id, Name FROM Account WHERE Name LIKE '%OIL%'
|
128
|
+
|
129
|
+
==== get schema
|
130
|
+
schema = Account.describe
|
131
|
+
schema.name # Account
|
132
|
+
schema.field_names # [Id, Name, ....]
|
88
133
|
|
89
134
|
== Documents
|
90
135
|
The following steps generate *doc* directory, which all documents are generated in.
|
data/lib/sf_cli/sf/core/base.rb
CHANGED
@@ -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
|
data/lib/sf_cli/sf/data/core.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
require_relative '../core/base'
|
2
|
-
require_relative './
|
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
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|