• ao guo
  • NEWBIE
  • 0 Points
  • Member since 2019

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

I am trying to deploy some classes that I have updated, but when I deploy them I get an error from a test class that has nothing to do with the classes that I am deploying.  The purpose of the OverrideAccount class is to check to see if the current user should have access to the account or not.  If they should, then give them the standard account page, otherwise show them a VF page with limited data.

Error message from the deployment validation:
System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.OverrideAccount.<init>: line 17, column 1 Class.OverRideAccount_Test.OverRideAccount_test: line 56, column 1

Test Class code:
@isTest
public class OverRideAccount_Test {

    private static testmethod void OverRideAccount_test(){
        user[] u = [select id,name from user where isactive =:true and profile.name!=: 'System Administrator' limit 5];  
  
        // Create account with current logged in user (admin) as owner
        account a = new account() ;
        a.name = 'testName' ;
        a.ownerId = userinfo.getuserid() ;
        system.debug('a ==> '+ A) ;
        insert a ;

        // Create account with general user as owner
        account a1 = new account() ;
        a1.name = 'testName' ;
        a1.ownerId = u[0].id ;
        system.debug('a ==> '+ A1) ;
        insert a1 ;
        
     ...
     ...
    
        //test Override method as the admin
        Apexpages.Standardcontroller std = new ApexPages.StandardController( a) ;
        Apexpages.CurrentPage().getParameters().put( 'id',a.id ) ;
        overRideAccount oa = new overRideAccount(std) ;
        oa.redirect();
        getdomain.DomainURL() ;      
        
        //test Override method as a general user (not the a1 account owner)
        Apexpages.Standardcontroller std1 = new ApexPages.StandardController( a1) ;
        Apexpages.CurrentPage().getParameters().put( 'id',a1.id ) ;
        system.runas(u[2]){
line 56    overRideAccount oa1 = new overRideAccount(std1) ;
                oa1.redirect();
        }
     }
           
}

OverrideAccount Class code:
public account acct {get;set;}
    public account ContRecord {get;set;}
    public profile profile ;  
    public boolean showpage = true;
    Public userRole UserRole ;
    Public userRole loggedInUserRole ;
    Public user user ;
    Public User LoggedinUser ;
    public Id id ;       
    public string domainURL {get;set;}

    public OverrideAccount(apexPages.standardController controller){
          acct = (account)controller.getrecord() ;
          this.id = controller.getid() ;
line 17    ContRecord = [select id,name,ownerId,BillingAddress,ShippingAddress,Billing_Address__c,Shipping_Address__c,BillingStreet ,BillingCity,BillingState,BillingPostalCode,BillingCountry,
                                    ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry,CreatedBy.name,lastModifiedBy.name ,CreatedDate,createdby.id,lastmodifiedby.id,
                                    lastmodifieddate,Ultimate_Parent_Owner_ID__c,lastActivityDate,account_availability__c,Account_Link__c 
                                    from account where id = : acct.Id limit 1] ;     
        //domain URL for View hierarchy link on visualforce limited view page
        domainURL =  url.getSalesforceBaseUrl().toExternalForm(); 
        domainURL = getDomain.SfdchostName(); 
        system.debug('Domain URL ==>' + domainURL);
        user = [select id,name,UserRoleId,profileId from user where id =:ContRecord.OwnerId limit 1];
       
        Profile = [select id,name from profile where id = :userinfo.getprofileId() ];                 
        
        if(user!=null){
        UserRole = [select id,parentRoleId,DeveloperName,Name from UserRole where Id=:user.UserRoleId limit 1] ;
            if(UserRole != nuLL){
            LoggedinUser = [select id,name,UserRoleId,profileId from user where id =:userInfo.getUserId() limit 1];  
                if(LoggedinUser.UserRoleId != null){
                loggedInUserRole =  [select id,parentRoleId,DeveloperName,Name from UserRole where Id=:LoggedinUser.userroleId limit 1] ;
                }
            }
        }            
    }
Thanks for any help on this one and let me know if you need further information.

-Ben