function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
santhoshgsanthoshg 

List has more than 1 row for assignment Sobject

Hi All

 

The following SOQL query shows the "List has more than 1 row for assignment Sobject".

 

PLS help me

 

list<contact> ct=[select lastname,firstname,account.name,account.industry from contact where Title='salesforce'];
system.debug(ct.lastname);
system.debug(ct.account.name);
system.debug(ct.account.industry);

 

 

thanks

santhos

Gaurav-GuleriaGaurav-Guleria

use index in system.debug:
system.debug(ct[0].lastname);
system.debug(ct[0].account.name);
system.debug(ct[0].account.industry);

vbsvbs
Santhoshg - 'ct' is a list variable and values will have to accessed like an array. Try this:
system.debug(ct[0].lastname); OR
system.debug(ct.get(0).lastname);

Although the error should not be what is displayed here.
hpereirahpereira

You should iterate throw the list:

 

list<contact> ct=[select lastname,firstname,account.name,account.industry from contact where Title='salesforce'];

for (contact c : ct) {
system.debug(c.lastname);
system.debug(c.account.name);
system.debug(c.account.industry);

}

 

Regards

hpereirahpereira
Hello Santhos,
Could you give kudos to my reply (click the star), if it helped you?
Thanks,
Hugo