+ Start a Discussion
CloudStrickerCloudStricker 

Inserting Attachment to an object using Using command line interface

Hi All,

 

Anybody help me how to insert an attachment to any object (say Account) through command line.I am able to insert a note to an account but not able to do with attachment.

ClintLeeClintLee

I'm not sure exactly what you mean by the command line but ths is how you can add an attachment to an Account in your Apex code.

 

// You'll need an Account object.  Here I'm just creating one for demo purposes.

Account a = new Account( Name = 'Acct' );  

insert a;

 

// Create and insert your attachment

Attachment att = new Attachment( Name          = 'My Attachment'

                                                            ,Description = 'This is a new attachment'

                                                            ,Body            = Blob.valueOf( 'Body of the Attachment' )

                                                            ,ParentId      = a.Id );

insert att;

 

Hope that helps.

 

Clint