0

Just started using databasedotcom gem and now stuck.

When trying to find a record in Salesforce by Id, if the id/record doesn't exist, it produces the following error:

"Provided external ID field does not exist or is not accessible:"

If the Id does exist I am able to continue with my page fine.

Here's my code:

def search
@account = Account.find(params[:id])

if @account.Id
  redirect_to new_user_registration_path(:id => @account.Id)
elsif params[:id].to_s.present? and @account.nil?
  flash[:alert] = "Couldn't find that one.  Please check and re-submit your number."
  redirect_to search_path
end

end

How can I overcome this?

Thank you.

1 Answers1

0

Changed the code to the following and it works fine now - thank you Danny Burkes. It captures the exception and routes accordingly.

def search
begin
@account = Account.find(params[:id])

if @account.Id
  redirect_to new_user_registration_path(:id => @account.Id)
end
rescue Exception => e
  flash[:alert] = "Couldn't find that one.  Please check and re-submit your number."
  redirect_to search_path
end

end