You need to sign in to do that
Don't have an account?
Ashw
System.QueryException: List has no rows for assignment to SObject Error is in expression '{!change}' in page preCall: Class.preCall_cls.Change: line 5, column 1
public with sharing class preCall_cls { public Void Change() { if(conId != '--None--'){ Contact obj = [select id,name,AccountId,Phone from Contact where name =: conId]; co.AccountId= obj.AccountId; co.Phone= obj.Phone; } else { ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Please select correct value'); apexpages.addmessage(myMsg); co.AccountId=''; co.Phone=''; } } public list<SelectOption> AccValues {get;set;} public Contact co {get;set;} public string conId {get;set;} public preCall_cls(){ AccValues = new List<SelectOption>(); list<Contact> lst = [select id,name,AccountId,Phone from Contact]; AccValues.add(new selectoption('--None--','--None--')); for(Contact con : lst){ AccValues.add(new selectoption(con.id,con.Name)); } co = new Contact(); //co = [select id,name,AccountId,Phone from Contact where name =: conId]; } }
In your case query on Account return nothing.
Your Contact name is uniqe or not ?
if not then write LIMIT 1 in your query.
Regards
Virendra
But still code is not working even phone field is also not populating
When user select any value from controller than you will get Id in controller not name sos in where clause you have to apply id instead of name
IF it helps you than please mark it as a solution and please like it ENJOY APEX