1

I've faced an issue. I'm trying to create a method to update a requirement in Salesforce. (I'm using Selenium - Java) and I have the following error. " The method update(com.sforce.soap.enterprise.sobject.SObject[]) in the type EnterpriseConnection is not applicable for the arguments (com.sforce.async.SObject[]) Type mismatch: cannot convert from Requirement__c to SObject".

 static EnterpriseConnection connection = GetConnection();

    private static EnterpriseConnection GetConnection()
    {
    String username = "aaa";
    String password = "aaa";
    String authEndPoint = "aaa";

    try
    {
    ConnectorConfig config = new ConnectorConfig();
    config.setUsername(username);
    config.setPassword(password);
    config.setAuthEndpoint(authEndPoint);

    return new EnterpriseConnection(config);
    }
    catch (ConnectionException ce)
    {
    ce.printStackTrace();
    }

    return null;
    }

    public static class forceLogin1
    {
          
    public boolean loginSample() {
           boolean success = false;
           String username = "aaa";
           String password = "aaa!";
           String authEndPoint = "aaa";
         
           try {
              ConnectorConfig config = new ConnectorConfig();
              config.setUsername(username);
              config.setPassword(password);        
         
              System.out.println("AuthEndPoint: " + authEndPoint);
              config.setAuthEndpoint(authEndPoint);
         
              EnterpriseConnection connection = new EnterpriseConnection(config);
         
            
              com.sforce.soap.enterprise.GetUserInfoResult userInfo = connection.getUserInfo();
              System.out.println("UserID: " + userInfo.getUserId());
              System.out.println("User Full Name: " + userInfo.getUserFullName());
              System.out.println("User Email: " + userInfo.getUserEmail());
              System.out.println();
              System.out.println("SessionID: " + config.getSessionId());
              System.out.println("Auth End Point: " + config.getAuthEndpoint());
              System.out
                    .println("Service End Point: " + config.getServiceEndpoint());
              System.out.println();
         
              success = true;
           } catch (ConnectionException ce) {
              ce.printStackTrace();
           }
         
           return success;
        }
    }
    
    public static void updateRequirements(String oppId) {
        
        try{  
        Requirement__c updateRequirement  = new Requirement__c();
    
           updateRequirement.setId(oppId);
           updateRequirement.setStatus__c("Pending");
           SaveResult[] results = connection
                    .update(new SObject[] { updateRequirement  });
           } 
    catch (ConnectionException ce) {
              ce.printStackTrace();
           }
        }

Imports:

import com.sforce.async.SObject;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.sobject.Requirement__c;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;

Can anyone help me with a solution? Great thanks

2
  • You mismatched the connector and the sObject that you're using. You need to make sure you're importing the right objects in your source. Unfortunately, given the limited amount of code you provided, we cannot provide a full answer other than "check your work." If you want more help, you can edit your question to include additional code. Commented Sep 26, 2021 at 18:25
  • Thanks @sfdcfox. I edited. Commented Sep 26, 2021 at 18:45

1 Answer 1

1

Try the below code,

SaveResult[] results = connection.update(new Requirement__c[] {updateRequirement});

Notice that instead of generic SObject, I am using the array of Requirement__c

2
  • Thanks a lot. it's working now Commented Sep 26, 2021 at 19:35
  • @Test please mark the answer as answered so it helps anyone that comes here to know it was right answer Commented Sep 26, 2021 at 19:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.