• gaurav.d
  • NEWBIE
  • 0 Points
  • Member since 2011

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

hi  i m able to create records in salesforce standard objects . but can we create custom object in sales force and insert records in custom object using REST API.

hi,

 

 i m trying to create a custom field in to standard object  but it is creating in to standard fields  not in custom field.

 and second thing i m not able to create field type  exept Text and AutoNumber.   this is the code that i m using.

 

 

// create a new custom object
                String objectName = "Test4";
                String displayName = "Test4 Object";
                 
                CustomObject co = new CustomObject();
                co.setFullName(objectName+"__c");
                co.setDeploymentStatus(DeploymentStatus.Deployed);
                co.setDescription("Created by gaurav using the Metadata API");
                co.setLabel(displayName);
                co.setPluralLabel(displayName+"s");
                co.setSharingModel(SharingModel.ReadWrite);
                co.setEnableActivities(true);
                 
                // create the text id field
                String custom ="Test";
                CustomField field = new CustomField();
                field.setType(FieldType.Text);
                field.setDescription("The Gaurav");
                field.setLabel(displayName);
                field.setFullName(objectName+"__c");
                // add the field to the custom object
                co.setNameField(field);

 try {
                  // submit the custom object to salesforce
                  AsyncResult[] ars = metadataConnection.create(new CustomObject[] { co });
                  if (ars == null) {
                      System.out.println("The object was not created successfully");
                      return;
                  }
                   
                  String createdObjectId = ars[0].getId();
                  String[] ids = new String[] {createdObjectId};
                  boolean done = false;
                  long waitTimeMilliSecs = 1000;
                  AsyncResult[] arsStatus = null;
          /**
               * After the create() call completes, we must poll the results
               * of the checkStatus() call until it indicates that the create
               * operation is completed.
                   */
                  while (!done) {
                      arsStatus = metadataConnection.checkStatus(ids);
                      if (arsStatus == null) {
                          System.out.println("The object status cannot be retrieved");
                          return;
                      }
                      done = arsStatus[0].isDone();
                      if (arsStatus[0].getStatusCode() != null )  {
                          System.out.println("Error status code: "+arsStatus[0].getStatusCode());
                          System.out.println("Error message: "+arsStatus[0].getMessage());
                      }
                      Thread.sleep(waitTimeMilliSecs);
                      // double the wait time for the next iteration
                      waitTimeMilliSecs *= 2;
                      System.out.println("The object state is "+arsStatus[0].getState());
                  }
                   
              System.out.println("The ID for the created object is "+arsStatus[0].getId());
                }
                catch (Exception ex) {
                    System.out.println("\nFailed to create object, error message was: \n" +ex.getMessage());
                }
    
    }

 

hi,

 

i m creating web service to login in to salesforce and list up all the standard objects and their  fields .

 

now i m able to login in to salesforce through java code but not getting standard objects . please help me

how to list up standard objects of sales force through java code????

hi  i m able to create records in salesforce standard objects . but can we create custom object in sales force and insert records in custom object using REST API.

Hi All,

 

I have a Java app that communicates with Salesforce, and among other things, it creates custom fields in a custom object via the create() method of the Metadata API.

 

The Java app works fine with a Salesforce developer/sandbox org.

 

My questions is: will the same Java app work with a production org (Enterprise or Unlimited) ?.

 

Thanks in advance,

Fernando