Sorry bad category...
Last edited by lucasvm; 12-09-2008 at 01:19 PM.
im working with salesforce with a form oh php and i need to check that before letting users register to win a gift, sorry my bad english...the form works great and it sends the info to my salesforce database but it doesnt check if it is a duplicate mail or user....
I see what you are trying to do
Give me a day or so to think about it and see if I can come up with a resolution for you sir
Thanks for joining the site by the way
~Mike
great, thanks for your reply and help.- i really dont get it with the salesforce API...i need to check it in the form made with html/php before they send the info, so if they are already in the database then it wont register...i dont know if my english is good, sorry.
Last edited by lucasvm; 12-09-2008 at 05:16 PM.
So if you are wanting to check to see if you have duplicates in the object in Salesforce, you could try something like this:
Hope this makes sense man!PHP Code:
$wsdl = './includes/soapclient/partner.wsdl.xml';
$userName = "myemail@salesforce.com";
$password = "password";
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName, $password);
//check to see if the form has been submitted
if (isset($_GET['submit']))
{
//prepare a SOQL statement to Salesforce to check
//your table in Salesforce to see if the email matches the one coming
//in from the form
$soql = "Select Email FROM Lead where email like '{$_GET['email']}%' ";
$leads = get_records($client, $soql);
/*so if you get something back from the get_records function, that means you have a match of the email in your
salesforce database. You can compare the leads object email to your $_GET['email'] and if they match you can
render a message back to the user saying something like "you already registered, only one person is allowed to
register".*/
if($leads->email == $_GET['email'])
{
echo "ou already registered, only one person is allowed to register";
}
else
{
//insert the new lead or record into your table here
}
}
function get_records(&$connection, $query)
{
try
{
$queryOptions = new QueryOptions(500);
$response = $connection->query(($query), $queryOptions);
// check count to see if we are done
if ($response->size > 0)
{
$accounts = $response->records;
// Cycles through additional responses if the number of records
// exceeds the batch size
while (!$response->done)
{
set_time_limit(100);
$response = $connection->queryMore($response->queryLocator);
$accounts = array_merge($accounts, $response->records);
}
}
return $accounts;
}
catch (exception $e)
{
// This is reached if there is a major problem in the data or with
// the salesforce.com connection. Normal data errors are caught by
// salesforce.com
echo '<pre>' . print_r($e, true) . '</pre>';
return false;
exit;
}
}
~Mike
great thanks i will try it, just one question, i got my form sending to a salesforce url, not mine, and i cant add code there, is there a way to add this php code into the form?, <form method="post" action="here i send to a salesforce url" id="form"> what do you think???????????
i do this to validate fields: onsubmit="return validation4(this); but with javascript...
Edit:
mmmm maybe i would add the salesforce url here:
if($leads->email == $_GET['email'])
{
echo "ou already registered, only one person is allowed to register";
}
else
{
https://www.salesforce.com/servlet/servlet.AFDSFSDFSFS
}
what you think?, but the problem is the form heheh
Last edited by lucasvm; 12-10-2008 at 02:24 PM.
oh shoot I thought that this was an external form. You are actually sending the data right into salesforce. So you action is actually some kind of form right on Salesforce?
I must be a newbie at this because I did not see that or know that you could do that
I am not sure how you would get this code in there, I mean I know that you cannot add code like PHP into Salesforce, it will not work
~Mike
oh bad news hehe, i did not make this form...it was another developer...did you read this?
Edit:
mmmm maybe i would add the salesforce url here:
if($leads->email == $_GET['email'])
{
echo "ou already registered, only one person is allowed to register";
}
else
{
https://www.salesforce.com/servlet/servlet.AFDSFSDFSFS
}
but i dont know how to change the form, how can i do?
hey man did you ever get this working or figured out?
~Mike
Bookmarks