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
gmuppetgmuppet 

Perl WWW::Salesforce - Missing Entity type information error with create

New to this so appologies if I'm doing something stupid.

 

Running the following:

 

use strict;
use WWW::Salesforce::Simple;


# Authenticate with the Salesforce

 

my $sforce = WWW::Salesforce::Simple->new(
        'username' => '*****',
        'password' => '*****'
) or die 'failed sf login'.$!;

my %lead=();

%lead = (
        'email' => 'testtestcom',
        'leadsource' => 'WebRegistration',
        'company' => 'TestCo',
        'country' => 'US',
        'firstname' => 'Test',
        'lastname' => 'Person'

);

my $result = $sforce->create(type => 'lead',%lead);

 

 

and get the error: 

> Missing entity type information. sObject requires a separate 'type' field be sent. at sf2.pl line 30

 

Any ideas?

 

While I'm at it, are there any decent docs on using Perl with salesforce with code examples of queries ,inserts & creates etc? There doesn't seem to be much around.

 

Thanks in advance.

 

G

BoltonBolton
Your test worked fine for me - though I had to provide a valid email address in order for it to work. Are you doing anything else in this script that you're not showing us on here?
gmuppetgmuppet

Hi Bolton - thanks for the feedback.

 

What you have run is exactly what I am running so it's strange.

 

I guess it is either a problem with:

- Account being used?  I can log on and query ok with perl.

- Perl Modules?  I'll look into this to ensure I've got the latest versions.

 

Thanks

EricVlachEricVlach

Have you seen http://search.cpan.org/dist/WWW-Salesforce/lib/WWW/Salesforce.pm ? it helps a little.

 

The create method needs the type key in the hash itself, not in the method call (like the update and upsert methods use.)

 

%lead = (

        'type' => 'Lead',

        'email' => 'testtestcom',
        'leadsource' => 'WebRegistration',
        #etc...

);

 

I've been spending a lot of time lately using WWW::Salesforce in my perl scripts, let me know if you run into other troubles.

-Eric

BoltonBolton

I ran this chap's script and it worked fine.  I've used the method call like that before for readabilities sake and it seems to work.  I knocked up a little test script now to make sure I'm not going insane, that dumps the value of the hash on the other side.

 

 

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

my %vars = (
name => 'terry',
likes => 'carrots'
);

foo(type => 'bar', %vars);

sub foo {
my (%in) = @_;
warn Dumper \%in;
}

 

 This produces:

 

$VAR1 = { 'name' => 'terry', 'likes' => 'carrots', 'type' => 'bar' };

 

I suspect he's on the right track looking at module versions. I'd be interested to know how he fixed it! :)

 

gmuppetgmuppet

Folks,

 

The problem is definitely to do with my perl installation.

 

I repeated this on a different machine - ubuntu :-)  - and I get different behaviour- it works fineThe posted code works apart from having to change the email address into a valid email address (as already stated).  I'm not going to spend any more time on sorting route cause but it will be to do with perl versions / modules / crappy machine etc.

 

For interested readers, ill post the demo script I got working last night - it does a query, update and create.

The beauty of perl is that "there is more than one way to do it" but I realise the code could be improved and made neater but it was a useful exercise for me to go through.

 

Thanks

 

gmuppet.

 

  

 


use WWW::Salesforce::Simple;
use Data::Dumper;

my $sforce=WWW::Salesforce::Simple->new(
'username' => '******',
'password' => '******') or die 'login fail'.$!;


# query structure

foreach my $field (@{$sforce->get_field_list("Lead")}) {
print $field->{name} . "\n";
}


# get exising record

my $result1 = $sforce->do_query("select
Id,Email,LeadSource,Company,Website,FirstName,LastName from Lead where
Email = 'kakin\@athenahome.com'");


my $id= $result1->[0]->{"Id"}[0];
my $Email= $result1->[0]->{"Email"};
my $LeadSource= $result1->[0]->{"LeadSource"};
my $Company= $result1->[0]->{"Company"};
my $Website= $result1->[0]->{"Website"};
my $FirstName= $result1->[0]->{"FirstName"};
my $LastName= $result1->[0]->{"LastName"};

# change name
$FirstName = "Bob";

my %newdata;

$newdata{"Email"}=$Email;
$newdata{"id"}=$id;
$newdata{"LeadSource"}=$LeadSource;
$newdata{"Website"}=$Website;
$newdata{"FirstName"}=$FirstName;
$newdata{"LastName"}=$LastName;

# update existing record

my $result = $sforce->update('type' => 'Lead',%newdata);

if ($result->result->{"success"} eq "false") {
print $result->result->{errors}->{message} . "\n";
}


# create new record


my %newdata1;

$newdata1{"Email"}="cho3r3\@sssee3f.com";
$newdata1{"LeadSource"}="web";
$newdata1{"Website"}="eeeeee";
$newdata1{"FirstName"}="bill";
$newdata1{"LastName"}="black";
$newdata1{"Company"}="widjits";

my $result2 = $sforce->create(type => 'lead',%newdata1);

if ($result2->result->{"success"} eq "false") {
print $result2->result->{errors}->{message} . "\n";
}

 


 

jrosejrose

I was experiencing this issue as well. It seems to have resolved upon updating SOAP-Lite to version 0.710.08. The previously installed version was around 0.60.

 

-Joe