0

Ok I know that this king of question have been aloready asked, but I still can't find the issue...

So I have a test class like this :

@testSetup static void init(){
    Profile p = new Profile(Name = 'Standard User');  

    User u = new User(Alias = 'standt', Email='[email protected]', //ProfileId = profileId.id,
                      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
                      LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');

    Account account = new Account(Name = 'account test');
    insert account;

    Opportunity opp = new Opportunity(Name = 'opp', Account = account);
    insert opp;
}
@isTest static void DevisToFactureTest(){
    //Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];

   //the error point out this line
    User u = [SELECT Id FROM User WHERE LastName='Testing'];

    Account account = [SELECT Id FROM Account WHERE Name = 'account test' LIMIT 1];

    Opportunity opportunity = [SELECT Id FROM Opportunity WHERE Name = 'opp' LIMIT 1];

    Schema.DescribeSObjectResult cfrSchema = Schema.SObjectType.Quote; 
    Map<String,Schema.RecordTypeInfo> AccountRecordTypeInfo = cfrSchema.getRecordTypeInfosByName(); 
    Id rtId = AccountRecordTypeInfo .get('abc').getRecordTypeId();

    Quote q= new Quote(Name = 'test', OpportunityId = opportunity.Id, RecordTypeId = rtId);
    insert q;
}

And I got the error when I run the test class

0

1 Answer 1

4

You didn't insert the user in testsetup method :p

Following would work for you.

@testSetup static void init(){
    Profile p = new Profile(Name = 'Standard User');  

    User u = new User(Alias = 'standt', Email='[email protected]', //ProfileId = profileId.id,
                      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
                      LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
    Insert u;

    Account account = new Account(Name = 'account test');
    insert account;

    Opportunity opp = new Opportunity(Name = 'opp', Account = account);
    insert opp;
}
2
  • 1
    ohh lol. even i missed that part. nice catch man
    – Ratan Paul
    Commented Oct 6, 2016 at 10:47
  • @dou You are welcome.Please mark answer correct to close this question.
    – Mr.Frodo
    Commented Oct 6, 2016 at 11:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .