Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8617371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:50:28+00:00 2026-06-12T05:50:28+00:00

We need to add an attachment for new contact. We are using APEX class

  • 0

We need to add an attachment for new contact. We are using APEX class for adding new contact. We are able create new contact. we need to maintain the Order information for a contact. This is not possible with the available fields/custom fields. So we are going to try with attachment. a customer may have multiple orders.
Can you please let me know how to add attachment for a contact using c#.

Please find the below code snippet:

Contact newContact = new Contact();

newContact.LastName = downloadInformation.Name;
newContact.Email = downloadInformation.Email;

try
{
    SforceService salesForce = new SforceService();
    MySFServiceService mySFServive = new MySFServiceService();
    mySFServive.SessionHeaderValue = new SForce.MyService.SessionHeader();

    LoginResult loginResult = salesForce.login("id", "password");
    mySFServive.SessionHeaderValue.sessionId = loginResult.sessionId;
    // UserRegistration is a method defined in our apex class.
    // parametter 1: contact object parameter
    // 2: account name
    mySFServive.UserRegistration(newContact, "Test Account");
}
catch (Exception ex)
{
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:50:29+00:00Added an answer on June 12, 2026 at 5:50 am

    Import the enterprise WSDL into your app (which it looks like you already have), then you’d create an instance of the attachment object,set its body to the order blob, and set the parentId to be the id of the contact. So you’d need to update your custom UserRegistration call to return the created contactId, then you could do.

    salesforce.SessionHeaderValue = new SforceService.SessionHeader();
    salesforce.SessionHeaderValue.sessionId = loginResult.sessionId;
    salesforce.Url = loginResult.serverUrl;
    ...
    String contactId = mySFervive.UserRegistration(....);
    Attachment a = new Attachment();
    a.Body = readFileIntoByteArray(someFile);
    a.parentId = contactId;
    a.Name = "Order #1";
    
    SaveResult sr = salesforce.create(new SObject [] {a})[0];
    if (sr.success){ 
    // sr.id contains id of newly created attachment
    } else {
     //sr.errors[0] contains reason why attachment couldn't be created.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need add Auto complete on apex Tabular Form. there is a column as
I need add a new user group for mediawiki. The new group has more
I can't access a element with its href. Like this example, i need add
Need to add two same name .csproj class libraries in my solution.Have two project
I have a SharePoint List to which I'm adding new ListItems using the Client
I need to make a table such that the user can add attachment links
I'm using this piece of code I found ( http://impnerd.com/wordpress-hack-add-post-images-to-your-homepage ) to display the
Create an instance from another one of different kind/class. Quick example: you are using
Through the website, I need to allow the user to add attachments and store
Hї! I have wrote test for my application. I need add item to database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.