• ShanghaiDrew
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

I am attempting to design a trigger to insert new Content (ContentVersion) when a new attachment is added.  We are switching from using attachments to Content.  However, the majority of files are added through via the desktop email programs (using Maildrop and Salesforce for Outlook) so I have written a trigger to copy the file to Content. Unfortunately, I can't seem to get it working for the body/file.  After insert, the attachment body referenced seems to be in some temp location and before insert the attachment has yet to be loaded so it can't find any body.

 

When I use before insert, I get the following error: Error: Required fields are missing: [Body]

 

When I use after insert, I get the following error: Error: Apex trigger NewAttachment caused an unexpected exception, contact your administrator: NewAttachment: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.io.FileNotFoundException: /tmp/bvf/cmp_5879646311450005283.def (No such file or directory): []: Trigger.NewAttachment: line 56, column 5

 

Any suggestions?

 

Here's my trigger:

 

trigger NewAttachment on Attachment (before insert) {

List<Attachment_Tracker__c> tracker = new List<Attachment_Tracker__c>();
List<ContentVersion> CV = new List<ContentVersion>();

for (Integer i = 0; i < Trigger.new.size(); i++) {
	String AttParent = Trigger.new[i].ParentId;
	String ContentDesc = '';
	String FileName = Trigger.new[i].Name;
	Blob BodyData = Trigger.new[i].Body;
		// Check to make sure there is a ParentID for the attachment and if records already exist for this Parent
		if(AttParent!=null) {
			String AttParSub = AttParent.substring(0,15);
			Map<String,ID> TrackMap = new Map<String,ID>();
			for (Attachment_Tracker__c c: [select Contact__c, id from Attachment_Tracker__c Where Contact__c =:AttParent] ) {
				TrackMap.put(c.Contact__c, c.id);
			}

			// Make sure the ParentID is a ContactID and it isn't already in the Attachment Tracker
			if(AttParent.startsWith('003')) {
				//Get the Contact Name
				Contact FullName = [SELECT Name, AccountID, Title FROM Contact WHERE Id = :AttParent];
				ContentDesc = FullName.Name+' ('+FullName.Title+' at '+FullName.AccountID+')';
				String ContName = FullName.Name;
				String ContAcct = FullName.AccountID;
				String ContTit = FullName.Title;
				// Get ID to set the Workspace to Resumes
				ContentWorkspace Workspace = [select id from ContentWorkspace where name = 'Resumes' limit 1];

				////////////////////////////////////////
				// First Copy Attachemnet to Content //
				//////////////////////////////////////
			    CV.add(new ContentVersion(
			    	FirstPublishLocationId = Workspace.id, 
			    	// Title = Trigger.new[i].Name,
			    	Contact__c = Trigger.new[i].ParentId,
			    	PathOnClient = Trigger.new[i].Name, 
			    	VersionData = BodyData
			    	) );

				////////////////////////////////////////
				// Now Update the Attachment Tracker //
				//////////////////////////////////////	
				if(!TrackMap.containsKey(AttParent)){
					tracker.add(new Attachment_Tracker__c(
		            Contact__c = Trigger.new[i].ParentId,
					File_Name__c = Trigger.new[i].Name,
					ContactName__c = ContName,
					Job_Title__c = ContTit,
					Company__c=ContAcct
	                ) ) ;
				}
	        }
		}
    insert tracker;
	insert CV;
	}
}

Hi,

 

I've using MailDrop in combination with Mail for a few days now, and I've found it a really handy solution.

 

However, when long email converations are going on, the entire content of the email conversation (including all the quotes) are added on each new email reply.

 

Therefore, I believe it would be great if MailDrop would only store the text that was selected in the email in question, in analogy with the way you can select the text you want to quote in an email when hitting the 'reply' button.

 

It would be great if this feature could be added to MailDrop! It would make sure I don't have to edit each archived email manually each time.

Hello, I'm making a simple automator workflow to upload PDFs to a specific record in SalesForce. Is it possible to use the SalesForceScripting app to upload attachments? I do have it successfully querying and inserting a row in SalesForce, just not sure how to throw the attachment contents in with the insert statement. TIA for any pointers! Daniel

Simon,  I have been using your product Maildrop for some years and have had good success with it.  However you recently changed the manner in which attachments were added to Salesforce.  In the past, the attachment showed up on the actual object/contact etc, now it shows up on the actual email or activity.  I like the way you have done this, but we have become very used to the manner you used to do this.  Would there be a way that I could have the option to attach an attachment, both to the actual 'Object' or 'Contact', rather than nesting it under the email itself???

 

 

I noticed that Maildrop doesn't require API but SF3 does. My company has the Professional level of Salesforce so we don't have API as part of our package.

Two questions ...

1. Will SF3 still require API once it is out of Beta and available via AppExchange?

2. I saw a post by Simon that says you can buy API access a-la-carte from Salesforce but when I called them the sales rep said that isn't an option. Can anyone confirm that they have done this without having to upgrade to Enterprise or higher?

Thanks!