Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

My Apex class is

Class1:

      Public class myclass{
             //some code
           public void save(){
                invoice_policy__c inp=[select net__c,Internal_alerts__c,Send_Email__c,Email_Alerts__c,Send_To__c from invoice_policy__c where id=:selectin]; //getting error here
         if(inp.Internal_alerts__c == true){
             //some code

           }
       }
string Selectin;
Public string getSelectin(){return Selectin;}
public void setSelectin(string selectin){this.selectin = Selectin;}

       public list<selectoption> getselectname()
      {
          list<selectoption> option = new list<selectoption>();  

         for(Invoice_Policy__c invoice : [select id,name,Policy_Status__c from Invoice_Policy__c where Policy_Status__c='Active'] )  
          {       

             option.add(new selectoption(invoice.Id,invoice.name));
              system.debug('invocenameee'+invoice.Id);  
              }
            return option;     
     } 
   }

My test class is

invoice_policy__c ip = new invoice_policy__c(name='TestPolicy',net__c='3',Policy_Status__c='Active',send_to__c='[email protected]',Email_Alerts__c='Before',Internal_Alerts__c =true);
        ip.send_email__c='2';
        insert ip;
        system.debug('testttt'+ip);

         myclass ic = new myclass();
        ic.getselectin();
        ic.setselectin('a0Wi0000000NMqbEAG');
        ic.save();

Getting error as System.QueryException List has no rows for assignment to SObject Help on this pls

share|improve this question
1  
you dont want to rely on setAllData, better setup your own data. but besides that, what does the following print out to the console? public class myclass2{ public void myMethod1(string strid,string invoiceid){ invoice__c invoice=[select Name,guid__c,invoice_contact__c,status__C from invoice__c where id=:invoiceid]; system.debug('###invoice=' + invoice); ... } } – Seb__Wagner May 15 at 13:00
If I don'y use seealldata=true,getting QueryException somewhere else in my code.Whatever Id I'm passing in my first class myclass those related fields are displayed in Invoice – Eagerin Sf May 15 at 13:06
Unit tests should exercise your methods as users would; why not just mimic the normal program flow? – Mike Chale May 15 at 13:07
1  
On why seealldata=true is a bad idea: salesforce.stackexchange.com/a/8562/142 – Mike Chale May 15 at 13:08
1  
Why are you setting selectin to a hardcoded ID field? ic.setselectin('a0Wi0000000NMqbEAG'); in a testmethod you should never refer to hard coded IDs. Seems like you want ic.setselectin(ip.id) – crop1645 Jun 12 at 1:51
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.