SFDC.SalesforceApi 1.0.0.3

This is salesforce package to create custom objects and custum fields using metadata.
     This package also contains some methods to create/update elements such as Opportunity, Account, CustomObjects__c

Install-Package SFDC.SalesforceApi -Version 1.0.0.3
dotnet add package SFDC.SalesforceApi --version 1.0.0.3
<PackageReference Include="SFDC.SalesforceApi" Version="1.0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SFDC.SalesforceApi --version 1.0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Code to Create Matadata Custom Fields:

@using SFDC

    SalesForceApi api = new SalesForceApi();
    var loginInfo = api.Login("abc@m.com", "********");

    ElementModel model = new ElementModel()
    {
        FullName = "Account.CustomFieldTest3__c",
        Type = FieldType.Url,
        Label = "CustomTest",
    };

    MetadataApi meta = new MetadataApi(loginInfo.sessionId,loginInfo.metadataServerUrl);
    UpsertResult[] result = meta.CreateCustomField(model);

Custom Objects :

    CustomObject co = new CustomObject();
    co.fullName = model.FullName.Replace(' ', '_') + "__c";
    co.deploymentStatus = DeploymentStatus.Deployed;
    co.deploymentStatusSpecified = true;
    co.description = model.Description;
    co.enableActivities = true;
    co.label = model.Label;
    co.pluralLabel = model.Label + "s";
    co.sharingModel = SharingModel.ReadWrite;
    co.sharingModelSpecified = true;

    co.fields = new CustomField[]{};
    co.nameField = new CustomField();
    co.nameField.label = model.Label;
    co.nameField.type = FieldType.Text;
    co.nameField.typeSpecified = true;
    UpsertResult[] result2 = meta.UpsertCustomObject(co);

Create/Update an actual Opportunity/Contact

   SalesForceApi api2 = new SalesForceApi("endPointUrl","sessionId");


    CreateSObject opportunity = new CreateSObject()
    {
        Type = "Opportunity",
        Fields = new List<ElementField>()
        {
            new ElementField()
            {
                Key = "Name",
                Value = "My New Opportunity Name"
            },
            new ElementField()
            {
                Key = "Amount",
                Value = "999"
            },
        }
    };

    SFDC.soapApi.SaveResult[] saveResults = api2.CreateElement(opportunity);


    UpdateSObject contact = new UpdateSObject()
    {
        Id = "0031W0000213yCzQAI",
        Type = "Contact",
        Fields = new List<ElementField>()
        {
            new ElementField()
            {
                Key = "FirstName",
                Value = "Otto"
            },
            new ElementField()
            {
                Key = "LastName",
                Value = "Jespersen"
            },
        }
    };

    SFDC.soapApi.SaveResult[] saveResults = api2.UpdateElement(contact);

Code to Create Matadata Custom Fields:

@using SFDC

    SalesForceApi api = new SalesForceApi();
    var loginInfo = api.Login("abc@m.com", "********");

    ElementModel model = new ElementModel()
    {
        FullName = "Account.CustomFieldTest3__c",
        Type = FieldType.Url,
        Label = "CustomTest",
    };

    MetadataApi meta = new MetadataApi(loginInfo.sessionId,loginInfo.metadataServerUrl);
    UpsertResult[] result = meta.CreateCustomField(model);

Custom Objects :

    CustomObject co = new CustomObject();
    co.fullName = model.FullName.Replace(' ', '_') + "__c";
    co.deploymentStatus = DeploymentStatus.Deployed;
    co.deploymentStatusSpecified = true;
    co.description = model.Description;
    co.enableActivities = true;
    co.label = model.Label;
    co.pluralLabel = model.Label + "s";
    co.sharingModel = SharingModel.ReadWrite;
    co.sharingModelSpecified = true;

    co.fields = new CustomField[]{};
    co.nameField = new CustomField();
    co.nameField.label = model.Label;
    co.nameField.type = FieldType.Text;
    co.nameField.typeSpecified = true;
    UpsertResult[] result2 = meta.UpsertCustomObject(co);

Create/Update an actual Opportunity/Contact

   SalesForceApi api2 = new SalesForceApi("endPointUrl","sessionId");


    CreateSObject opportunity = new CreateSObject()
    {
        Type = "Opportunity",
        Fields = new List<ElementField>()
        {
            new ElementField()
            {
                Key = "Name",
                Value = "My New Opportunity Name"
            },
            new ElementField()
            {
                Key = "Amount",
                Value = "999"
            },
        }
    };

    SFDC.soapApi.SaveResult[] saveResults = api2.CreateElement(opportunity);


    UpdateSObject contact = new UpdateSObject()
    {
        Id = "0031W0000213yCzQAI",
        Type = "Contact",
        Fields = new List<ElementField>()
        {
            new ElementField()
            {
                Key = "FirstName",
                Value = "Otto"
            },
            new ElementField()
            {
                Key = "LastName",
                Value = "Jespersen"
            },
        }
    };

    SFDC.soapApi.SaveResult[] saveResults = api2.UpdateElement(contact);

Release Notes

Summary of changes made in this release of the package.

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0.3 402 1/26/2018
1.0.0.2 656 1/26/2018
1.0.0.1 300 1/25/2018
1.0.0 269 1/25/2018