Skip to content

Instantly share code, notes, and snippets.

@ianhenrysmith
Last active July 6, 2017 18:46
Show Gist options
  • Select an option

  • Save ianhenrysmith/6f4e4b6ae917431e081c36028bfa678e to your computer and use it in GitHub Desktop.

Select an option

Save ianhenrysmith/6f4e4b6ae917431e081c36028bfa678e to your computer and use it in GitHub Desktop.
generate leads or contact data for salesforce testing purposes. defaults to 100 contacts. to run, just do a `ruby ./salesforce_data_generator.rb lead 10`, or with whatever args you want. make sure to do a `gem install faker` first. works in ruby 2.4
require "faker"
require "csv"
def contact_row
[
first_name,
last_name,
email,
title,
birthday
]
end
def contact_header
[
"FirstName",
"LastName",
"Email",
"Title",
"Birthdate"
]
end
def lead_row
[
first_name,
last_name,
email,
title,
company
]
end
def lead_header
[
"FirstName",
"LastName",
"Email",
"Title",
"Company"
]
end
def first_name
Faker::Name.first_name
end
def last_name
Faker::Name.last_name
end
def email
Faker::Internet.email
end
def title
Faker::Name.title
end
def birthday
Faker::Date.birthday(18, 65)
end
def company
Faker::Company.name
end
def generate_csv
CSV.open(filename, "wb") do |csv|
csv << self.send(:"#{type}_header")
count.times do
csv << self.send(:"#{type}_row")
end
end
end
def filename
@filename ||= "#{type}s-#{Time.now.to_i}.csv"
end
def type
@type ||= ARGV[0] ? ARGV[0].downcase : "contact"
end
def count
@count ||= ARGV[1] ? ARGV[1].to_i : 100
end
generate_csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment