+ Start a Discussion
Peter MitchellPeter Mitchell 

SOAP API:Can't create a record due to "not an External ID or indexed field" error

I'm new to SalesForce and new to using the SOAP API to create a record. I am trying to create a Case and link it to an Account, but nothing I have tried has worked yet. Error received:

"ERROR creating record: Field name provided, Id is not an External ID or indexed field for Account"

I have read the documentation on "create() and Foreign Keys" and followed the example code. (This is in Java.) As far as I can tell the Account Id field is what is used to link the Case to the Account. If I query the Case for Case.AccountId equal to the value in Account.Id I get a list of Case records. But when I try to create a Case with the Account Id I get the error shown.

I have used describeSObjects() to look at all the fields in Account and Case, but I don't see anything that indicates external id or index. I thought that if the Case records are already linked by Account Id then it would be set, but that is not seeming to be true. How can I find this out?

Thanks,
Peter
Best Answer chosen by Peter Mitchell
Terence_ChiuTerence_Chiu
From the setup menu, can you go to Customize->Cases->Fields and from the Case Standard Fields section click on the Account Name field ? From there click on the Set Field-Level Security field. Can you verify that the profiles have the Visible checkboxes selected and not the Read Only checkboxes ?

All Answers

Terence_ChiuTerence_Chiu
Would you be able to share a code snippet of how you are creating the Case records and assigning them the record Id of an Account record ? Thanks.

 
Peter MitchellPeter Mitchell
Here is the test method:
 
// create a test case
private static void createCase() {
	Case clientCase = new Case();
	Case[] records = new Case[1];
	EnterpriseConnection salesforceConnection;
	ConnectorConfig config = new ConnectorConfig();
	Account clientAccount = new Account();
	Account caseParentAccount = new Account();
	String accountLinkId = "";

	config.setUsername( "name" );
	config.setPassword( "pass" );

	// create the record in Salesforce.com
	try {
		salesforceConnection = Connector.newConnection( config );

		QueryResult queryResults = salesforceConnection.query( "SELECT Id, Name, Account_ID_Number__c, MasterRecordId "
															   + "FROM Account WHERE Name = 'Account Name' LIMIT 5" );
		if ( queryResults.getSize() > 0 ) {
			clientAccount = (Account) queryResults.getRecords()[0];
			accountLinkId = clientAccount.getId();
		}
		// fill in the case details
		caseParentAccount.setId( accountLinkId );
		clientCase.setAccount( caseParentAccount );
		clientCase.setStatus( "_New" );

		clientCase.setSubject( "Test Case" );
		clientCase.setDescription( "Test Case" );

		// add the case to the record set that will be sent in SalesForce api call
		records[0] = clientCase;

		// create the records in Salesforce.com
		SaveResult[] saveResults = salesforceConnection.create( records );

		// check the returned results for any errors
		for ( int i = 0; i < saveResults.length; i++ ) {
			if ( saveResults[i].isSuccess() ) {
				System.out.println( i + ". Successfully created record - Id: " + saveResults[i].getId() );
			} else {
				Error[] errors = saveResults[i].getErrors();
				for ( int j = 0; j < errors.length; j++ ) {
					System.out.println( "ERROR creating record: " + errors[j].getMessage() );
				}
			}
		}

	} catch ( Exception e ) {
		e.printStackTrace();
	}

}

 
Terence_ChiuTerence_Chiu
Have you tried using the setAccountId method instead ?
if ( queryResults.getSize() > 0 ) { 
            clientAccount = (Account) queryResults.getRecords()[0];  
            accountLinkId = clientAccount.getId(); 
        } 

        // fill in the case details 
        caseParentAccount.setId( accountLinkId ); 
        //clientCase.setAccount( caseParentAccount );
        clientCase.setAccountId(accountLinkId);
        clientCase.setStatus( "_New" );


 
Peter MitchellPeter Mitchell
I tried using setAccountId and get the following error:

ERROR creating record: Unable to create/update fields: AccountId. Please check the security settings of this field and verify that it is read/write for your profile or permission set.

When I look at Field Accessibility under Security Controls I don't see AccountId as one of the fields. How can I verify and set it if it doesn't show in list?

Also, from the documentation and sample code I got the impression that to set the AccountId I needed to create an Account object with the ID field set and then add the Account to the Case. The problem there is that it says the field is not external or not indexed.

Any other ideas?
Terence_ChiuTerence_Chiu
From the setup menu, can you go to Customize->Cases->Fields and from the Case Standard Fields section click on the Account Name field ? From there click on the Set Field-Level Security field. Can you verify that the profiles have the Visible checkboxes selected and not the Read Only checkboxes ?
This was selected as the best answer