SFDO-API 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/lib/SFDO/API.rb +40 -22
- 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: c627cf05d223498b3612c2c9c152f183f422e8f1
|
4
|
+
data.tar.gz: ee2535a593751055205437893ee947279bc05171
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1cea12846844cd70926fd2c68e4270f30c0158273fc2e9d173db612c2f7fe8cbf54052ee0c9129a5de6d145dce7b3b7fe073dac437633abffd660007990c469
|
7
|
+
data.tar.gz: 7940ad8a382c3eebfa65c06a192ecd2bd5fef2974dd2cf8306d8d50b63b94c6eb0f94f7490af618a32962adb3b3dc1ba212467e4ddc9474c750948dded92692e
|
data/README.md
CHANGED
@@ -78,9 +78,9 @@ To delete all instances of an object
|
|
78
78
|
end
|
79
79
|
```
|
80
80
|
|
81
|
-
|
81
|
+
### Custom Objects
|
82
82
|
|
83
|
-
|
83
|
+
To create instances of custom objects that may have managed or unmanaged namespace use true_object_name.
|
84
84
|
|
85
85
|
```ruby
|
86
86
|
def create_gau_via_api(gau_name)
|
@@ -88,7 +88,10 @@ NOTE: in the future we will remove the need to use true_object_name() from calli
|
|
88
88
|
end
|
89
89
|
```
|
90
90
|
|
91
|
-
|
91
|
+
NOTE: in the future we will remove the need to use true_object_name() from calling code when creating and selecting custom objects,
|
92
|
+
but for now this is how it works.
|
93
|
+
|
94
|
+
When using delete_one_foo or delete_all_foo do not use any namespace value, SFDO-API does that for you
|
92
95
|
|
93
96
|
```ruby
|
94
97
|
def delete_gaus_via_api
|
@@ -100,7 +103,9 @@ puts gaus.inspect
|
|
100
103
|
end
|
101
104
|
```
|
102
105
|
|
103
|
-
|
106
|
+
### Using objects where local override changes required fields
|
107
|
+
|
108
|
+
Note that ISVs may override required fields on standard Salesforce objects, and these may be needed for SFDO-API to work properly
|
104
109
|
|
105
110
|
```ruby
|
106
111
|
# NPSP will automatically create certain fields on certain objects based on required input values for those records.
|
@@ -110,8 +115,11 @@ Note that ISVs may override required fields and these may be needed for SFDO-API
|
|
110
115
|
'Opportunity': ['ForecastCategory'] }
|
111
116
|
```
|
112
117
|
|
118
|
+
### TODO
|
113
119
|
|
120
|
+
Fields on namespaced object may be namespaced themselves. SFDO-API does not handle this case yet.
|
114
121
|
|
122
|
+
Custom fields on standard Salesforce objects may have namespaces. SFDO-API does not handle such fields yet.
|
115
123
|
|
116
124
|
|
117
125
|
## Development
|
@@ -123,4 +131,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
123
131
|
## Contributing
|
124
132
|
|
125
133
|
Bug reports and pull requests are welcome on GitHub at https://github.com/SalesforceFoundation/SFDO-API.
|
126
|
-
|
data/lib/SFDO/API.rb
CHANGED
@@ -36,65 +36,83 @@ module SfdoAPI
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def org_describe()
|
39
|
-
@
|
40
|
-
@api_client
|
39
|
+
if @org_description.nil? || !@org_description.respond_to?(:contains)
|
40
|
+
@org_description = api_client do
|
41
|
+
@api_client.describe
|
42
|
+
end
|
41
43
|
end
|
44
|
+
return @org_description
|
42
45
|
end
|
43
46
|
|
47
|
+
def prefix_to_name
|
48
|
+
if @prefix_to_name.nil? || !@prefix_to_name.respond_to?(:contains)
|
49
|
+
@prefix_to_name = {}
|
50
|
+
org_describe.each do |z|
|
51
|
+
@prefix_to_name.store(z.keyPrefix, z.name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
return @prefix_to_name
|
55
|
+
end
|
44
56
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
def true_object_name(handle) #either an ID or a string name
|
58
|
+
from_id = prefix_to_name[handle[0..2]]
|
59
|
+
from_name = obj_names_without_namespace[handle]
|
60
|
+
if !from_name.nil? || !from_id.nil?
|
61
|
+
return from_name if from_id.nil?
|
62
|
+
return from_id if from_name.nil?
|
63
|
+
end
|
64
|
+
return 'invalid'
|
50
65
|
end
|
51
66
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
return obj_name
|
67
|
+
def obj_names_without_namespace
|
68
|
+
if @obj_names_without_namespace.nil? || !@obj_names_without_namespace.respond_to?(:contains)
|
69
|
+
@obj_names_without_namespace = {}
|
70
|
+
org_describe.each do |z|
|
71
|
+
@obj_names_without_namespace.store(z.name.split("__",2).last, z.name)
|
58
72
|
end
|
73
|
+
end
|
74
|
+
@obj_names_without_namespace
|
59
75
|
end
|
60
76
|
|
61
77
|
def get_object_describe(object_name)
|
62
78
|
api_client do
|
63
|
-
org_describe
|
64
79
|
@description = @api_client.get("/services/data/v35.0/sobjects/#{object_name}/describe")
|
65
80
|
|
66
81
|
describeobject = Hashie::Mash.new(@description.body)
|
67
82
|
|
68
83
|
required = describeobject.fields.map do |x|
|
69
84
|
Hashie::Mash.new(
|
70
|
-
|
71
|
-
|
72
|
-
|
85
|
+
fieldName: x.name,
|
86
|
+
required: (!x.nillable && !x.defaultedOnCreate),
|
87
|
+
default: x.defaultValue)
|
73
88
|
end
|
74
89
|
required.select(&:required)
|
75
90
|
end
|
76
91
|
end
|
77
92
|
|
78
93
|
def delete(type, obj_id)
|
94
|
+
delete_by_id(obj_id)
|
95
|
+
end
|
96
|
+
|
97
|
+
def delete_by_id(obj_id)
|
79
98
|
api_client do
|
80
|
-
@api_client.destroy(true_object_name(
|
99
|
+
@api_client.destroy(true_object_name(obj_id), obj_id)
|
81
100
|
end
|
82
101
|
end
|
83
102
|
|
84
|
-
def delete_all(
|
103
|
+
def delete_all(id)
|
85
104
|
api_client do
|
86
|
-
obj_type = true_object_name(obj_type)
|
87
105
|
id.each(&:destroy)
|
88
106
|
end
|
89
107
|
end
|
90
108
|
|
91
|
-
|
92
109
|
def method_missing(method_called, *args, &block)
|
93
110
|
breakdown = method_called.to_s.split('_')
|
94
111
|
obj_type = breakdown.last.capitalize
|
112
|
+
|
95
113
|
case method_called.to_s
|
96
114
|
when /^delete_all_/
|
97
|
-
delete_all
|
115
|
+
delete_all *args
|
98
116
|
when /^delete_one/
|
99
117
|
delete obj_type, *args
|
100
118
|
when /^create_/
|
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.4
|
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-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|