• Ramesh Gudepu
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
public class CustomApp {
MetadataConnection metadataconnection;
ConnectorConfig metaConfig;

private void disableCustomApp(String endpoint, String metaUserName, String metaPassword) throws Exception {
  getMetaConnection( endpoint, metaUserName, metaPassword);
  Profile profile = new Profile();
     profile.setFullName("Admin");
     ProfileApplicationVisibility appVisibility =new ProfileApplicationVisibility();
        appVisibility.setApplication("Sales Automation");
        appVisibility.setVisible(true);
        profile.setApplicationVisibilities(new ProfileApplicationVisibility[] {appVisibility});
  AsyncResult[] asyncResults = this.metadataconnection.create(new Metadata[] {profile});
  if (asyncResults == null) {
    System.out.println("The custom app was not disabled successfully");
   return;
  }
  do {
   printAsyncResultStatus(asyncResults);
   Thread.sleep(2000);
   asyncResults = this.metadataconnection.checkStatus(new String[] {asyncResults[0].getId()});
  }
  while (!asyncResults[0].isDone());
  if(asyncResults[0].getState().equals("completed")){
   System.out.println("The custom app was disabled successfully");
  }
  printAsyncResultStatus(asyncResults);
}

private void printAsyncResultStatus(AsyncResult[] asyncResults) throws Exception {
  if (asyncResults == null || asyncResults.length == 0 || asyncResults[0] == null) {
   throw new Exception("The object status cannot be retrieved");
  }
  AsyncResult asyncResult = asyncResults[0];
  if (asyncResult.getStatusCode() != null) {
  }
  System.out.println("Object with id:" + asyncResult.getId() + " is " + asyncResult.getState());
  System.out.println("Object with id:" + asyncResult.getId() + " is " + asyncResult.getMessage());
}

public void getMetaConnection(String endpoint, String metaUserName, String metaPassword){
  try {
      metaConfig = new ConnectorConfig();
   metaConfig.setServiceEndpoint(endpoint);
   metaConfig.setManualLogin(true);
   LoginResult loginResult = new EnterpriseConnection(metaConfig).login(metaUserName, metaPassword);
   metaConfig.setServiceEndpoint(loginResult.getMetadataServerUrl());
   metaConfig.setSessionId(loginResult.getSessionId());
   metadataconnection = new MetadataConnection(metaConfig);
  } catch (ConnectionException ce) {
   throw new RuntimeException("INVALID_LOGIN", ce);
  }
}

Error :
Object with id:04si0000000xDFWAA2 is InProgress
Object with id:04si0000000xDFWAA2 is null
Object with id:04si0000000xDFWAA2 is Error
Object with id:04si0000000xDFWAA2 is duplicate value found: <unknown> duplicates value on record with id: <unknown>
    
i need a help on to list the package names in the salesforce organization
public class CustomApp {
MetadataConnection metadataconnection;
ConnectorConfig metaConfig;

private void disableCustomApp(String endpoint, String metaUserName, String metaPassword) throws Exception {
  getMetaConnection( endpoint, metaUserName, metaPassword);
  Profile profile = new Profile();
     profile.setFullName("Admin");
     ProfileApplicationVisibility appVisibility =new ProfileApplicationVisibility();
        appVisibility.setApplication("Sales Automation");
        appVisibility.setVisible(true);
        profile.setApplicationVisibilities(new ProfileApplicationVisibility[] {appVisibility});
  AsyncResult[] asyncResults = this.metadataconnection.create(new Metadata[] {profile});
  if (asyncResults == null) {
    System.out.println("The custom app was not disabled successfully");
   return;
  }
  do {
   printAsyncResultStatus(asyncResults);
   Thread.sleep(2000);
   asyncResults = this.metadataconnection.checkStatus(new String[] {asyncResults[0].getId()});
  }
  while (!asyncResults[0].isDone());
  if(asyncResults[0].getState().equals("completed")){
   System.out.println("The custom app was disabled successfully");
  }
  printAsyncResultStatus(asyncResults);
}

private void printAsyncResultStatus(AsyncResult[] asyncResults) throws Exception {
  if (asyncResults == null || asyncResults.length == 0 || asyncResults[0] == null) {
   throw new Exception("The object status cannot be retrieved");
  }
  AsyncResult asyncResult = asyncResults[0];
  if (asyncResult.getStatusCode() != null) {
  }
  System.out.println("Object with id:" + asyncResult.getId() + " is " + asyncResult.getState());
  System.out.println("Object with id:" + asyncResult.getId() + " is " + asyncResult.getMessage());
}

public void getMetaConnection(String endpoint, String metaUserName, String metaPassword){
  try {
      metaConfig = new ConnectorConfig();
   metaConfig.setServiceEndpoint(endpoint);
   metaConfig.setManualLogin(true);
   LoginResult loginResult = new EnterpriseConnection(metaConfig).login(metaUserName, metaPassword);
   metaConfig.setServiceEndpoint(loginResult.getMetadataServerUrl());
   metaConfig.setSessionId(loginResult.getSessionId());
   metadataconnection = new MetadataConnection(metaConfig);
  } catch (ConnectionException ce) {
   throw new RuntimeException("INVALID_LOGIN", ce);
  }
}

Error :
Object with id:04si0000000xDFWAA2 is InProgress
Object with id:04si0000000xDFWAA2 is null
Object with id:04si0000000xDFWAA2 is Error
Object with id:04si0000000xDFWAA2 is duplicate value found: <unknown> duplicates value on record with id: <unknown>
    
public class CustomApp {
MetadataConnection metadataconnection;
ConnectorConfig metaConfig;

private void disableCustomApp(String endpoint, String metaUserName, String metaPassword) throws Exception {
  getMetaConnection( endpoint, metaUserName, metaPassword);
  Profile profile = new Profile();
     profile.setFullName("Admin");
     ProfileApplicationVisibility appVisibility =new ProfileApplicationVisibility();
        appVisibility.setApplication("Sales Automation");
        appVisibility.setVisible(true);
        profile.setApplicationVisibilities(new ProfileApplicationVisibility[] {appVisibility});
  AsyncResult[] asyncResults = this.metadataconnection.create(new Metadata[] {profile});
  if (asyncResults == null) {
    System.out.println("The custom app was not disabled successfully");
   return;
  }
  do {
   printAsyncResultStatus(asyncResults);
   Thread.sleep(2000);
   asyncResults = this.metadataconnection.checkStatus(new String[] {asyncResults[0].getId()});
  }
  while (!asyncResults[0].isDone());
  if(asyncResults[0].getState().equals("completed")){
   System.out.println("The custom app was disabled successfully");
  }
  printAsyncResultStatus(asyncResults);
}

private void printAsyncResultStatus(AsyncResult[] asyncResults) throws Exception {
  if (asyncResults == null || asyncResults.length == 0 || asyncResults[0] == null) {
   throw new Exception("The object status cannot be retrieved");
  }
  AsyncResult asyncResult = asyncResults[0];
  if (asyncResult.getStatusCode() != null) {
  }
  System.out.println("Object with id:" + asyncResult.getId() + " is " + asyncResult.getState());
  System.out.println("Object with id:" + asyncResult.getId() + " is " + asyncResult.getMessage());
}

public void getMetaConnection(String endpoint, String metaUserName, String metaPassword){
  try {
      metaConfig = new ConnectorConfig();
   metaConfig.setServiceEndpoint(endpoint);
   metaConfig.setManualLogin(true);
   LoginResult loginResult = new EnterpriseConnection(metaConfig).login(metaUserName, metaPassword);
   metaConfig.setServiceEndpoint(loginResult.getMetadataServerUrl());
   metaConfig.setSessionId(loginResult.getSessionId());
   metadataconnection = new MetadataConnection(metaConfig);
  } catch (ConnectionException ce) {
   throw new RuntimeException("INVALID_LOGIN", ce);
  }
}

Error :
Object with id:04si0000000xDFWAA2 is InProgress
Object with id:04si0000000xDFWAA2 is null
Object with id:04si0000000xDFWAA2 is Error
Object with id:04si0000000xDFWAA2 is duplicate value found: <unknown> duplicates value on record with id: <unknown>
    
i need a help on to list the package names in the salesforce organization
I can successfully create an object and tab using the metadata API.  However, the tab isn't visible by default (uh), so I have to change the user profile information to correct.

However, when I try and do this using the update() method I get
UNKNOWN_EXCEPTION
An unexpected error occurred.

Can you tell me how to do the tab visibility update?  Am I doing something wrong?

Profile p = new Profile();
ProfileTabVisibility ptv = new ProfileTabVisibility("MyCustomObject__c",TabVisibility.DefaultOn );
ProfileTabVisibility[] tabVisibilities = new ProfileTabVisibility[] {ptv };
p.setTabVisibilities(tabVisibilities);
UpdateMetadata pum = new UpdateMetadata("Admin", p);
AsyncResult[] ars3 = (AsyncResult[]) metadatabinding.update(new UpdateMetadata[] { pum });

 The tab does exist, it does have that name, and the "Admin" profile does exist.

Thanks
Jon