SFDO-API 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +75 -2
- data/lib/SFDO/API.rb +22 -10
- data/lib/SFDO/API/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a889210734dd667c332c1a2b6cc9c2e614f7b96e
|
4
|
+
data.tar.gz: bc0172a50528c4c7aa20ec670d8336227868640f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fc1612e504e920b02d7a65a1b1456b1efccf524c3e63048791a1c04a06be25cc1a48ebc643242f114a204d286ddff53adf84a73bc0bc2307f4663bbc346e1c1
|
7
|
+
data.tar.gz: 5ef960b4d79bd44d37384955516412c85fd92d6d03e63d53a4c806ec6d2d48b4cd2e833ed250bca5f795ed4957bfd9ad0e6a1e271110526e26417ce658122a84
|
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# SFDO::API
|
2
2
|
|
3
|
-
SFDO-API is a convenient way to
|
4
|
-
the
|
3
|
+
SFDO-API is a convenient way to use the Salesforce API to manipulate objects in a target org. SFDO-API was intended orginally to
|
4
|
+
facilitate the sharing of common API calls across multiple source repositories, but the project is evolving to provide powerful
|
5
|
+
tools for handiling SF objects, like support for managed and unmanaged namespaces, multiple namespaces in an org, etc.
|
6
|
+
|
7
|
+
SFDO-API accepts commands from the calling script, and then lets the restforce Ruby gem deal directly with the Salesforce API.
|
5
8
|
|
6
9
|
## Installation
|
7
10
|
|
@@ -21,13 +24,18 @@ Or install it yourself as:
|
|
21
24
|
|
22
25
|
## Usage
|
23
26
|
|
27
|
+
### All examples below are calling code, not SFDO-API code
|
28
|
+
|
24
29
|
To create a simple Account and get the ID for that Account:
|
30
|
+
|
25
31
|
```ruby
|
26
32
|
def create_account_via_api(client_name)
|
27
33
|
@account_id = create 'Account', Name: client_name
|
28
34
|
end
|
29
35
|
```
|
36
|
+
|
30
37
|
You can also address the Restforce API client directly if you want, for example to issue a 'select' query:
|
38
|
+
|
31
39
|
```ruby
|
32
40
|
def create_contact_via_api(client_name, street = '', city = '', state = '', country = '', zip = '')
|
33
41
|
@contact_id = create 'Contact', LastName: client_name,
|
@@ -41,6 +49,71 @@ You can also address the Restforce API client directly if you want, for example
|
|
41
49
|
@account_id_for_contact = my_account_object.AccountId
|
42
50
|
end
|
43
51
|
```
|
52
|
+
|
53
|
+
To delete a single instance of an object for which you have the Id value
|
54
|
+
```ruby
|
55
|
+
def delete_account_via_api
|
56
|
+
delete_one_account(@account_id)
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
def delete_contacts_via_api
|
62
|
+
api_client do
|
63
|
+
@array_of_contacts.each do |contact_id|
|
64
|
+
delete_one_contact(contact_id)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
To delete all instances of an object
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
def delete_household_accounts
|
74
|
+
api_client do
|
75
|
+
hh_accs = @api_client.query("select Id from Account where Type = 'Household'")
|
76
|
+
delete_all_household_account(hh_accs)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
To create instances of custom objects that may have managed or unmanaged namespace use true_object_name.
|
82
|
+
|
83
|
+
NOTE: in the future we will remove the need to use true_object_name() from calling code, but for now this is how it works.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
def create_gau_via_api(gau_name)
|
87
|
+
@gau_id = create "#{true_object_name('General_Accounting_Unit__c')}", Name: gau_name
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
Note that when using delete_one_foo or delete_all_foo do not use any namespace value, SFDO-API does that for you
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
def delete_gaus_via_api
|
95
|
+
api_client do
|
96
|
+
gaus = @api_client.query("select Id from #{true_object_name('General_Accounting_Unit__c')}")
|
97
|
+
puts gaus.inspect
|
98
|
+
delete_all_General_Accounting_Unit__c(gaus)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
Note that ISVs may override required fields and these may be needed for SFDO-API to work properly
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
# NPSP will automatically create certain fields on certain objects based on required input values for those records.
|
107
|
+
# There is no way to know in advance from the API which these are, so we find them empirically and note them here
|
108
|
+
# before calling the create() method in SfdoAPI
|
109
|
+
@fields_acceptibly_nil = { 'Contact': ['Name'],
|
110
|
+
'Opportunity': ['ForecastCategory'] }
|
111
|
+
```
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
44
117
|
## Development
|
45
118
|
|
46
119
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/SFDO/API.rb
CHANGED
@@ -22,7 +22,6 @@ module SfdoAPI
|
|
22
22
|
|
23
23
|
def is_valid_obj_hash?(object_name, obj_hash, fields_acceptibly_nil)
|
24
24
|
required_fields = get_object_describe(object_name).map(&:fieldName)
|
25
|
-
# [name, id, required_field_1__c, etc]
|
26
25
|
valid = true
|
27
26
|
required_fields.each do |f|
|
28
27
|
|
@@ -36,15 +35,32 @@ module SfdoAPI
|
|
36
35
|
valid
|
37
36
|
end
|
38
37
|
|
39
|
-
def
|
40
|
-
|
41
|
-
@org_objects ||= api_client do
|
38
|
+
def org_describe()
|
39
|
+
@org_describe ||= api_client do
|
42
40
|
@api_client.describe
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
44
|
+
|
45
|
+
def npsp_managed_obj_names()
|
46
|
+
# GOAL: Delete NPSP objects whether managed or unmanaged
|
47
|
+
# Managed will start with np*__
|
48
|
+
# Unmanaged will have no prefix but end with __c
|
49
|
+
@npsp_managed_obj_names ||= @org_describe.select{|x| x.name =~ /^np.*__.*__c/i}.map{|y| y.name}
|
50
|
+
end
|
51
|
+
|
52
|
+
def true_object_name(obj_name)
|
53
|
+
potentials = npsp_managed_obj_names().select{|x| x =~ /#{obj_name}/i}
|
54
|
+
if potentials.size > 0
|
55
|
+
return potentials.first #.split("__.").first + "__."
|
56
|
+
elsif org_describe().select{|x| x.name =~ /^#{obj_name}/i}.map{|y| y.name}.size > 0
|
57
|
+
return obj_name
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
46
61
|
def get_object_describe(object_name)
|
47
62
|
api_client do
|
63
|
+
org_describe
|
48
64
|
@description = @api_client.get("/services/data/v35.0/sobjects/#{object_name}/describe")
|
49
65
|
|
50
66
|
describeobject = Hashie::Mash.new(@description.body)
|
@@ -61,21 +77,17 @@ module SfdoAPI
|
|
61
77
|
|
62
78
|
def delete(type, obj_id)
|
63
79
|
api_client do
|
64
|
-
@api_client.destroy(type, obj_id)
|
80
|
+
@api_client.destroy(true_object_name(type), obj_id)
|
65
81
|
end
|
66
82
|
end
|
67
83
|
|
68
84
|
def delete_all(obj_type, id)
|
69
85
|
api_client do
|
70
|
-
|
71
|
-
#@api_client.destroy(obj_type, id)
|
86
|
+
obj_type = true_object_name(obj_type)
|
72
87
|
id.each(&:destroy)
|
73
88
|
end
|
74
89
|
end
|
75
90
|
|
76
|
-
# Given that the developer calls 'delete_contact(id)'
|
77
|
-
# When 'contact' is a valid object
|
78
|
-
# Then this method_missing method, will translate 'delete_contact' into "generic_delete('contact', id)"
|
79
91
|
|
80
92
|
def method_missing(method_called, *args, &block)
|
81
93
|
breakdown = method_called.to_s.split('_')
|
data/lib/SFDO/API/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SFDO-API
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris McMahon
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|