Class: Readiness::Salesforce::Accounts

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/salesforce/accounts.rb

Overview

Defines the class Accounts within the module Readiness::Salesforce.

Author:

  • Jason Colyer

Since:

  • 1.0.12

Class Method Summary collapse

Methods inherited from Client

auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries

Class Method Details

.account_arr(account) ⇒ Object

Returns an accounts ARR

Author:

  • Jason Colyer

Since:

  • 1.0.26



360
361
362
363
364
365
366
367
368
369
370
# File 'lib/support_readiness/salesforce/accounts.rb', line 360

def self.()
  total = 0
  return total if .Zuora__R00N40000001lGjTEAU__r.nil?

  .Zuora__R00N40000001lGjTEAU__r.each do |subscription|
    next if Date.parse(subscription.Zuora__EffectiveEndDate__c) < Date.today

    total += subscription.Zuora__TotalContractValue__c.to_i
  end
  total
end

.account_expiration(account) ⇒ Object

Returns an accounts latest expiration

Author:

  • Jason Colyer

Since:

  • 1.0.26



335
336
337
338
339
# File 'lib/support_readiness/salesforce/accounts.rb', line 335

def self.()
  return '1970-01-01' if .Zuora__R00N40000001lGjTEAU__r.nil?

  .Zuora__R00N40000001lGjTEAU__r.map(&:Zuora__EffectiveEndDate__c).max
end

.account_health_score(account) ⇒ Object

Returns an accounts health score

Author:

  • Jason Colyer

Since:

  • 1.0.26



423
424
425
426
427
# File 'lib/support_readiness/salesforce/accounts.rb', line 423

def self.()
  .GS_Health_Score_Color__c.downcase
rescue NoMethodError
  nil
end

.account_is_partner_customer?(account, type) ⇒ Boolean

Returns if an account is a partner customer or not

Returns:

  • (Boolean)

Author:

  • Jason Colyer

Since:

  • 1.0.26



434
435
436
437
438
439
440
441
# File 'lib/support_readiness/salesforce/accounts.rb', line 434

def self.(, type)
  return false if .Latest_Sold_To_Contact__r.nil?
  return false if type != 'customer'
  return false if .Account_ID_18__c == '0016100000g04oWAAQ'
  return true if .Latest_Sold_To_Contact__r.Email == 'ecopo@us.ibm.com'

  false
end

.account_market_segment(account) ⇒ Object

Returns an accounts market segment

Author:

  • Jason Colyer

Since:

  • 1.0.26



377
378
379
380
381
# File 'lib/support_readiness/salesforce/accounts.rb', line 377

def self.()
  .Ultimate_Parent_Sales_Segment_Employees__c.downcase
rescue NoMethodError
  'unknown'
end

.account_region(account) ⇒ Object

Returns an accounts region

Author:

  • Jason Colyer

Since:

  • 1.0.26



405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/support_readiness/salesforce/accounts.rb', line 405

def self.()
  return 'org_region_amer' if .Account_Demographics_Geo__c == 'AMER'
  return 'org_region_apac' if .Account_Demographics_Geo__c == 'APJ'
  return 'org_region_emea' if .Account_Demographics_Geo__c == 'EMEA'
  if .Account_Demographics_Geo__c == 'SMB'
    return 'org_region_amer' if .Account_Demographics_Region__c == 'AMER'
    return 'org_region_apac' if .Account_Demographics_Region__c == 'APJ'
    return 'org_region_emea' if .Account_Demographics_Region__c == 'EMEA'
  end

  nil
end

.account_seats(account) ⇒ Object

Returns an accounts seat count

Author:

  • Jason Colyer

Since:

  • 1.0.26



388
389
390
391
392
393
394
395
396
397
398
# File 'lib/support_readiness/salesforce/accounts.rb', line 388

def self.()
  total = 0
  return total if .Zuora__R00N40000001lGjTEAU__r.nil?

  .Zuora__R00N40000001lGjTEAU__r.each do |subscription|
    next if Date.parse(subscription.Zuora__EffectiveEndDate__c) < Date.today

    total += subscription.Zuora__Quantity__c.to_i
  end
  total
end

.account_sold_to(account) ⇒ Object

Returns an accounts sold to

Author:

  • Jason Colyer

Since:

  • 1.0.26



494
495
496
497
498
499
500
501
502
503
# File 'lib/support_readiness/salesforce/accounts.rb', line 494

def self.()
  return nil if .Zuora__R00N40000001kyLcEAI__r.nil?
  return nil if .Zuora__R00N40000001kyLcEAI__r.first.Zuora__SoldToWorkEmail__c == 'ecopo@us.ibm.com'

  {
    "salesforce_id" => .Account_ID_18__c,
    "email" => .Zuora__R00N40000001kyLcEAI__r.first.Zuora__SoldToWorkEmail__c,
    "name" => .Zuora__R00N40000001kyLcEAI__r.first.Name
  }
end

.account_subscriptions(account, type) ⇒ Object

Return an Array of subscriptions used for the account sync

Author:

  • Jason Colyer

Since:

  • 1.0.26



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/support_readiness/salesforce/accounts.rb', line 243

def self.(, type)
  subs = []
  return subs if .Zuora__R00N40000001lGjTEAU__r.nil?

  grouped = .Zuora__R00N40000001lGjTEAU__r.group_by { |z| z.Zuora__Subscription__c }
  grouped.each_value.each do |charges|
    valid_charges = charges.select { |c| c.Subscription_Status__c == 'Active' && Date.parse(c.Zuora__EffectiveEndDate__c) >= Date.today }
    next if valid_charges.count.zero?

    charge_names = valid_charges.map { |x| x.Name }
    sub_types = if type == 'global'
                  process_global_subs(, charge_names)
                else
                  process_usgov_subs(, charge_names)
                end
    subs += sub_types
  end
  subs.compact.uniq
end

.account_type(account, expiration) ⇒ Object

Returns an accounts type

Author:

  • Jason Colyer

Since:

  • 1.0.26



346
347
348
349
350
351
352
353
# File 'lib/support_readiness/salesforce/accounts.rb', line 346

def self.(, expiration)
  return 'alliance_partner' if %w[0014M00001sDiGEQA0].include?(.Account_ID_18__c)
  return 'open_partner' if .Type == 'Partner' && .Partner_Track__c == 'Open'
  return 'select_partner' if .Type == 'Partner' && .Partner_Track__c == 'Select'
  return 'former_customer' if Date.parse(expiration) < Date.today

  'customer'
end

.global_accounts(client) ⇒ Array

Return an Array of accounts from Salesforce for Global support

Examples:

config = Readiness::Salesforce::Configuration.new
config.api_version = '58.0'
config.client_id = ENV.fetch('SFDC_CLIENTID')
config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
config.password = ENV.fetch('SFDC_PASSWORD')
config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
config.username = ENV.fetch('SFDC_USERNAME')
client = Readiness::Salesforce::Client.new(config)
accounts = Readiness::Salesforce::Accounts.global_accounts(client)
pp accounts.count
# => 51234

Parameters:

  • client (Object)

    An instance of Client

Returns:

  • (Array)

Author:

  • Jason Colyer

Since:

  • 1.0.26



90
91
92
93
94
# File 'lib/support_readiness/salesforce/accounts.rb', line 90

def self.global_accounts(client)
  query = Queries.new(global_sync_query_string)
  results = Queries.run!(client, query)
  results.map { |r| global_sync_object(r) }.compact
end

.global_highest_support_level(subscriptions) ⇒ Object

Returns an accounts highest support level for the Global support sync

Author:

  • Jason Colyer

Since:

  • 1.0.26



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/support_readiness/salesforce/accounts.rb', line 448

def self.global_highest_support_level(subscriptions)
  return 'ultimate' if subscriptions.include? 'sub_sm_ultimate'
  return 'gold' if subscriptions.include? 'sub_dotcom_ultimate'
  return 'ultimate' if subscriptions.include? 'sub_gitlab_dedicated'
  return 'premium' if subscriptions.include? 'sub_sm_premium'
  return 'silver' if subscriptions.include? 'sub_dotcom_premium'
  return 'starter' if subscriptions.include? 'sub_sm_starter'
  return 'consumption_only' if subscriptions.include? 'sub_consumption_ai'
  return 'consumption_only' if subscriptions.include? 'sub_consumption_cicd_minutes'
  return 'consumption_only' if subscriptions.include? 'sub_consumption_eap'
  return 'consumption_only' if subscriptions.include? 'sub_consumption_storage'
  return 'custom' if subscriptions.include? 'sub_usgov_12x5'
  return 'custom' if subscriptions.include? 'sub_usgov_24x7'
  return 'custom' if subscriptions.include? 'sub_ss_ase'
  return 'custom' if subscriptions.include? 'sub_ss_growth'
  return 'custom' if subscriptions.include? 'sub_ss_enterprise'
  return 'community' if subscriptions.include? 'sub_edu'
  return 'community' if subscriptions.include? 'sub_oss'
  return 'community' if subscriptions.include? 'sub_community_other'
  return 'other' if subscriptions.include? 'sub_proserv'
  return 'sub_other' if subscriptions.include? 'sub_proserv'

  'expired'
end

.global_sync_object(account) ⇒ Object

Return a Hash used for the account sync for Global support

Author:

  • Jason Colyer

Since:

  • 1.0.26



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
174
175
176
177
178
179
180
181
182
# File 'lib/support_readiness/salesforce/accounts.rb', line 126

def self.global_sync_object()
  subscriptions = (, 'global')
  if subscriptions.count.zero?
    usgov_subs = (, 'usgov')
    # Return nil if it has no global subs but has us gov subs
    return nil if usgov_subs.count.nonzero?
  end
  expiration = ()
  type = (, expiration)
  partner = %w[alliance_partner open_partner select_partner].include?(type)
  {
    "name" => "#{Digest::SHA1.hexdigest(.Account_ID_18__c)[0..7]} #{.Name}",
    "salesforce_id" => .Account_ID_18__c,
    "sfdc_short_id" => .Account_ID_18__c[..-4],
    "support_level" => (partner ? 'ultimate' : global_highest_support_level(subscriptions)),
    "aar" => ().to_f,
    "sales_segmentation" => (),
    "account_owner" => .Account_Owner_Calc__c,
    "type" => type,
    "technical_account_manager" => .Technical_Account_Manager_Name__c,
    "solutions_architect" => .Solutions_Architect_Lookup__r&.Name,
    "seats_decimal" => ().to_f,
    "org_region" => (),
    "health_score" => (),
    "expiration_date" => expiration,
    "restricted_account" => (.Restricted_Account__c == 'Restricted Party'),
    "greatly_expired" => (partner ? false : Date.parse(expiration) <= Date.today.years_ago(3)),
    "sub_consumption_ai" => subscriptions.include?('sub_consumption_ai'),
    "sub_consumption_cicd_minutes" => subscriptions.include?('sub_consumption_cicd_minutes'),
    "sub_consumption_duo_enterprise" => subscriptions.include?('sub_consumption_duo_enterprise'),
    "sub_consumption_duo_premium" => subscriptions.include?('sub_consumption_duo_premium'),
    "sub_consumption_duo_amazon_q" => subscriptions.include?('sub_consumption_duo_amazon_q'),
    "sub_consumption_eap" => subscriptions.include?('sub_consumption_eap'),
    "sub_consumption_storage" => subscriptions.include?('sub_consumption_storage'),
    "sub_proserv" => subscriptions.include?('sub_proserv'),
    "sub_dotcom_premium" => subscriptions.include?('sub_dotcom_premium'),
    "sub_dotcom_ultimate" => subscriptions.include?('sub_dotcom_ultimate'),
    "sub_sm_starter" => subscriptions.include?('sub_sm_starter'),
    "sub_sm_premium" => subscriptions.include?('sub_sm_premium'),
    "sub_sm_ultimate" => subscriptions.include?('sub_sm_ultimate'),
    "sub_usgov_12x5" => subscriptions.include?('sub_usgov_12x5'),
    "sub_usgov_24x7" => subscriptions.include?('sub_usgov_24x7'),
    "sub_gitlab_dedicated" => subscriptions.include?('sub_gitlab_dedicated'),
    "sub_edu" => subscriptions.include?('sub_edu'),
    "sub_oss" => subscriptions.include?('sub_oss'),
    "sub_community_other" => subscriptions.include?('sub_community_other'),
    "sub_ss_ase" => subscriptions.include?('sub_ss_ase'),
    'sub_ss_growth' => subscriptions.include?('sub_ss_growth'),
    'sub_ss_enterprise' => subscriptions.include?('sub_ss_enterprise'),
    "sub_other" => subscriptions.include?('sub_other'),
    "partner_customer" => (, type),
    "not_in_sfdc" => false,
    "support_hold" => .Support_Hold__c,
    "sold_to" => (),
    "org_in_escalated_state" => (.Account_Risk_Level__c == 'At Risk - Escalated')
  }
end

.global_sync_query_stringString

Provides the String needed to make a specific type of SOQL query

Parameters:

  • aid (String)

    The ID of the Account to check

Returns:

  • (String)

Author:

  • Jason Colyer

Since:

  • 1.0.26



585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
# File 'lib/support_readiness/salesforce/accounts.rb', line 585

def self.global_sync_query_string
  <<~QUERY
    SELECT
      Account_ID_18__c,
      Name,
      Type,
      Ultimate_Parent_Sales_Segment_Employees__c,
      Account_Owner_Calc__c,
      Technical_Account_Manager_Name__c,
      GS_Health_Score_Color__c,
      Restricted_Account__c,
      Solutions_Architect_Lookup__r.Name,
      Account_Demographics_Geo__c,
      Account_Demographics_Region__c,
      Latest_Sold_To_Contact__r.Email,
      Latest_Sold_To_Contact__r.Name,
      Partner_Track__c,
      Partners_Partner_Type__c,
      Support_Hold__c,
      Account_Risk_Level__c,
      Support_Instance__c,
      (
        SELECT
          Id,
          Name,
          Zuora__ProductName__c,
          Zuora__EffectiveEndDate__c,
          Zuora__Quantity__c,
          Zuora__TotalContractValue__c,
          Subscription_Status__c,
          Zuora__Subscription__c
        FROM Zuora__R00N40000001lGjTEAU__r
        WHERE
          Zuora__EffectiveEndDate__c != NULL
      ),
      (
        SELECT
          Name,
          Zuora__SoldToWorkEmail__c
        FROM Zuora__R00N40000001kyLcEAI__r
        WHERE
          IsDeleted = false
        ORDER BY CreatedDate ASC
        LIMIT 1
      )
    FROM Account
    WHERE
      Type != 'Prospect' AND
      (
        Type IN ('Customer', 'Former Customer') OR
        (
          Type = 'Partner' AND
          Partners_Partner_Status__c IN ('Authorized', 'Former') AND
          Partners_Partner_Type__c IN ('Alliance', 'Channel') AND
          Partner_Track__c IN ('Open', 'Select', 'Technology')
        )
      )
  QUERY
end

.process_global_subs(account, charge_names) ⇒ Object

Since:

  • 1.0.12



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/support_readiness/salesforce/accounts.rb', line 263

def self.process_global_subs(, charge_names)
  sub_types = []
  sub_types.push('sub_consumption_cicd_minutes') if charge_names.any? { |x| SubscriptionDefinitions.consumption_cicd_minutes.include?(x) }
  sub_types.push('sub_consumption_storage') if charge_names.any? { |x| SubscriptionDefinitions.consumption_storage.include?(x) }
  sub_types.push('sub_dotcom_premium') if charge_names.any? { |x| SubscriptionDefinitions.dotcom_premium.include?(x) }
  sub_types.push('sub_dotcom_ultimate') if charge_names.any? { |x| SubscriptionDefinitions.dotcom_ultimate.include?(x) }
  sub_types.push('sub_gitlab_dedicated') if charge_names.any? { |x| SubscriptionDefinitions.gitlab_dedicated.include?(x) }
  sub_types.push('sub_edu') if charge_names.any? { |x| SubscriptionDefinitions.edu.include?(x) }
  sub_types.push('sub_oss') if charge_names.any? { |x| SubscriptionDefinitions.oss.include?(x) }
  sub_types.push('sub_community_other') if charge_names.any? { |x| SubscriptionDefinitions.community_other.include?(x) }
  sub_types.push('sub_ss_growth') if charge_names.any? { |x| SubscriptionDefinitions.ss_success_advanced.include?(x) }
  sub_types.push('sub_ss_enterprise') if charge_names.any? { |x| SubscriptionDefinitions.ss_success_signature.include?(x) }
  sub_types.push('sub_ss_ase') if charge_names.any? { |x| SubscriptionDefinitions.ss_success_signature.include?(x) }
  sub_types.push('sub_ss_enterprise') if .Account_ID_18__c == '00161000010fYlBAAU' && charge_names.select { |x| x =~ /Success\ Plan\ Services/ }
  sub_types.push('sub_ss_enterprise') if .Account_ID_18__c == '001PL00000S7nT3YAJ' && charge_names.select { |x| x =~ /Success\ Plan\ Services/ }
  sub_types.push('sub_ss_enterprise') if .Account_ID_18__c == '0016100000K8R8fAAF' && charge_names.select { |x| x =~ /Success\ Plan\ Services/ }
  sub_types.push('sub_ss_enterprise') if .Account_ID_18__c == '0014M00001lcEpNQAU' && charge_names.select { |x| x =~ /Success\ Plan\ Services/ }
  if .Account_ID_18__c == '0016100000SEhkLAAT'
    sub_types.push('sub_ss_enterprise') if (Date.parse('2025-04-29')..Date.parse('2026-04-28')).cover?(Date.today)
    sub_types.push('sub_ss_ase') if (Date.parse('2025-04-29')..Date.parse('2026-04-28')).cover?(Date.today)
    sub_types.push('sub_ss_growth') if (Date.parse('2026-04-29')..Date.parse('2027-04-28')).cover?(Date.today)
  end
  if .Support_Instance__c != 'federal-support'
    has_12x5 = charge_names.any? { |x| SubscriptionDefinitions.usgov_12x5.include?(x) }
    has_24x7 = charge_names.any? { |x| SubscriptionDefinitions.usgov_24x7.include?(x) }
    unless has_12x5 || has_24x7
      sub_types.push('sub_sm_premium') if charge_names.any? { |x| SubscriptionDefinitions.sm_premium.include?(x) }
      sub_types.push('sub_sm_ultimate') if charge_names.any? { |x| SubscriptionDefinitions.sm_ultimate.include?(x) }
      sub_types.push('sub_consumption_duo_premium') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_premium.include?(x) }
      sub_types.push('sub_consumption_duo_enterprise') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_enterprise.include?(x) }
      sub_types.push('sub_consumption_duo_amazon_q') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_amazon_q.include?(x) }
      sub_types.push('sub_ss_ase') if charge_names.any? { |x| SubscriptionDefinitions.ss_ase.include?(x) }
      sub_types.push('sub_consumption_eap') if charge_names.any? { |x| SubscriptionDefinitions.consumption_eap.include?(x) }
    end
  end
  sub_types
end

.process_usgov_subs(account, charge_names) ⇒ Object

Since:

  • 1.0.12



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/support_readiness/salesforce/accounts.rb', line 301

def self.process_usgov_subs(, charge_names)
  sub_types = []
  sub_types.push('sub_usgov_12x5') if charge_names.any? { |x| SubscriptionDefinitions.usgov_12x5.include?(x) }
  sub_types.push('sub_usgov_24x7') if charge_names.any? { |x| SubscriptionDefinitions.usgov_24x7.include?(x) }
  sub_types.push('sub_usgov_24x7') if charge_names.any? { |x| SubscriptionDefinitions.fedramp.include?(x) }
  sub_types.push('sub_gitlab_dedicated') if charge_names.any? { |x| SubscriptionDefinitions.fedramp.include?(x) }
  if .Support_Instance__c == 'federal-support'
    sub_types.push('sub_sm_premium') if charge_names.any? { |x| SubscriptionDefinitions.sm_premium.include?(x) }
    sub_types.push('sub_sm_ultimate') if charge_names.any? { |x| SubscriptionDefinitions.sm_ultimate.include?(x) }
    sub_types.push('sub_consumption_duo_premium') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_premium.include?(x) }
    sub_types.push('sub_consumption_duo_enterprise') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_enterprise.include?(x) }
    sub_types.push('sub_consumption_duo_amazon_q') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_amazon_q.include?(x) }
    sub_types.push('sub_ss_ase') if charge_names.any? { |x| SubscriptionDefinitions.ss_ase.include?(x) }
    sub_types.push('sub_consumption_eap') if charge_names.any? { |x| SubscriptionDefinitions.consumption_eap.include?(x) }
  end
  has_12x5 = charge_names.any? { |x| SubscriptionDefinitions.usgov_12x5.include?(x) }
  has_24x7 = charge_names.any? { |x| SubscriptionDefinitions.usgov_24x7.include?(x) }
  if has_12x5 || has_24x7
    sub_types.push('sub_sm_premium') if charge_names.any? { |x| SubscriptionDefinitions.sm_premium.include?(x) }
    sub_types.push('sub_sm_ultimate') if charge_names.any? { |x| SubscriptionDefinitions.sm_ultimate.include?(x) }
    sub_types.push('sub_consumption_duo_premium') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_premium.include?(x) }
    sub_types.push('sub_consumption_duo_enterprise') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_enterprise.include?(x) }
    sub_types.push('sub_consumption_duo_amazon_q') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_amazon_q.include?(x) }
    sub_types.push('sub_ss_ase') if charge_names.any? { |x| SubscriptionDefinitions.ss_ase.include?(x) }
    sub_types.push('sub_consumption_eap') if charge_names.any? { |x| SubscriptionDefinitions.consumption_eap.include?(x) }
  end
  sub_types
end

.update!(client, aid, **args) ⇒ Boolean

Updates an Account in Salesforce. This will exit on error

Examples:

config = Readiness::Salesforce::Configuration.new
config.api_version = '58.0'
config.client_id = ENV.fetch('SFDC_CLIENTID')
config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
config.password = ENV.fetch('SFDC_PASSWORD')
config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
config.username = ENV.fetch('SFDC_USERNAME')
client = Readiness::Salesforce::Client.new(config)
result = Readiness::Salesforce::Client.update!(client, '0016100000AYvx9', Support_Hold__c: false, Support_Instance__c: 'federal-support')
pp result
# => true
result = Readiness::Salesforce::Client.update!(client, '0016100000AYvx9', Restricted_Account__c: nil)
pp result
# => true

Parameters:

  • client (Object)

    An instance of Client

  • aid (String)

    The ID of the Account to update

  • args (Various)

    This allows for multiple ‘key: value’ entries when calling the function

Returns:

  • (Boolean)

Author:

  • Jason Colyer

Since:

  • 1.0.12



37
38
39
40
# File 'lib/support_readiness/salesforce/accounts.rb', line 37

def self.update!(client, aid, **args)
  client.connection.update!('Account', Id: aid, **args)
  true
end

.us_gov_check_query_string(aid) ⇒ String

Provides the String needed to make a specific type of SOQL query

Parameters:

  • aid (String)

    The ID of the Account to check

Returns:

  • (String)

Author:

  • Jason Colyer

Since:

  • 1.0.12



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/support_readiness/salesforce/accounts.rb', line 546

def self.us_gov_check_query_string(aid)
  <<~STRING
    SELECT
      Zuora__Account__r.Account_ID_18__c,
      Zuora__Account__r.Support_Hold__c,
      Zuora__Account__r.Restricted_Account__c,
      Zuora__Subscription__c
    FROM Zuora__SubscriptionProductCharge__c
    WHERE
      Zuora__Account__r.Account_ID_18__c = '#{aid}' AND
      Subscription_Status__c = 'Active' AND
      Zuora__EffectiveEndDate__c >= #{(Date.today - 91.days).iso8601} AND
      (
        Name IN (
          '12x5 US Citizen Support - 1 Year',
          '12x5 US Citizen Support - 2 Year',
          '12x5 US Citizen Support - 3 Year',
          '12x5 US Citizen Support - Monthly',
          '24x7 US Citizen Support - 1 Year',
          '24x7 US Citizen Support - 2 Year',
          '24x7 US Citizen Support - 3 Year',
          '24x7 US Citizen Support - Monthly',
          'GitLab Dedicated for US Public Sector - Ultimate - 1 Year',
          'GitLab Dedicated for US Public Sector - Ultimate - 2 Year',
          'GitLab Dedicated for US Public Sector - Ultimate - 3 Year',
          'GitLab Dedicated for US Public Sector - Ultimate - Monthly'
        ) OR
        Zuora__Account__r.Support_Instance__c = 'federal-support'
      )
  STRING
end

.us_gov_enabled?(client, aid) ⇒ Boolean

Determines if a SFDC Account is US Government enabled.

Examples:

config = Readiness::Salesforce::Configuration.new
config.api_version = '58.0'
config.client_id = ENV.fetch('SFDC_CLIENTID')
config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
config.password = ENV.fetch('SFDC_PASSWORD')
config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
config.username = ENV.fetch('SFDC_USERNAME')
client = Readiness::Salesforce::Client.new(config)
pp Readiness::Salesforce::Client.us_gover_enabled?(client, '0016100000AYvx9')
# => false

Parameters:

  • client (Object)

    An instance of Client

  • aid (String)

    The ID of the Account to check

Returns:

  • (Boolean)

Author:

  • Jason Colyer

Since:

  • 1.0.12



61
62
63
64
65
66
67
68
69
# File 'lib/support_readiness/salesforce/accounts.rb', line 61

def self.us_gov_enabled?(client, aid)
  query = Queries.new(us_gov_check_query_string(aid))
  results = Queries.run!(client, query)
  return false if results.count.zero?
  return false if results.first.Zuora__Account__r.Support_Hold__c
  return false unless results.first.Zuora__Account__r.Restricted_Account__c.nil?

  true
end

.us_gov_only?(account, subs) ⇒ Boolean

Determines if a given account with its subscriptions is US Government only

Returns:

  • (Boolean)

Author:

  • Jason Colyer

Since:

  • 1.0.130



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/support_readiness/salesforce/accounts.rb', line 510

def self.us_gov_only?(, subs)
  return false if subs.count.zero?
  return false if subs.include? 'sub_consumption_cicd_minutes'
  return false if subs.include? 'sub_dotcom_premium'
  return false if subs.include? 'sub_dotcom_ultimate'
  return false if subs.include? 'sub_edu'
  return false if subs.include? 'sub_oss'
  return false if subs.include? 'sub_community_other'

  if subs.include?('sub_usgov_12x5') || subs.include?('sub_usgov_24x7') || .Support_Instance__c == 'federal-support'
    global_subs_present = false
    grouped = .Zuora__R00N40000001lGjTEAU__r.group_by { |z| z.Zuora__Subscription__c }
    grouped.each_value do |charges|
      valid_charges = charges.select { |c| c.Subscription_Status__c == 'Active' && Date.parse(c.Zuora__EffectiveEndDate__c) >= Date.today }
      next if valid_charges.count.zero?
      next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.usgov_12x5.include?(x) }
      next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.usgov_24x7.include?(x) }
      next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.fedramp.include?(x) }
      next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.sm_ultimate.include?(x) } && .Support_Instance__c == 'federal-support'
      next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.sm_premium.include?(x) } && .Support_Instance__c == 'federal-support'
      next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.sm_starter.include?(x) } && .Support_Instance__c == 'federal-support'

      global_subs_present = true
    end
    return true unless global_subs_present
  end
  false      
end

.usgov_accounts(client) ⇒ Array

Return an Array of accounts from Salesforce for US Government support

Examples:

config = Readiness::Salesforce::Configuration.new
config.api_version = '58.0'
config.client_id = ENV.fetch('SFDC_CLIENTID')
config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
config.password = ENV.fetch('SFDC_PASSWORD')
config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
config.username = ENV.fetch('SFDC_USERNAME')
client = Readiness::Salesforce::Client.new(config)
accounts = Readiness::Salesforce::Accounts.usgov_accounts(client)
pp accounts.count
# => 7125

Parameters:

  • client (Object)

    An instance of Client

Returns:

  • (Array)

Author:

  • Jason Colyer

Since:

  • 1.0.26



115
116
117
118
119
# File 'lib/support_readiness/salesforce/accounts.rb', line 115

def self.usgov_accounts(client)
  query = Queries.new(usgov_sync_query_string)
  results = Queries.run!(client, query)
  results.map { |r| usgov_sync_object(r) }
end

.usgov_highest_support_level(subscriptions) ⇒ Object

Returns an accounts highest support level for the US Government support sync

Author:

  • Jason Colyer

Since:

  • 1.0.26



478
479
480
481
482
483
484
485
486
487
# File 'lib/support_readiness/salesforce/accounts.rb', line 478

def self.usgov_highest_support_level(subscriptions)
  return 'ultimate' if subscriptions.include? 'sub_sm_ultimate'
  return 'ultimate' if subscriptions.include? 'sub_gitlab_dedicated'
  return 'premium' if subscriptions.include? 'sub_sm_premium'
  return 'starter' if subscriptions.include? 'sub_sm_starter'
  return 'custom' if subscriptions.include? 'sub_usgov_12x5'
  return 'custom' if subscriptions.include? 'sub_usgov_24x7'

  'expired'
end

.usgov_sync_object(account) ⇒ Object

Return a Hash used for the account sync for US Government support

Author:

  • Jason Colyer

Since:

  • 1.0.26



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/support_readiness/salesforce/accounts.rb', line 189

def self.usgov_sync_object()
  subscriptions = (, 'usgov')
  expiration = ()
  type = (, expiration)
  partner = %w[alliance_partner open_partner select_partner].include?(type)
  {
    "name" => "#{Digest::SHA1.hexdigest(.Account_ID_18__c)[0..7]} #{.Name}",
    "salesforce_id" => .Account_ID_18__c,
    "sfdc_short_id" => .Account_ID_18__c[..-4],
    "support_level" => usgov_highest_support_level(subscriptions),
    "arr" => ().to_f,
    "market_segment" => (),
    "account_owner" => .Account_Owner_Calc__c,
    "type" => type,
    "technical_account_manager" => .Technical_Account_Manager_Name__c,
    "solutions_architect" => .Solutions_Architect_Lookup__r&.Name,
    "number_of_seats" => ().to_f,
    "health_score" => (),
    "expiration_date" => expiration,
    "restricted_account" => (.Restricted_Account__c == 'Restricted Party'),
    "greatly_expired" => (partner ? false : Date.parse(expiration) <= Date.today.years_ago(3)),
    "emergency_support_24x7" => subscriptions.include?('sub_usgov_24x7'),
    "sub_consumption_ai" => subscriptions.include?('sub_consumption_ai'),
    "sub_consumption_cicd_minutes" => subscriptions.include?('sub_consumption_cicd_minutes'),
    "sub_consumption_duo_enterprise" => subscriptions.include?('sub_consumption_duo_enterprise'),
    "sub_consumption_duo_premium" => subscriptions.include?('sub_consumption_duo_premium'),
    "sub_consumption_duo_amazon_q" => subscriptions.include?('sub_consumption_duo_amazon_q'),
    "sub_consumption_eap" => subscriptions.include?('sub_consumption_eap'),
    "sub_consumption_storage" => subscriptions.include?('sub_consumption_storage'),
    "sub_proserv" => subscriptions.include?('sub_proserv'),
    "sub_dotcom_premium" => subscriptions.include?('sub_dotcom_premium'),
    "sub_dotcom_ultimate" => subscriptions.include?('sub_dotcom_ultimate'),
    "sub_sm_starter" => subscriptions.include?('sub_sm_starter'),
    "sub_sm_premium" => subscriptions.include?('sub_sm_premium'),
    "sub_sm_ultimate" => subscriptions.include?('sub_sm_ultimate'),
    "sub_usgov_12x5" => subscriptions.include?('sub_usgov_12x5'),
    "sub_usgov_24x7" => subscriptions.include?('sub_usgov_24x7'),
    "sub_gitlab_dedicated" => subscriptions.include?('sub_gitlab_dedicated'),
    "sub_edu" => subscriptions.include?('sub_edu'),
    "sub_oss" => subscriptions.include?('sub_oss'),
    "sub_community_other" => subscriptions.include?('sub_community_other'),
    "sub_ss_ase" => subscriptions.include?('sub_ss_ase'),
    "sub_other" => subscriptions.include?('sub_other'),
    "not_in_sfdc" => false,
    "support_hold" => .Support_Hold__c,
    "date_marked_not_in_sfdc" => nil
  }
end

.usgov_sync_query_stringString

Provides the String needed to make a specific type of SOQL query

Parameters:

  • aid (String)

    The ID of the Account to check

Returns:

  • (String)

Author:

  • Jason Colyer

Since:

  • 1.0.26



652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# File 'lib/support_readiness/salesforce/accounts.rb', line 652

def self.usgov_sync_query_string
  <<~QUERY
    SELECT
      Account_ID_18__c,
      Name,
      Ultimate_Parent_Sales_Segment_Employees__c,
      Account_Owner_Calc__c,
      Technical_Account_Manager_Name__c,
      GS_Health_Score_Color__c,
      Restricted_Account__c,
      Solutions_Architect_Lookup__r.Name,
      Support_Hold__c,
      Support_Instance__c,
      (
        SELECT
          Id,
          Name,
          Zuora__ProductName__c,
          Zuora__EffectiveEndDate__c,
          Zuora__Quantity__c,
          Zuora__TotalContractValue__c,
          Subscription_Status__c,
          Zuora__Subscription__c
        FROM Zuora__R00N40000001lGjTEAU__r
      )
    FROM Account
    WHERE
      Id IN
        (
          SELECT
            Zuora__Account__c
          FROM Zuora__SubscriptionProductCharge__c
          WHERE
            Subscription_Status__c = 'Active' AND
            Zuora__EffectiveEndDate__c >= #{(Date.today - 91.days).iso8601} AND
            (
              Name IN (
                '12x5 US Citizen Support - 1 Year',
                '12x5 US Citizen Support - 2 Year',
                '12x5 US Citizen Support - 3 Year',
                '12x5 US Citizen Support - Monthly',
                '24x7 US Citizen Support - 1 Year',
                '24x7 US Citizen Support - 2 Year',
                '24x7 US Citizen Support - 3 Year',
                '24x7 US Citizen Support - Monthly',
                'GitLab Dedicated for US Public Sector - Ultimate - 1 Year',
                'GitLab Dedicated for US Public Sector - Ultimate - 2 Year',
                'GitLab Dedicated for US Public Sector - Ultimate - 3 Year',
                'GitLab Dedicated for US Public Sector - Ultimate - Monthly'
              ) OR
              Zuora__Account__r.Support_Instance__c = 'federal-support'
            )
        )
  QUERY
end