The usual order of execution detailed at http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm still applies with some special considerations
The Before triggers and validation rules do not fire unless that checkbox is ticked under Customise > Lead > Settings. Note that for orgs created prior to '08 you'll need to contact support to enable this (related answer)
After triggers still always fire irrespective of the above setting
To check if a Lead has been converted and do custom lead conversion logic, the best home for such is the LeadAfter trigger, where you can check
If (trigger.isUpdate && Lead.IsConverted && !trigger.oldmap.get(lead.id).IsConverted)
//do your stuff
Here you will have access to the convertedAccountId, convertedContactId, ConvertedOpportunityId and any OpportunityContactRoles
This is also a good place to re parent any custom related list records from the converted Lead to either of Company or Contact
Just added some debug logs to triggers, and here's the order of execution :
(This is with the Enforce Validations and Triggers on Lead Conversion Enabled)
Account Custom Field Mappings
Account Before (Fires based on lead settings)
Account After
Contact Custom Field Mappings
Contact Before (Fires based on lead settings)
Contact After
Opportunity Field Mappings
Opportunity Before (Fires based on lead settings)
Opportunity After (OCR's not available)
Lead Before
Lead After (OCR's available)
If the Enforce Validations and Triggers setting is turned off, none of the Before triggers fire. The After triggers however still fire.
Take a look at the documentation:
There you have the ability to provide an existing AccountId and ContactId with the methods setAccountId() and setContactId(), respectively.
You just have to make sure that your contact is associated with the account you provide in AccountId, and if you use PersonAccounts, don't provide the ContactId
setAccountId Sets the ID of the account into which the lead
will be merged. This value is required only when updating an existing
account, including person accounts. Otherwise, if setAccountID is
specified, a new account is created.
setContactId Sets the
ID of the contact into which the lead will be merged (this contact
must be associated with the account specified with setAccountId, and
setAccountId must be specified). This value is required only when
updating an existing contact.Important If you are converting a lead
into a person account, do not specify setContactId or an error will
result. Specify only setAccountId of the person account. If
setContactID is specified, then the application creates a new contact
that is implicitly associated with the account.
Best Answer
Try taking a look at this blog post:http://blog.jeffdouglas.com/2009/02/13/enhancing-the-lead-convert-process-in-salesforce. You could hook into it and copy the attachment over.