Activity Forums Salesforce® Discussions Can we insert the accountId in Community User?

  • Ravi

    Member
    July 29, 2016 at 7:00 am

    AccountId field is not writable for user you can link account through contact.

    here is the sample code this  might  help you .

    Id p = [select id from profile where name='Partner Community User'].id;

    Account ac = new Account(name ='Grazitti') ;
    insert ac;

    Contact con = new Contact(LastName ='testCon',AccountId = ac.Id);
    insert con;

    User user = new User(alias = 'test123', email='[email protected]',
    emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
    localesidkey='en_US', profileid = p, country='United States',IsActive =true,
    ContactId = con.Id,
    timezonesidkey='America/Los_Angeles', username='[email protected]');

    insert user;
    system.runAs(user) {
    // statements to be executed by this test user.
    }

    • This reply was modified 7 years, 8 months ago by  Ravi.
    • This reply was modified 7 years, 8 months ago by  Ravi.
    • This reply was modified 7 years, 8 months ago by  Ravi.
    • This reply was modified 7 years, 8 months ago by  Ravi.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos