• Thiyagarajan.Selvaraj
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies

Must be something very silly.But i get an error like this

14:17:59:040 FATAL_ERROR System.QueryException: List has more than 1 row for assignment to SObject

 

for code below

 

List<Contact> mylist = new list<Contact> {[select id from Contact ]};

 

Anyone can spot anything?

                 

 

 

hi all i have created one class that dynamically fetch student records.when i created test class it is not covering all code.

 

 

 

 

 public with sharing class DynamicStudent  

{

 public String allstdnames { get; set; }

   public String selectedstudId { get; set; }

   public string Id{get;set;} 

  public student__c stdinfo{get;set;} 

  public list<SelectOption> getallstds()    {

 list<selectOption> options=new list<selectOption>(); 

   list<student__c> allstds=[select id,name from student__c limit 10]; 

   for(integer i=0;i<allstds.size();i++) 

   { 

   options.add(new selectOption(allstds[i].id,allstds[i].name)); 

   } 

   return options; 

   } 

    public void res() 

    {

     stdinfo=[select id,name from student__c where id=: selectedstudId ]; 

   }

 

-------------------------------------------------------

@isTest
private class testdynamicstudent{

static testMethod void myTest() {

DynamicStudent ds=new DynamicStudent();
list<selectoption> opt=new list<selectOption>();


opt.add(new selectoption('a0490000002khRH','select123'));

ds.getallstds();
ds.res();
}

 

}

 

 

how to pass the select option values in getallstds method

help  me

thanks  in advance

    

Hi ,

 

I know this is quite naive question but when I went through all the posted solution still I am not understand  the concept very well.

Here is my snippet of my code:

 

System.debug('check variable =' + qtr + segment + accId ); 

List<MyAccount__c>  lstReport=[Select id , Segment__c,(Select id,Name__c from  Account_Competitor__r)from MyAccount__c  where Fiscal_Quarter__c=:qtr    and Segment__c in :segment and MyAccount__c=:accId];

if(lstReport==null){
            System.debug('if null should return here'); 
          	lstReport=new List<MyAccount__c> ();
           
}

 

 

 

I already run the query in the Force.com console and yes it return no data with the printed variable in System.debug('check variable =' + qtr + segment + accId );  .

 

So I expect it should be null, as it also throw me Attempt to de-reference a null.

 

But it didn't enter the condition if(lstReport==null). So what I should do to check it is  return null value? 

 

Thanks in advance

unidha

Hello Helpers

 

I would like to know  how  can I send email with attachment  from an apex class

 

I know  how  to send mails.

I sew articles about how  to attach a VFpage  rendered as pdf

 

but what I need is to attach a file  to my email

 

I am thinking to a static resource  

 

any suggestions?

 

regards

csbaa

 

  • April 21, 2013
  • Like
  • 0