function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KunjanKunjan 

How to manage custom object using asf-soap-adapter?

Hello,

Please let me know asf-soap-adapter is useful for custom objects or not?

I can communicate with standard objects only using Ruby application, same way I can't communicate with custom objects.

 

If it is possible to use custom object also using this api then please let me know how to access them with Ruby?

 

Thanks in advance,
Kunjan

cloudcodercloudcoder

Yes, custom objects are fully supported. One thing to note though, is that the adapter takes care of the __c for you when creating objects. eg, here is a snippet from the Getting Started Article (http://wiki.developerforce.com/index.php/Getting_Started_with_the_Force.com_Toolkit_for_Ruby) 

 

 

script/generate model Salesforce::CustomObject

And update the resulting model file to run set_table_name:

class CustomObject < SfBase     
  set_table_name ‘CustomObject’  
  # must be a valid Salesforce Table, otherwise, it will complain.   
end

 

KunjanKunjan

I made chances in model file, but now it's throwing error like:

Anonymous modules have no name to be referenced by

 

Please help me to solve this issue.

 

Thanks,

- Kunjan

KunjanKunjan

It seems like model file was inherited by SfBase class and due to that eror was generaetd.

 

But can you please tell me how to access custom fields of standard and custom object?

 

I am getting following error while accessing custom field of custom object.

undefined method `VisitDate' for #<Salesforce::VisitorReport:0x2986140>

where VisitDate is my custom field and VisitorReport is my custom object.

 

Thanks,

- Kunjan

cloudcodercloudcoder

Does your custom object already exist within your Salesforce org? The toolkit does not currently support db:migrate of pushing new models into Salesforce and creating the custom object.

KunjanKunjan

The custom object is already exist in my salesforce org. Even the same error I am getting with custom fields of standard object. So is it possible to use/get custom fields of standard/custom object?

 

- Kunjan

cloudcodercloudcoder

Yes, definitely. Can you share me the code snippet where you are trying to access the custom field?

KunjanKunjan

Controller code:

def index
    @visitor_reports = Salesforce::VisitorReport.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @visitor_reports }
    end
  end

 

index.html.erb:

<% @visitor_reports.each do |visitor_report| %>
  <tr>
    <td><%=h visitor_report.id %></td>
    <td><%=h visitor_report.name %></td>
    <td><%=h visitor_report.VisitDate %></td>
    <td><%=h visitor_report.Description %></td>
    <td><%= link_to 'Show', visitor_report %></td>
    <td><%= link_to 'Edit', edit_salesforce_visitor_report_path(h visitor_report.id) %></td>
    <td><%= link_to 'Destroy', visitor_report, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>

I got error at line where I try to access custom field VisitDate and Description. Id and Name are working fine.

cloudcodercloudcoder

Hi,

 

Sorry for the delayed response. Looks like there are two issues.

 

1. The getting started article had an error in it. It missed the module definition when you create your model. The correct syntax is as follows (assuming my custom object is called Book__c):

 

 

class Salesforce::Book < Salesforce::SfBase                                 
  set_table_name 'Book'
end
2. The second, and bigger issue, is that there appears to be a bug in the toolkit I will have to fix. Right now you can't use a custom object with an underscore (_) in it. eg: Book_Reviews__c.   I will get this fixed, but for now, custom objects with no underscores work just fine.

 

 

 

KunjanKunjan

Thanks for your support.

 

Now I am facing another problem while editing standard/custom record.

A new record is always created instead of updating the existing record. My controller code looks like:

 

I have tried with save and update_attributes but both are adding new record.

 

def update
    @account = Salesforce::Account.new(params[:salesforce_account])

    respond_to do |format|

      #if @account.save

      if @account.update_attributes(params[:account])     
        format.html { redirect_to(@account, :notice => 'Salesforce::Account was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @account.errors, :status => :unprocessable_entity }
      end
    end
  end

 

If you can help me to solve this issue than it will be very useful for me.

Thanks

KunjanKunjan

I think the code which is written in below link has some mistake.

http://wiki.developerforce.com/index.php/Getting_Started_with_the_Force.com_Toolkit_for_Ruby

 

In that code, you have to made changes at 2 places.

1) In 2nd line...write 

@contact = Salesforce::Contact.update(params[:id], params[:salesforce_contact]) instead of

@contact = Salesforce::Contact.new(params[:salesforce_contact])

 

2) In 4th line...write

if @contact.update_attributes(params[:contact])

instead ov if @contact.save

 

And it works fine...cheers

cloudcodercloudcoder

Awesome, thanks! I've been going through and cleaning up that article this week as there have been a number of errors I picked up too