0

I am trying to create a new user inside of Salesforce using nforce. However, every time I create the user I get the error: FIELD_INTEGRITY_EXCEPTION stating Profile ID: id value of incorrect type: 005210026VpWAAUAQ4 or I receive INVALID_CROSS_REFERENCE_KEY with a message of invalid cross reference id. Which message I receive depends on the value I have set for profileId, 005210026VpWAAUAQ4 causes a FIELD_INTEGRITY_EXCEPTION while 00e36000000YIZ6AAO causes an INVALID_CROSS_REFERENCE_KEY. Any ideas on how to solve the errors and create a new user?

var acc = nforce.createSObject('User');
acc.set('ProfileId', '00e36000000YIZ6AAO'); // throws error here
  • 1
    That profile id is incorrect validate it by running a soql on profile – Avijit Chakraborty Jan 19 at 5:01
  • though this is valid id (profile type) but it is not from same sandbox where you are running your code. make sure you see this record using soql. – Himanshu Jan 19 at 5:16
  • @AvijitChakraborty What would that look like, I only started using the Salesforce api a few days ago, would it be similar to my other soql command: var q = "SELECT Id FROM User WHERE Username = 'swheeler@test.kanban'"? – Seth Wheeler Jan 19 at 8:58
  • 1
    The query string would be e.g. select Id from Profile where Name = 'Standard User'. – Keith C Jan 19 at 9:10
  • 1
    Generally, profiles are not created on the fly. Query to get the Id of the relevant profile that you have already set up in the org. – Keith C Jan 19 at 11:21
0

After lots of help from the community, I realized new users in salesforce have to be tied to a profile. Unfortunately, I was not aware profiles and users were different objects in Salesforce.

My Solution:

var q = "SELECT Id FROM Profile WHERE Name = 'Test_Profile'";

org.query({
            query: q
        }, function(err, resp) {
            var acc = nforce.createSObject('User');
            acc.set('ProfileId', resp.records[0]._fields.id);

            org.insert({
                sobject: acc
            }, function(err, resp) {
                if (!err) 
                    console.log('It worked!');
                else
                    console.log(err);
            });

        });

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.