Skip to content

Instantly share code, notes, and snippets.

@r38y
Created September 18, 2008 18:49
Show Gist options
  • Save r38y/11461 to your computer and use it in GitHub Desktop.
Save r38y/11461 to your computer and use it in GitHub Desktop.
def notifications(request)
organization_sfdc_id = params['Envelope']['Body']['notifications']['OrganizationId']
object_class = params['Envelope']['Body']['notifications']['Notification']['sObject']['xsi:type'].gsub(/sf:/, '')
logger.fatal("organization_sfdc_id: #{organization_sfdc_id}")
logger.fatal("object_class: #{object_class}")
begin
if ['Lead', 'Contact'].include?(object_class)
organization = Organization.find_by_sfdc_id(organization_sfdc_id)
organization.setup
notifications = request.notification
logger.fatal "="*50
logger.fatal request
logger.fatal "="*50
notifications.each do |notification|
object = notification.sObject
logger.fatal "*"*50
logger.fatal object
logger.fatal "object_class: #{object_class}"
logger.fatal "*"*50
# we have to do this because a managed package will be used sometimes
ceeb_code = (object.respond_to?(:ceeb_code__c) ? object.ceeb_code__c : object.TargetX_SRMa__ceeb_code__c)
# we have to do this because a managed package will be used sometimes
if object.respond_to?(:school_level__c)
school_level = object.school_level__c
else #object.respond_to?(:TargetX_SRMa__school_level__c)
school_level = object.TargetX_SRMa__school_level__c
end
logger.error("ID: #{object.id}")
asf_account = OrgSpecific::AsfAccount.find_or_create(ceeb_code, school_level)
if object_class == 'Contact'
asf_contact = OrgSpecific::AsfContact.find(object.id)
asf_contact.account = asf_account
asf_contact.save
end
end
logger.error "Returning TRUE response"
return NotificationsResponse.new(true)
else
raise "We don't know what to do with this message!!"
end
rescue => ar_details
logger.error "ERROR: #{ar_details.class}: #{ar_details}"
logger.error " #{ar_details.backtrace[0]}"
return NotificationsResponse.new(false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment