• alex_berg
  • NEWBIE
  • 59 Points
  • Member since 2012
  • Software Builder


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies

I am trying to create a partner portal user in a unit test., but having terrible difficulties. I understand that I must create a Contact and Account first, ensure the Account is a partner account, then create a user that points to the contact. However, I am unable to create a user that points to a contact.

 

 

Contact contact1 = new Contact(LastName = 'TestContact');
 Database.insert(contact1);
 Account account1 = new Account(Name = 'TestAccount');
 Database.insert(account1);
 account1.IsPartner = true;
 Database.update(account1);
 Profile profile1 = [Select Id from Profile where name = 'System Administrator'];
 UserRole userRole1 = new UserRole(
 	PortalType = 'Partner',
 	//PortalRole = 'Test',
 	//Name = 'Test Portal Role',
 	PortalAccountId = account1.Id
 );
 Database.insert(userRole1);
 User user1 = new User(
 	//IsPortalEnabled = true, // 4) Compiler says Field is not writeable.
 	//ContactId = contact1.Id, // 3) Runtime says Only Portal Users can be associated to a Contact.
 	UserType = 'PowerPartner', // 2) Compiler says field not writeable.
 	UserRoleId = userRole1.Id,
 	Username = System.now().millisecond() + 'test12345@test.com',
 	LastName = 'McTesty',
 	Email = 'test12345@test.com',
 	Alias = 'test123',
 	CommunityNickname = 'test12345',
 	TimeZoneSidKey = 'America/Los_Angeles',
 	LocaleSidKey = 'en_US',
	EmailEncodingKey = 'UTF-8',
	ProfileId = profile1.Id,
	LanguageLocaleKey = 'en_US'
);
Database.insert(user1);
//user1.IsPartner = true;
//user1.IsPortalEnabled = true;
//Database.update(user1);
//user1.ContactId = contact1.Id; // 1) Runtime says role type must match user type.
//Database.update(user1);

 

 

Can anyone paste some working code for this? Or maybe I'm making an obvious mistake?

 

I created a Platform Event in my scratch org. When I try to pull it into source, I get the error:
ERROR:  Cannot retrieve translation for object:[my platform event name].
Translation is not enabled on the scratch org, and I don't need it.

I tried to .forceignore it, no-go. I can't pull the other things from my scratch org in that I need. I don't know where/how to fix this in the scratch org. I'm stuck...  

Has anyone created a simple connector to toggl time tracking?  For example, I would like to drop a button on a case "Track Time" and have it open a Toggl session with Project = Case #.

  • November 17, 2012
  • Like
  • 0

I am trying to create a partner portal user in a unit test., but having terrible difficulties. I understand that I must create a Contact and Account first, ensure the Account is a partner account, then create a user that points to the contact. However, I am unable to create a user that points to a contact.

 

 

Contact contact1 = new Contact(LastName = 'TestContact');
 Database.insert(contact1);
 Account account1 = new Account(Name = 'TestAccount');
 Database.insert(account1);
 account1.IsPartner = true;
 Database.update(account1);
 Profile profile1 = [Select Id from Profile where name = 'System Administrator'];
 UserRole userRole1 = new UserRole(
 	PortalType = 'Partner',
 	//PortalRole = 'Test',
 	//Name = 'Test Portal Role',
 	PortalAccountId = account1.Id
 );
 Database.insert(userRole1);
 User user1 = new User(
 	//IsPortalEnabled = true, // 4) Compiler says Field is not writeable.
 	//ContactId = contact1.Id, // 3) Runtime says Only Portal Users can be associated to a Contact.
 	UserType = 'PowerPartner', // 2) Compiler says field not writeable.
 	UserRoleId = userRole1.Id,
 	Username = System.now().millisecond() + 'test12345@test.com',
 	LastName = 'McTesty',
 	Email = 'test12345@test.com',
 	Alias = 'test123',
 	CommunityNickname = 'test12345',
 	TimeZoneSidKey = 'America/Los_Angeles',
 	LocaleSidKey = 'en_US',
	EmailEncodingKey = 'UTF-8',
	ProfileId = profile1.Id,
	LanguageLocaleKey = 'en_US'
);
Database.insert(user1);
//user1.IsPartner = true;
//user1.IsPortalEnabled = true;
//Database.update(user1);
//user1.ContactId = contact1.Id; // 1) Runtime says role type must match user type.
//Database.update(user1);

 

 

Can anyone paste some working code for this? Or maybe I'm making an obvious mistake?