+ Start a Discussion

How to create a new record only after Attachment??



I need to create a new record in the related list.. but that record should get created only after i attached a file to it...


In order to upload the file.. i have created a visualforce page...



Cory CowgillCory Cowgill

Without further details, it looks like there are 2 ways you can accomplish this.


1. You can create an Apex Trigger on the Attachment object. You need to do this in the Force.com IDE. I wouldn't recommend this approach though as their is a known trigger bug on the Attachment insert triggers (Something I discovered working with SF Premier Support, its in another post in the boards.)


2. Since this is a custom VF Page, you should have a custom controller or custom controller extensions When you execute the Save action in the controller, you can should wrap the insert DML statement with a Try/Catch block. If the Attachment insert is successful, then you could create the new record you want to create and perform a second DML statement in another try/catch block to insert that record.


As this is the new boards forum, please provide some more details around your issue so folks can give some more detailed assistance.