• Abhinav MIshra
  • NEWBIE
  • 70 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 12
    Replies
How to Create UserRole in Test Class.
We have to create a User in the test class and have to assign UserRole to that user.
UserRole portalRole = [Select Id From UserRole Where PortalType = 'None' Limit 1];
User u1 = new User(FirstName = 'test',LastName='user', Alias='test', CommunityNickName='test'+generateRandomString(), Title='Inside Energy Advisor',
                          Division='Test Granite Bay', EmailEncodingKey='UTF-8',LanguageLocaleKey='en_US',LocaleSidKey='en_US',
                          TimeZoneSidKey='America/Los_Angeles', Country = 'US', ProfileId = p.Id, EmployeeNumber= '1234',  UserRoleId = portalRole.Id,isActive = true);
        
        u1.UserName = 'testUser-' + generateRandomString() + '@test.com';
        u1.Email = 'testUser-' + generateRandomString() + '@test.com';
        User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];

    System.runAs (thisUser) {

        insert u1;
    }
       
      
        User u2 = new User(FirstName = 'First', LastName='Last', Alias='test', CommunityNickName='test'+generateRandomString(), Title='Inside Energy Advisor',
                          Division='Granite Bay', EmailEncodingKey='UTF-8',LanguageLocaleKey='en_US',LocaleSidKey='en_US',
                          TimeZoneSidKey='America/Los_Angeles', Country = 'US', ProfileId = p.Id, EmployeeNumber= '12345',Supervirory_Org_ID__c = 'SUP8.12786', Job_Code__c = 926,isActive = true);
       
    	u2.UserName = 'testUser1-' + generateRandomString() + '@test.com';
        u2.Email = 'testUser1-' + generateRandomString() + '@test.com';
   		u2.ManagerId = u1.Id;
        System.runAs (thisUser) {
        insert u2;
         
        }
        User us = [SELECT id,  UserRole.Name, Manager.FirstName,Email, Manager.Id, Manager.UserRoleId,Manager.UserRole.Name from User where id = :u2.Id];

We are getting the ManagerId in the last query but unable to get the Manager.FirstName,Manager.UserRoleId and Manager.UserRole.Name .
Can we create UserRole in Test Class and assign it to the User ?
If yes then how.
Please Suggest.
how to find profile name of current user in trigger and how to write the test class for that trigger
Can anybody share the C# bulk (query, insert, update, delete) api examples. Online i can find Java exaples, but not C#.

-Sid
In which scenerios this cases will be used in individual case?

I have two salesforce developer accounts and I create a class with web service method in one of the developer org and want other developer org to invoke this class method using the SOAP Web Service. How can I achieve it?

To put it again: How can the web services in one developer org ( or any salesforce org) can be consumed/used/invoked by other developer org?

I am kind of new to web services but needs a heads up like how to get started.

Hi all,

I have this kind of problem:
when I run tests, they stuck with status "Queued".
I've been waiting for 40-50 min.
User-added image

Thanks.
Hi All,

I am relatively new to salesforce and am still learning the ropes, hence pardon me for any stupid question. My assignment now is to build something in lightning and run it in mobile.

My questions are:

is it possible to develop a lighting component [i assume the snd result is html5 and js] and wrap it around a mobile app. [say android java !]
what would be my approach to start with a simple app and then extend it further ?

thanks and regards
jagat

Posting this in order to help others who, months from now, might Google "OP_WITH_INVALID_USER_TYPE_EXCEPTION" and find this explanation.

 

We wrote an Apex trigger on the User object, to insert a custom object record anytime a user updates their Chatter status.  This was done to fulfill a client's requirement to audit all Chatter activity.

 

The trigger worked fine, until one day the client signed up some Chatter Free users.  When such a user tried to update their status, they got a pop-up with an OP_WITH_INVALID_USER_TYPE_EXCEPTION error.

 

We scratched our collective heads for awhile.  After all, Apex triggers run in "system mode," right?  That is supposed to mean that "object and field-level permissions of the current user are ignored."  And yet this trigger seemed like it was running in "user mode," enforcing restrictions based on who the current user was.

 

The root cause turned out to be that a Chatter Free user cannot be the owner of a custom object record, and SFDC by default sets the current user as a new record's first owner.  We discovered this when we realized, via experiment, that Apex triggers fired as the result of actions by Chatter Free users could definitely update an existing record, but were having problems creating records.

 

So the simple solution was to explicitly set the owner of the new record to some fully-licensed user prior to inserting it.