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
envecreativeenvecreative 

Transfer Attachments Across Objects

I've been going out of my mind trying to find the information I'm looking for, so hopefully someone can help me out. I see that when a user converts a Lead to an Account/Opportunity, the attachments (Notes & Attachments section) from the Lead transfer over to the Account. I need to be able to do the same between Opportunities and a custom object I built.

 

I'm familiar with passing values through a URL - I am using this function to pass data into the custom object at creation presently - but I don't see how to pass attachments. Can somone please give me some idea of how to do it?

 

If it's easier, it would be even better if I could set up attachment upload areas within the custom object that would intersperse the attachments in various areas around the custom object layout. (The client doesn't really like having to batch everything in one area for this giant layout.) I'm attaching an image so you can see what I have in mind.

 

bob_buzzardbob_buzzard

I think you'll have to write some Apex code or use the dataloader to do this.  Through the Salesforce UI you upload attachments to particular record and I'm not aware of any way to change the parent record via the screens.

 

In Apex code you can extract an Attachment object via SOQL, change the ParentId field to point at the record you would like the attachment to be associated with and update via DML.

 

The data loader would allow you to do this via exporting Attachment records and changing the parent id via excel or simlar, then updating the records.

bob_buzzardbob_buzzard

With regard to your second point, you'd need Visualforce pages embedded in the record view page to pull the required attachments for the section.

Idd BaksheeshIdd Baksheesh

Hi,

You will have to write a custom process using visualforce page and controller. The VF page can have no design objects, just a simple 

 

<Apex: page action="{!convert}"/>

 

The convert function will have the following pseudo code:

 

1. Create custom object object1

1. Map fields from opportunity to custom object (if you want a dynamic process, you can use custom settings to create this map or hardcode) Object1.field1=Opportunity1.field1;

2. For transfering attachment. 

i If you want to preserve original attachment,  use the sobject.clone function and change the parent id of the cloned attachment.

ii. If you want to discard original attachment, simply change the parent id from opportunity to the custom object id. (make sure you custom object has notes and attachment checkbox checked.)

3. Insert object1

 

Now you can create custom detail page button and use the VF page, the button automatically passes the opportunity Id in the page.

 

Hope it helps.

 

Idd BaksheeshIdd Baksheesh

For the second part, Bob has pointed to the right place.