sf_cli 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{rdoc/README.rdoc → README.rdoc} +24 -38
- data/lib/sf_cli/console/commands.rb +36 -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 +13 -10
- data/lib/sf_cli/sf/core/base.rb +1 -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 +6 -8
- data/lib/sf_cli/sf/data/delete_bulk.rb +9 -10
- data/lib/sf_cli/sf/data/delete_record.rb +8 -9
- data/lib/sf_cli/sf/data/delete_resume.rb +7 -9
- 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 +20 -27
- data/lib/sf_cli/sf/data/query_helper.rb +3 -0
- data/lib/sf_cli/sf/data/resume.rb +6 -6
- data/lib/sf_cli/sf/data/search.rb +9 -10
- data/lib/sf_cli/sf/data/update_record.rb +11 -14
- data/lib/sf_cli/sf/data/upsert_bulk.rb +9 -12
- data/lib/sf_cli/sf/data/upsert_resume.rb +7 -10
- 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 +1 -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 +7 -6
- 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 +29 -0
- data/lib/sf_cli/sf/sobject/list.rb +18 -0
- data/lib/sf_cli.rb +5 -12
- metadata +10 -9
- 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: fa13644d7e9281efbbb57516775a5edd9b69fb7ff9fbc260332a54d0afebc227
|
4
|
+
data.tar.gz: feb9c574b8d0681fbe9ba43572cb9b7725558fc20f69eebbbd3a2b3734aa60b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ade35b3acd147ac13367c6d681c31028fef4b661ab2a97101e21b170221231c81c8d76a13c9e6f2688b085ae4889c8872ced4dd72b4f1d21cc8ac465cde78096
|
7
|
+
data.tar.gz: f7fb45fc3c50d2ab557f82d28b74119465fddad2c5930710aadbe0b44c19da49b8ac76c6815f0e18132d0f49d1590ed456ed42069ca07385e75db3d630f0812e
|
@@ -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
|
-
|
52
|
+
Using Bulk API 2.0
|
64
53
|
sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv', timeout: 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 (experimental)
|
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,36 @@
|
|
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
|
+
module Console
|
8
|
+
module Commands
|
9
|
+
def use(_target_org)
|
10
|
+
target_org = _target_org.to_sym == :default ? nil : _target_org
|
11
|
+
org_info = sf.org.display target_org: target_org
|
12
|
+
conn = SfCli::Sf::Model::SfCommandConnection.new target_org: target_org, instance_url: org_info.instance_url
|
13
|
+
SfCli::Sf::Model.set_connection conn
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate(*object_types)
|
17
|
+
SfCli::Sf::Model.generate object_types
|
18
|
+
end
|
19
|
+
|
20
|
+
def connection
|
21
|
+
SfCli::Sf::Model.connection
|
22
|
+
end
|
23
|
+
|
24
|
+
def target_org
|
25
|
+
connection.target_org
|
26
|
+
end
|
27
|
+
|
28
|
+
def apex(apex_code)
|
29
|
+
sf.apex.run target_org: target_org, file: StringIO.new(apex_code)
|
30
|
+
end
|
31
|
+
|
32
|
+
alias :gen :generate
|
33
|
+
alias :conn :connection
|
34
|
+
end
|
35
|
+
end
|
36
|
+
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
@@ -4,19 +4,25 @@ require 'stringio'
|
|
4
4
|
module SfCli::Sf::Apex
|
5
5
|
module Run
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# Run apex code and returns its result.
|
8
|
+
# If you don't specify the script file, it starts interactive mode.
|
9
|
+
# @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
10
|
#
|
9
|
-
#
|
11
|
+
# @param target_org [Symbol,String]
|
12
|
+
# an alias of paticular org, or username can be used.
|
10
13
|
#
|
11
|
-
#
|
14
|
+
# @param file [String,StringIO]
|
15
|
+
# (1) path to a local file that contains Apex code.
|
16
|
+
# (2) StringIO object
|
12
17
|
#
|
13
|
-
#
|
14
|
-
#
|
18
|
+
# @return [ApexResult] Apex execution result.
|
19
|
+
#
|
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,7 +52,6 @@ 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
56
|
def run(target_org: nil, file: nil)
|
54
57
|
return run_interactive(target_org) if file.nil?
|
data/lib/sf_cli/sf/core/base.rb
CHANGED
@@ -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,19 +1,17 @@
|
|
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
|
4
8
|
#
|
5
|
-
#
|
9
|
+
# @return [String] record ID
|
6
10
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# *target_org* --- an alias of paticular org, or username can be used<br>
|
10
|
-
#
|
11
|
-
# ======
|
11
|
+
# @example
|
12
12
|
# # create a TheCustomObject record with name and age
|
13
13
|
# sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33}
|
14
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
15
|
def create_record(object_type, values: {}, target_org: nil)
|
18
16
|
field_values = field_value_pairs(values)
|
19
17
|
flags = {
|
@@ -2,17 +2,15 @@ require_relative './bulk_result_v2'
|
|
2
2
|
|
3
3
|
module SfCli::Sf::Data
|
4
4
|
module DeleteBulk
|
5
|
-
#
|
5
|
+
# Delete records using Bulk API 2.0
|
6
|
+
# @param file [String] path of a CSV file, which is written record IDs to delete
|
7
|
+
# @param sobject [Symbol, String] object type (ex. Account)
|
8
|
+
# @param timeout [Integer] max minutes to wait for the job complete the task.
|
9
|
+
# @param target_org [Symbol, String] an alias of paticular org, or username can be used
|
6
10
|
#
|
7
|
-
#
|
11
|
+
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
8
12
|
#
|
9
|
-
#
|
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
|
-
# ======
|
13
|
+
# @example
|
16
14
|
# # start a delete job
|
17
15
|
# jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv' # this returns immediately
|
18
16
|
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
@@ -23,7 +21,8 @@ module SfCli::Sf::Data
|
|
23
21
|
# # Or, you can wait for the job completion with one try.
|
24
22
|
# result = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv', timeout: 5 # wait within 5 minutes
|
25
23
|
#
|
26
|
-
#
|
24
|
+
# @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
|
+
#
|
27
26
|
#
|
28
27
|
def delete_bulk(file:, sobject:, timeout: nil, target_org: nil)
|
29
28
|
flags = {
|
@@ -1,20 +1,19 @@
|
|
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
|
6
9
|
#
|
7
|
-
#
|
10
|
+
# @return [String] ID that is deleted.
|
8
11
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# *target_org* --- an alias of paticular org, or username can be used<br>
|
12
|
-
#
|
13
|
-
# ======
|
12
|
+
# @example
|
14
13
|
# sf.data.delete_record :Hoge__c, record_id: 'xxxxxxx'
|
15
14
|
# sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
16
15
|
#
|
17
|
-
#
|
16
|
+
# @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
17
|
#
|
19
18
|
def delete_record(object_type, record_id: nil, where: nil, target_org: nil)
|
20
19
|
where_conditions = field_value_pairs(where)
|
@@ -2,15 +2,15 @@ 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 timeout [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>
|
8
10
|
#
|
9
|
-
#
|
11
|
+
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
10
12
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# ======
|
13
|
+
# @example
|
14
14
|
# # start a delete job
|
15
15
|
# jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv' # this returns immediately
|
16
16
|
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
@@ -22,9 +22,7 @@ module SfCli::Sf::Data
|
|
22
22
|
#
|
23
23
|
# puts 'yey!' if result.job_info.completed? # the job has completed
|
24
24
|
#
|
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]
|
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_delete_resume_unified the command reference
|
28
26
|
#
|
29
27
|
def delete_resume(job_id:, timeout: nil, target_org: nil)
|
30
28
|
flags = {
|
@@ -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)
|
data/lib/sf_cli/sf/data/query.rb
CHANGED
@@ -3,21 +3,17 @@ require_relative './query_helper'
|
|
3
3
|
|
4
4
|
module SfCli::Sf::Data
|
5
5
|
module Query
|
6
|
-
#
|
6
|
+
# Get object records using SOQL.
|
7
|
+
# @param soql [String] SOQL
|
8
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
9
|
+
# @param format [Symbol,String] get the command's raw output. human, csv, json can be available
|
10
|
+
# @param model_class [Class] the object model class
|
11
|
+
# @param bulk [Boolean] use Bulk API
|
12
|
+
# @param timeout [Integer] max minutes to wait for the job complete in Bulk API mode
|
7
13
|
#
|
8
|
-
#
|
14
|
+
# @return [Array,[String,Array]] records or a tuple containing a flag and records
|
9
15
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# *format* --- get the command's raw output. human, csv, json can be available<br>
|
13
|
-
#
|
14
|
-
# *model_class* --- the object model class<br>
|
15
|
-
#
|
16
|
-
# *bulk* --- use Bulk API<br>
|
17
|
-
#
|
18
|
-
# *timeout* --- max minutes to wait for the job complete in Bulk API mode<br>
|
19
|
-
#
|
20
|
-
# ======
|
16
|
+
# @example
|
21
17
|
# sf.data.query 'SELECT Id, Name FROM Account LIMIT 1' # => [{Id: "abc", Name: "account name"}]
|
22
18
|
#
|
23
19
|
# Account = Struct.new(:Id, :Name)
|
@@ -32,7 +28,7 @@ module SfCli::Sf::Data
|
|
32
28
|
# When using Bulk API, you get the records when the query job completes within time limit.
|
33
29
|
# The method returns a tapple(an array), which changes its contents according to the job result.
|
34
30
|
#
|
35
|
-
#
|
31
|
+
# @example
|
36
32
|
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true # max wait 1 min to get result (default)
|
37
33
|
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, timeout: 5 # max wait 5 min to get result
|
38
34
|
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, timeout: 0 # returns immediately
|
@@ -40,9 +36,7 @@ module SfCli::Sf::Data
|
|
40
36
|
# rows = result if done # if job is completed, the result is an array of record
|
41
37
|
# job_id = result unless done # if job hasn't completed or it has aborted, the result is the job ID
|
42
38
|
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# 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.
|
39
|
+
# @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
|
46
40
|
#
|
47
41
|
def query(soql, target_org: nil, format: nil, bulk: false, timeout: nil, model_class: nil)
|
48
42
|
flags = {
|
@@ -62,17 +56,15 @@ module SfCli::Sf::Data
|
|
62
56
|
return_result(result, raw_output, bulk, model_class)
|
63
57
|
end
|
64
58
|
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
59
|
+
# Resume a bulk query job, which you previously started, and get records
|
60
|
+
# @param job_id [String] job ID you want to resume
|
61
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
62
|
+
# @param format [Symbol,String] get the command's raw output. human, csv, json can be available
|
63
|
+
# @param model_class [Class] the object model class
|
70
64
|
#
|
71
|
-
#
|
65
|
+
# @return [Array,[String,Array]] records or a tuple containing a flag and records
|
72
66
|
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
# ======
|
67
|
+
# @example
|
76
68
|
# # start a query job
|
77
69
|
# result1 = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, timeout: 0 # returns immediately
|
78
70
|
#
|
@@ -86,7 +78,8 @@ module SfCli::Sf::Data
|
|
86
78
|
#
|
87
79
|
# result2 # => if done is true, this is an array of record. Otherwise it should be the Job ID.
|
88
80
|
#
|
89
|
-
#
|
81
|
+
# @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
|
+
#
|
90
83
|
def query_resume(job_id:, target_org: nil, format: nil, model_class: nil)
|
91
84
|
flags = {
|
92
85
|
:"bulk-query-id" => job_id,
|
@@ -2,6 +2,7 @@ require_relative './helper_methods'
|
|
2
2
|
|
3
3
|
module SfCli::Sf::Data
|
4
4
|
module Query
|
5
|
+
# @private
|
5
6
|
class RegularResultAdjuster # :nodoc: all
|
6
7
|
include ::SfCli::Sf::Data::HelperMethods
|
7
8
|
|
@@ -20,6 +21,7 @@ module SfCli::Sf::Data
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
24
|
+
# @private
|
23
25
|
class BulkResultAdjuster # :nodoc: all
|
24
26
|
include ::SfCli::Sf::Data::HelperMethods
|
25
27
|
|
@@ -42,6 +44,7 @@ module SfCli::Sf::Data
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
47
|
+
# @private
|
45
48
|
class RawOutputResultAdjuster # :nodoc: all
|
46
49
|
attr_reader :result
|
47
50
|
|
@@ -49,12 +49,12 @@ module SfCli::Sf::Data
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# View the status of a bulk job.
|
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
|
52
54
|
#
|
53
|
-
#
|
55
|
+
# @return [JobInfo] job information
|
54
56
|
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
# ======
|
57
|
+
# @example
|
58
58
|
# # start a delete job
|
59
59
|
# jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv' # this returns immediately
|
60
60
|
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
@@ -69,9 +69,9 @@ module SfCli::Sf::Data
|
|
69
69
|
# - in_progress?
|
70
70
|
# - completed?
|
71
71
|
#
|
72
|
-
# To know job status more, take a look at {
|
72
|
+
# To know job status more, take a look at {https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/bulk_api_2_job_states.htm the bulk API developer guide}
|
73
73
|
#
|
74
|
-
#
|
74
|
+
# @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
75
|
#
|
76
76
|
def resume(job_id:, target_org: nil)
|
77
77
|
flags = {
|
@@ -1,16 +1,15 @@
|
|
1
1
|
module SfCli::Sf::Data
|
2
2
|
module Search
|
3
|
-
#
|
3
|
+
# Search objects using SOSL.
|
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.
|
4
7
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# *target_org* --- an alias of paticular org, or username can be used<br>
|
8
|
-
#
|
9
|
-
# *format* --- get the command's raw output. human, csv, json can be available. *NOTE*: if you choose csv, csv files are downloaded in current directory<br>
|
10
|
-
#
|
11
|
-
# ======
|
12
|
-
# # example (in irb):
|
8
|
+
# @return [Hash] the search result
|
9
|
+
# @note if you choose csv as format, csv files are downloaded in current directory
|
13
10
|
#
|
11
|
+
# @example
|
12
|
+
# (in irb):
|
14
13
|
# > sf.data.search "FIND {TIM OR YOUNG OR OIL} IN Name Fields"
|
15
14
|
# =>
|
16
15
|
# {"Lead"=>["00Q5j00000WgEuDEAV"],
|
@@ -24,7 +23,7 @@ module SfCli::Sf::Data
|
|
24
23
|
# "0065j00001XHJLJAA5"],
|
25
24
|
# "User"=>["0055j00000CcL2bAAF", "0055j00000CcL1YAAV"]}
|
26
25
|
#
|
27
|
-
#
|
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_search_unified command reference
|
28
27
|
#
|
29
28
|
def search(sosl, target_org: nil, format: nil)
|
30
29
|
flags = {
|