Class: Salesforce::SfUtility
- Inherits:
-
Object
- Object
- Salesforce::SfUtility
- Defined in:
- lib/salesforce/sf_utility.rb
Overview
This is the utility class for managing Salesforce objects.
Constant Summary collapse
- SFObjectPrefix =
SalesObject KeyPrefix 3 digits code => Object Type locator. ID Prefix Entity Type (Following has associated ChatterFeed objectFeed
001 Account 02i Asset 500 Case 701 Campaign 003 Contact 800 Contract 00G Group 00Q Lead 006 Opportunity 00D Organization 01t Product2 501 Solution 00T Task 005 User (Special Feed class, with no associated SF object) 0D5 NewsFeed is special, It does not have SF Object (Other Chatter Object without Feed) 00V Campaign Member 00e Profile 00N Custom Field Definition
(FeedItem vs. FeedPost)
0D5 FeedItem (post by everyone) 0F7 FeedPost (post made by this user)
See: eng.genius.com/blog/2009/05/17/salesforcecom-api-gotchas-2/
{ '001' => 'Account', '02i' => 'Asset', '500' => 'Case', '701' => 'Campaign', '003' => 'Contact', '800' => 'Contract', '00G' => 'Group', '00Q' => 'Lead', '006' => 'Opportunity', '00D' => 'Organization', '01t' => 'Product2', '501' => 'Solution', '00T' => 'Task', '005' => 'User', # below are other Salesforce object without chatter {object}Feed '00V' => 'Campaign Member', '00E' => 'Profile', '00N' => 'Custom_Field_Definition', #distinction between FeedItem and FeedPost '0D5' => 'FeedItem', '0F7' => 'FeedPost', 'xxx' => 'Unknown', '' => 'Unknown' }
Class Method Summary collapse
-
.determine_sf_object_type(id) ⇒ Object
Determine the Salesforce object type based on 3-digits OID prefix.
-
.salesforce_object_create(otype) ⇒ Object
Create a blank Salesforce Object based on the object type.
-
.salesforce_object_find_all(otype, query_conditions = nil) ⇒ Object
Finders the appropriate Salesforce Object based on the Object Type returning nil means that the oid is not supported by this method, e.g.
-
.salesforce_object_find_by_id(oid) ⇒ Object
Finders the appropriate Salesforce Object based on Object.
-
.salesforce_object_find_by_type_and_conditions(otype, query_conditions) ⇒ Object
Finders the appropriate Salesforce Object based on Object Type and description nil means that the oid is not supported by this method, e.g.
Class Method Details
.determine_sf_object_type(id) ⇒ Object
Determine the Salesforce object type based on 3-digits OID prefix.
80 81 82 83 84 85 86 87 |
# File 'lib/salesforce/sf_utility.rb', line 80 def self.determine_sf_object_type(id) String oid = id[0,3] if SFObjectPrefix.has_key?(oid) return SFObjectPrefix.value(oid) else return 'Unknown' end end |
.salesforce_object_create(otype) ⇒ Object
Create a blank Salesforce Object based on the object type.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/salesforce/sf_utility.rb', line 176 def self.salesforce_object_create(otype) case otype when 'Account' sf_object = Salesforce::Account.new() when 'Asset' sf_object = Salesforce::Asset.new() when 'Case' sf_object = Salesforce::Case.new() when 'Campaign' sf_object = Salesforce::Campaign.new() when 'Contact' sf_object = Salesforce::Contact.new() when 'Contract' sf_object = Salesforce::Contract.new() when 'Group' sf_object = Salesforce::Group.new() when 'Lead' sf_object = Salesforce::Lead.new() when 'Opportunity' sf_object = Salesforce::Opportunity.new() when 'Organization' sf_object = Salesforce::Organization.new() when 'Product2' sf_object = Salesforce::Product2.new() when 'Solution' sf_object = Salesforce::Solution.new() when 'User' sf_object = Salesforce::User.new() else sf_object = nil end return sf_object end |
.salesforce_object_find_all(otype, query_conditions = nil) ⇒ Object
Finders the appropriate Salesforce Object based on the Object Type returning nil means that the oid is not supported by this method, e.g. not suitable.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/salesforce/sf_utility.rb', line 118 def self.salesforce_object_find_all(otype, query_conditions = nil) case otype when 'Account' sf_object = Salesforce::Account.find(:all, :conditions => query_conditions) when 'AccountFeed' sf_object = Salesforce::AccountFeed.find(:all, :conditions => query_conditions) when 'Asset' sf_object = Salesforce::Asset.find(:all, :conditions => query_conditions) when 'AssetFeed' sf_object = Salesforce::AssetFeed.find(:all, :conditions => query_conditions) when 'Case' sf_object = Salesforce::Case.find(:all, :conditions => query_conditions) when 'CaseFeed' sf_object = Salesforce::CaseFeed.find(:all, :conditions => query_conditions) when 'Campaign' sf_object = Salesforce::Campaign.find(:all, :conditions => query_conditions) when 'CampaignFeed' sf_object = Salesforce::CampaignFeed.find(:all, :conditions => query_conditions) when 'Contact' sf_object = Salesforce::Contact.find(:all, :conditions => query_conditions) when 'ContactFeed' sf_object = Salesforce::ContactFeed.find(:all, :conditions => query_conditions) when 'Contract' sf_object = Salesforce::Contract.find(:all, :conditions => query_conditions) when 'ContractFeed' sf_object = Salesforce::ContractFeed.find(:all, :conditions => query_conditions) when 'Group' sf_object = Salesforce::Group.find(:all, :conditions => query_conditions) when 'Lead' sf_object = Salesforce::Lead.find(:all, :conditions => query_conditions) when 'LeadFeed' sf_object = Salesforce::LeadFeed.find(:all, :conditions => query_conditions) when 'Opportunity' sf_object = Salesforce::Opportunity.find(:all, :conditions => query_conditions) when 'OpportunityFeed' sf_object = Salesforce::OpportunityFeed.find(:all, :conditions => query_conditions) when 'Organization' sf_object = Salesforce::Organization.find(:all, :conditions => query_conditions) when 'Product2' sf_object = Salesforce::Product2.find(:all, :conditions => query_conditions) when 'Product2Feed' sf_object = Salesforce::Product2Feed.find(:all, :conditions => query_conditions) when 'Solution' sf_object = Salesforce::Solution.find(:all, :conditions => query_conditions) when 'SolutionFeed' sf_object = Salesforce::SolutionFeed.find(:all, :conditions => query_conditions) when 'User' sf_object = Salesforce::User.find(:all, :conditions => query_conditions) when 'UserFeed' sf_object = Salesforce::UserFeed.find(:all, :conditions => query_conditions) else sf_object = nil end return sf_object end |
.salesforce_object_find_by_id(oid) ⇒ Object
Finders the appropriate Salesforce Object based on Object. No more guess work. nil means that the oid is not supported by this method, e.g. not suitable.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/salesforce/sf_utility.rb', line 92 def self.salesforce_object_find_by_id (oid) query_conditions = Hash.new query_conditions[:id] = oid otype = determine_sf_object_type(oid) if otype != 'Unknown' sf_object = salesforce_object_find_all(otype, query_conditions).first else sf_object = nil end return sf_object end |
.salesforce_object_find_by_type_and_conditions(otype, query_conditions) ⇒ Object
Finders the appropriate Salesforce Object based on Object Type and description nil means that the oid is not supported by this method, e.g. not suitable.
108 109 110 111 112 113 114 |
# File 'lib/salesforce/sf_utility.rb', line 108 def self.salesforce_object_find_by_type_and_conditions (otype, query_conditions) # for example #Salesforce::Group.find(:all, :conditions => ["email like :search", {:search => '%.com'}]) sf_objects = salesforce_object_find_all(otype, query_conditions) return sf_objects end |