You need to sign in to do that
Don't have an account?
Kunlun
Api for adding,deleting field in Object
I need to add and delete some fields in Account, I also need to set them value.
For example:
I want to do a loop to add field which name is in " filed1, field2,......fieldN "
I also need to do a loop to set value on " filed1, field2,......fieldN "
I can't make sure how many fields I should operate, so I don't know which number is "N".
Can I use api to do it?
For example:
I want to do a loop to add field which name is in " filed1, field2,......fieldN "
I also need to do a loop to set value on " filed1, field2,......fieldN "
I can't make sure how many fields I should operate, so I don't know which number is "N".
Can I use api to do it?
I had checked metadata help, and it likes as below.
CustomObject co = new CustomObject();
string name = "MyCustomObject";
co.fullName = name + "__c";
co.label = name + " Object";
CustomField nf = new CustomField();
nf.type = FieldType.Text;
nf.label = co.fullName + " Name";
co.nameField = nf;
AsyncResult[] ars = stub.create(new Metadata[] { co} );
what is stub? is it sfdc? sfdc only can create sObject[].
How can I add this customField into Account?
Thanks again.
CustomObject co = new CustomObject();
string name = "MyCustomObject";
co.fullName = name + "__c";
co.deploymentStatus = DeploymentStatus.Deployed;
co.description = "Created by the Metadata API";
co.enableActivities = true;
co.label = name + " Object";
co.pluralLabel = co.label + "s";
co.sharingModel = SharingModel.ReadWrite;
CustomField nf = new CustomField();
nf.type = FieldType.Text;
nf.label = co.fullName + " Name";
co.nameField = nf;
MetadataService stub = new MetadataService();
AsyncResult[] ars = stub.create(new Metadata[]{co});
but it throwed an error:INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session
And I should add this field into Account, Account is not a custom filed, how can I add them into Account?
null: Must specify a deployment status for the Custom Object
But I had set the deplyment status in my code.
CustomObject co = new CustomObject();
string name = "MyCustomObject1";
co.fullName = name + "__c";
co.deploymentStatus = DeploymentStatus.Deployed;
co.description = "Created by the Metadata API";
co.enableActivities = true;
co.label = name + " Object";
co.pluralLabel = co.label + "s";
co.sharingModel = SharingModel.ReadWrite;
CustomField nf = new CustomField();
nf.type = FieldType.Text;
nf.label = co.fullName + " Name";
co.nameField = nf;
AsyncResult[] ars = metaBinding.create(new Metadata[] { co });
I attempted to run that sample, and I received the following exception:
Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'SalesForceMetaDataAPI.metaforce.LayoutItem[]' to 'SalesForceMetaDataAPI.metaforce.LayoutItem'
The exception is thrown upon instantiating the MetadataService class: