0 votes
1 view
in Salesforce by (11.9k points)

I am using the restforce gem to push data to salesforce once an object is saved in my rails application. Everything is working fine but in the process of making my code DRY, I encountered an issue. I have a group of fields that I am submitting with every object I save. However, depending on the object type I want to submit other fields. I'm not sure how to set a group of field mappings to a variable.

I'm not getting any errors in the console but nothing is pushing to salesforce.

model.rb

def create_application

  constant_fields = Name: object.name, Email: object.email

  if object.type == "car"

    car_fields = Wheel_Size__c: object.wheel_size, Colour__c: object.car_colour)

    Restforce.new.create!(constant_fields, car_fields)

  else 

    plane_fields = Wing_Span__c: object.wing_span, Tail_Number__c: object.tail_number

    Restforce.new.create!(constant_fields, plane_fields)

  end

end 

1 Answer

0 votes
by (30.1k points)

It seems you're not using proper syntax for Ruby hashes. 

Try:

def create_application

  constant_fields = { Name: object.name, Email: object.email }

  if object.type == "car"

    car_fields = { Wheel_Size__c: object.wheel_size, Colour__c: object.car_colour }

    Restforce.new.create!(constant_fields.merge(car_fields))

  else 

    plane_fields = { Wing_Span__c: object.wing_span, Tail_Number__c: object.tail_number }

    Restforce.new.create!(constant_fields.merge(plane_fields))

  end

end 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...