Wednesday, 2 December 2009

Salesforce MySQL backup tool

I've been a little bored recently and working on 'unforced', a php tool to backup your salesforce instance in MySQL (I'm sure a MSSQL conversion wouldn't be too hard). I've been clearing up the code and working on replicating the table relationships from Salesforce to MySQL. Major Adodb problems, mostly due to my stupidly, have been causing problems:
  • MySQL doesn't handle table relationships without tweaking the tables with TYPE=InnoDB;
  • $db->Execute("...") won't handle multiple SQL commands, you can only use one at a time

It now works as you can see above. Problem being, if you create the tables, then the relationships and try to import the data, it creates all sorts of integrity issues as the tables needs to be imported in the correct order. I'll try and solve that one later

Friday, 1 May 2009

Using XML as a datasource in ASP.NET

A great tutorial is here. I wanted to have the salutations of people in a simple list without having to go to the trouble of setting up a SQL connection. I created my xml list like so:

<?xml version="1.0" encoding="ISO-8859-1"?>

<salutations>

<salutation text="Mr.">
</salutation>
<salutation text="Mrs.">
</salutation>
<salutation text="Ms.">
</salutation>
<salutation text="Dr.">
</salutation>
</salutations>

Copied it into my App_Data folder and followed the instructions of the document above. I set the XPath expression to salutations/salutation and it works. A more detailed description of searching and filtering can be found here. If you want to select a value when using code use the normal object.Selectedvalue = "choice".

Monday, 27 April 2009

ExternalID and upserts

I've read a lot about upserting into Salesforce using the API, though it seems to get a strict on what fields you can use as the 'primary key' when upserting. Salesforce asks that you use an ExternalIDField, which must be a custom field and you must specify it inside salesforce. Well thats not much use and I don't really have time to fix this. Instead you can use the lookupid attribute of default fields. this means, in effect that you could do a call like this:

salesforce.sObject[] objList;
salesforce.Contact connyhuq = new salesforce.Contact();

connyhuq.Title = "Ms.";
connyhuq.HEAPS_Interest__c = "Yes";
connyhuq.Email = "chuq@huqqers.org.uk";
connyhuq.LastName = "Kemp";
objList = new salesforce.sObject[] { connyhuq };

salesforce.UpsertResult[] upResult = binding.writeData("Email", objList);

What we have done is made the Email address the primary key on this upsert. I wish to make the Id of the object the key field but it complains that we do not have access rights to change this. I doubt there is anything you can do about this. So then I decided to try and composite key the fields and create a unqiue key for each entry, I don't have any good externalIDfields yet. However, the upsert routine only lets you use one field. Looks like I need to go into Salesforce to create the composite key field manually.

Monday, 6 April 2009

C# Salesforce Development

You will need the following:
  1. Visual Web Developer Express Edition
  2. Salesforce Developer Account
  3. WSDL generated by the salesforce account (http://www.salesforce.com/us/developer/docs/api_meta/index.htm)
  4. in VWD create a website, not a web project (this si a personal preference)
  5. Website -> Add Web Reference -> URL = your Enterprise.wsdl
  6. web reference name = "salesforce"
  7. Add Reference
now how do you use any of this? We need to expose the salesforce API functionality to the c# program
  1. in your App_Code folder create a class called sfconnector.cs
public salesforce.SforceService doLogin()
{
salesforce.SforceService binding = new salesforce.SforceService();
try
{
salesforce.LoginResult lr = binding.login(sforceUsername, sforcePassword);
binding.SessionHeaderValue = new salesforce.SessionHeader();
binding.SessionHeaderValue.sessionId = lr.sessionId;
binding.Url = lr.serverUrl;
binding.Url = lr.serverUrl;
}
catch (Exception)
{ }
return binding;
}

this will connect you to salesforce provided you have the correct username and password. If we can log in we probably want to log out as well.

public void logOut(Page pg)
{
pg.Session.Abandon();
pg.Response.Write("");
}

By calling this function we'll terminate the current session.

Wednesday, 18 March 2009

Upgrading Visual Studio 2008

After messing around with Visual Studio trial edition for some time and then leaving it be for a few months, I restarted it today. It complained that I needed to register it to use it further, offering an upgrade button and then immediately closing on clicking that link. I followed the link and it took me to a website to purchase a full copy. Only problem being that I already purchased a copy a few months back through my netowrk manager. Microsoft doesn't make the route to upgrading very clear at all and after a little googling I found this:

http://msdn.microsoft.com/en-us/library/ms246600(VS.80).aspx

So i tried it but our key doesn't want to work... I'll keep you informed how I solve this one

Monday, 23 February 2009

Lotus Notes 5 Youtube

Huh!? Does not compute. Well apparently it does. We have some Lotus notes rich text pages which are supposed to make Web Editing a treat. This is a lie. Best place to start is writing documents in word and copy and paste them across, there doesn't seem to be a simple text editing tool bar. But what about getting youtube in there? Well the best way is to copy your embed code from Youtube straight into the rich text editor. To get HTML to execute you normally surround the code in [brackets] but in this case we are going to leave it with out as the brackets don't work. You then select the embed code and click menu Text->Pass-Thru HTML. All done

Thursday, 5 February 2009

Visualforce

getting stuck into visualforce. Everything seems fine, though using the webeditor is proving problematic. It seems that you should use StandardControllers for all the inbuilt functionality that they provide, the extensions section allows you to expand the core functionality, otherwise you will have to rewrite things as simple as the save and get functions.

<apex:page standardcontroller="Account" extensions="Screening" tabstyle="contact">

However, things aren't that easy, you'll have to edit the Screening class in eclipse, it wont let you deal with it through the web interface. Sucky!

Thursday, 29 January 2009

Backing up folders using Samba and Cron

Now that we have a nightly backup of the joomla database we should probably make regular back ups of the folder structure to a separate machine. Our network is a predominately Windows based one. So we need to first of all gzip up the folder along with the database and then write it to the P: drive using Samba:

date=`date +%Y-%m-%d_%Hh%M`
mysqldumpdir='/home/administrator/Scripts/joomla-backup/'
mysqldump -uroot --password='******' --all-databases | gzip > $mysqldumpdir$date.gz
tar -c /var/www/joomla/ -i $mysqldumpdir$date.gz | gzip -c > Documents/backup.tar.gz

This first of all puts the joomla folder and the mysqldump file created last post into a tape archive. We string that together and gzip the results, at the moment this points to the Documents folder of the administrator, we will have to now hook it up with Samba. I started by installing the Samba client on my Ubuntu build. Or if you want an easier route, try Places -> Connect to Server, you can see it from there.

But you want to mount it right, folow the guide. warning make sure that the code will run from anywhere and use absolute addresses, then copy your local backup to the backup server, code looks like this:

date=`date +%Y-%m-%d_%Hh%M`
mysqldumpdir='/home/administrator/Scripts/joomla-backup/'
backupfolder='/home/administrator/Documents/'
mysqldump -uroot --password='******' --all-databases | gzip > $mysqldumpdir$date.gz
tar -c /var/www/joomla/ -i $mysqldumpdir$date.gz | gzip -c > $backupfolder$date.tar.gz
cp $backupfolder$date.tar.gz /mnt/devserver/$date.tar.gz

Wednesday, 21 January 2009

Cron PHP mysqldump ubuntu sendmail

The problem is we have a Joomla install on one of our servers, we want to back up the databases each night and mail us to confirm. Problem being that Ubuntu doesn't have sendmail installed by default and when you try and call the php mail() function it breaks saying it can't find send mail. A quick "sudo apt-get postfix" installed postfix mail, a much more competent mail system.

Next up is starting the cron tasks, I used a little guide and soon had cron running a mail script using a command line "sudo crontab -e" and editing in nano, not a big fan of vi

32 * * * * php /home/administrator/Scripts/backup-intranet.php

this emails me every 32 minutes, mails work on my gmail account, but my work account must be eating them with the spam filter.

So all good so far, the next stage is to set up the daily mysqldump to backup joomla. Adding another line into cron:

04 18 * * * mysqldump -uroot --password='******' --all-databases | gzip > /home/administrator/Scripts/joomla-backup/joomlasqlbackup_`date +%m_%d_%y`.gz

backing up at 6:04 each evening, it executes when I'm root from command line and from normal, but when I'm in cron it doesn't fire. To get around this I placed a bash script to run this and pointed cron to that:


#!/bin/bash

date=`date +%Y-%m-%d_%Hh%M`

mysqldump -uroot --password='******' --all-databases | gzip > /home/administrator/Scripts/joomla-backup/$date.gz

Make sure the folder has permissions for scripts ot write to it! And the new cron is:

/home/administrator/Scripts/databasebackup.sh

Tuesday, 13 January 2009

Differences in Eclipse 3.4.1 when using salesforce

As mentioned in the previous post, there are differences in the behaviour of Eclipse 3.4.1 from the 3.3.x instructions provided by salesforce. A few other differences include:

When writing classes and triggers you were previously asked to right hand click (RHC) and select Apex -> Run Tests

All the RHC commands are now accessible under RHC Force.com. A bit of rebranding I suppose

Setting up Eclipse 3.4.1 with salesforce IDE

The current Salesforce documentation only covers setting up Salesforce with Eclipse 3.3.x. This little guide shows how you can set up Eclipse 3.4.1 with the salesforce IDE.

Download Eclipse Classic and install to you local machine.

In Eclipse click Help -> Software Updates... -> Available Software -> Add Site

Add the reference http://www.adnsandbox.com/tools/ide/install/ and click OK

Tick the boxes and click Install.

Window -> Open Perspective -> Other -> Force.com

Let's create our first project

File -> New -> Force.com

Name it and fill in your details. Be warned, if you are running a sandbox and a live site, which ever security token was reset last is you current security token

This isn't supposed to work with 3.4.x and there is a idea request for this feature, I seem to have negated the need for this change. Yippee!

use the cookbook to get you started

Salesforce Apex Code development

Apex is a language that only deals with logic of the business variety. Finding a route into developing it proves a little more complicated that you might think.

You need Salesforce

You need a developer account and a sandbox to play about in. As soon as you save Apex it is live!

Get the Eclipse platform with the Java IDE

Next download the Salesforce IDE from the website

You need a developer account, this must be separate from your normal salesforce account

log into you developer account by going through .force.com

The old starting apex development video made in 2007 suggests that when in salesforce you go to:

Setup - Build - code

but this is no longer the case as the build tab does not exist on a clean install

To see triggers, they are under:

Setup - Customise - XYZ - Triggers