You need to sign in to do that
Don't have an account?
Manoprabha Palpandian
my coding is running if i click the edit button showing an error
public class Registrationcontroller {
public Registration1__c reg1 {get;set;}
public String editid {get;set;}
public Hotel__c hotel {get;set;}
public AirTravel__c air {get;set;}
public Registrationcontroller()
{
reg1 = new Registration1__c();
hotel = new Hotel__c();
air = new AirTravel__c();
}
public List<Registration1__c> getregisterlist(){
List<Registration1__c> listreg= new List<Registration1__c>();
listreg=[SELECT Id, Name, FirstName__c, LastName__c, Email__c, (SELECT id,name FROM Hotels__r),
(SELECT id,name FROM AirTravels__r) FROM Registration1__c];
return listreg;
}
public void editfunction() {
system.debug('editfunction inside===>'+editid);
reg1=[SELECT Id,Name, FirstName__c, LastName__c, Email__c
FROM Registration1__c where id=:editid];
hotel=[SELECT Id,Name, Check_Out_Date__c, Check_In_Date__c, Hotel_Commands__c FROM Hotel__c where id=:editid];
air=[SELECT Id,Name, Arrival__c, Departure__c, Air_Commands__c FROM AirTravel__c where id=:editid];
}
public void deletefunction() {
system.debug('editfunction inside===>'+editid);
List<Registration1__c> reg2=[SELECT Id, Name, FirstName__c, LastName__c, Email__c
FROM Registration1__c where id=:editid];
List<Hotel__c> hotel1=[SELECT Id,Name, Check_Out_Date__c, Check_In_Date__c, Hotel_Commands__c FROM Hotel__c where id=:editid];
List<AirTravel__c> air1=[SELECT Id,Name, Arrival__c, Departure__c, Air_Commands__c FROM AirTravel__c where id=:editid];
delete reg2;
delete hotel1;
delete air1;
ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.INFO,'Record deleted successfully'));
}
public void saveaction()
{
system.debug('saveaction inside===>'+reg1);
try{
upsert reg1;
if(reg1.Id !=null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.INFO,'Record saved successfully'));
//reg1 = new Registration1__c();
if(hotel != null)
{
hotel.Registration1__c = reg1.id;
upsert hotel;
}
if(air != null)
{
air.Registration1__c = reg1.id;
upsert air;
}
} else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.ERROR,'Record not saved'));
}
}
Catch(Exception e)
{
System.debug(e.getMessage());
}
}
}
<apex:page controller="Registrationcontroller" id="theRepeat" sidebar="false" showHeader="true">
<apex:form >
<apex:pageBlock id="pg1" >
<apex:messages />
<apex:pageBlockSection columns="1" >
<apex:inputField label="FirstName" value="{!reg1.FirstName__c}"/>
<apex:inputField label="LastName" value="{!reg1.LastName__c}"/>
<apex:inputField label="Email" value="{!reg1.Email__c}"/>
<apex:inputField label="HoTel Commands" value="{!hotel.Hotel_Commands__c}"/>
<apex:inputField label="Air Commands" value="{!air.Air_Commands__c}"/>
<apex:inputField label="CheckInDate" value="{!hotel.Check_In_Date__c}"/>
<apex:inputField label="CheckOutDate" value="{!hotel.Check_Out_Date__c}"/>
<apex:inputField label="Arrival" value="{!air.Arrival__c}"/>
<apex:inputField label="Departure" value="{!air.Departure__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!saveaction}" rerender="pg1,theTable" />
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:pageBlock >
<apex:dataTable value="{!registerlist}" var="regvalue" id="theTable" width="100%">
<apex:facet name="caption">Registration List</apex:facet>
<apex:column headerValue="Reg ID"><apex:outputText value="{!regvalue.Name}" /> </apex:column>
<apex:column headerValue="FirstName"><apex:outputText value="{!regvalue.FirstName__c}" /> </apex:column>
<apex:column headerValue="LastName"><apex:outputText value="{!regvalue.LastName__c}" /> </apex:column>
<apex:column headerValue="Email"><apex:outputText value="{!regvalue.Email__c}" /> </apex:column>
<apex:repeat value="{!regvalue.Hotels__r}" var="c">
<apex:column value="{!c.Name}"/>
</apex:repeat>
<apex:repeat value="{!regvalue.AirTravels__r}" var="d">
<apex:column value="{!d.Name}"/>
</apex:repeat>
<apex:column >
<apex:commandLink value="Edit" action="{!editfunction}" rerender="pg1">
<apex:param name="cid" value="{!regvalue.id}" assignto="{!editid}"/>
</apex:commandLink> ||
<apex:commandLink value="Delete" action="{!deletefunction}" rerender="pg1,theTable">
<apex:param name="cid" value="{!regvalue.id}" assignto="{!editid}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>
ERROR IS:
List has no rows for assignment to SObject
Error is in expression '{!editfunction}' in page registrationnew: Class.Registrationcontroller.editfunction: line 23, column 1
An unexpected error has occurred. Your development organization has been notified.
WHAT IS THE MISTAKE IN MY code editfunction() method
please anyone helpme
public Registration1__c reg1 {get;set;}
public String editid {get;set;}
public Hotel__c hotel {get;set;}
public AirTravel__c air {get;set;}
public Registrationcontroller()
{
reg1 = new Registration1__c();
hotel = new Hotel__c();
air = new AirTravel__c();
}
public List<Registration1__c> getregisterlist(){
List<Registration1__c> listreg= new List<Registration1__c>();
listreg=[SELECT Id, Name, FirstName__c, LastName__c, Email__c, (SELECT id,name FROM Hotels__r),
(SELECT id,name FROM AirTravels__r) FROM Registration1__c];
return listreg;
}
public void editfunction() {
system.debug('editfunction inside===>'+editid);
reg1=[SELECT Id,Name, FirstName__c, LastName__c, Email__c
FROM Registration1__c where id=:editid];
hotel=[SELECT Id,Name, Check_Out_Date__c, Check_In_Date__c, Hotel_Commands__c FROM Hotel__c where id=:editid];
air=[SELECT Id,Name, Arrival__c, Departure__c, Air_Commands__c FROM AirTravel__c where id=:editid];
}
public void deletefunction() {
system.debug('editfunction inside===>'+editid);
List<Registration1__c> reg2=[SELECT Id, Name, FirstName__c, LastName__c, Email__c
FROM Registration1__c where id=:editid];
List<Hotel__c> hotel1=[SELECT Id,Name, Check_Out_Date__c, Check_In_Date__c, Hotel_Commands__c FROM Hotel__c where id=:editid];
List<AirTravel__c> air1=[SELECT Id,Name, Arrival__c, Departure__c, Air_Commands__c FROM AirTravel__c where id=:editid];
delete reg2;
delete hotel1;
delete air1;
ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.INFO,'Record deleted successfully'));
}
public void saveaction()
{
system.debug('saveaction inside===>'+reg1);
try{
upsert reg1;
if(reg1.Id !=null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.INFO,'Record saved successfully'));
//reg1 = new Registration1__c();
if(hotel != null)
{
hotel.Registration1__c = reg1.id;
upsert hotel;
}
if(air != null)
{
air.Registration1__c = reg1.id;
upsert air;
}
} else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.ERROR,'Record not saved'));
}
}
Catch(Exception e)
{
System.debug(e.getMessage());
}
}
}
<apex:page controller="Registrationcontroller" id="theRepeat" sidebar="false" showHeader="true">
<apex:form >
<apex:pageBlock id="pg1" >
<apex:messages />
<apex:pageBlockSection columns="1" >
<apex:inputField label="FirstName" value="{!reg1.FirstName__c}"/>
<apex:inputField label="LastName" value="{!reg1.LastName__c}"/>
<apex:inputField label="Email" value="{!reg1.Email__c}"/>
<apex:inputField label="HoTel Commands" value="{!hotel.Hotel_Commands__c}"/>
<apex:inputField label="Air Commands" value="{!air.Air_Commands__c}"/>
<apex:inputField label="CheckInDate" value="{!hotel.Check_In_Date__c}"/>
<apex:inputField label="CheckOutDate" value="{!hotel.Check_Out_Date__c}"/>
<apex:inputField label="Arrival" value="{!air.Arrival__c}"/>
<apex:inputField label="Departure" value="{!air.Departure__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!saveaction}" rerender="pg1,theTable" />
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:pageBlock >
<apex:dataTable value="{!registerlist}" var="regvalue" id="theTable" width="100%">
<apex:facet name="caption">Registration List</apex:facet>
<apex:column headerValue="Reg ID"><apex:outputText value="{!regvalue.Name}" /> </apex:column>
<apex:column headerValue="FirstName"><apex:outputText value="{!regvalue.FirstName__c}" /> </apex:column>
<apex:column headerValue="LastName"><apex:outputText value="{!regvalue.LastName__c}" /> </apex:column>
<apex:column headerValue="Email"><apex:outputText value="{!regvalue.Email__c}" /> </apex:column>
<apex:repeat value="{!regvalue.Hotels__r}" var="c">
<apex:column value="{!c.Name}"/>
</apex:repeat>
<apex:repeat value="{!regvalue.AirTravels__r}" var="d">
<apex:column value="{!d.Name}"/>
</apex:repeat>
<apex:column >
<apex:commandLink value="Edit" action="{!editfunction}" rerender="pg1">
<apex:param name="cid" value="{!regvalue.id}" assignto="{!editid}"/>
</apex:commandLink> ||
<apex:commandLink value="Delete" action="{!deletefunction}" rerender="pg1,theTable">
<apex:param name="cid" value="{!regvalue.id}" assignto="{!editid}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>
ERROR IS:
List has no rows for assignment to SObject
Error is in expression '{!editfunction}' in page registrationnew: Class.Registrationcontroller.editfunction: line 23, column 1
An unexpected error has occurred. Your development organization has been notified.
WHAT IS THE MISTAKE IN MY code editfunction() method
please anyone helpme
It seems the below SOQL has no records being returned in your code:
So, you will need to ensure the query returns at least one records or you should check if its not null then only proceed further for operations.
Hope above information helps. Please mark as Best Answer so that it can help others in future.
Thanks.
I can help you with that. Don't worry but before that I want you to understand below concept:
When you do SOQL on Object, there could be below outcome:
1. it may give 0 record,
2. it may give 1 record,
3. it may give more than 1 records.
Since you're doing any SOQL, you'll need either an SObject datatype variable or List<SObject> datatype variable.
Now imagine above three scenario once again:
If you use sObject Data type variable and you received 0 record from SOQL. Then SOQL List has no records for assignment to sObject that you've declared to story query result. That is what youre getting in the error. Example:
Account acc = [SELECT Id FROM Account]; //If 0 record retrieved than SOQL/List has no record for assignment
Consider, second scenario,
Account acc = [SELECT Id FROM Account]; //If 1 record retreived than there is no problem.
Consider, last scenario,
Account acc = [SELECT Id FROM Account]; //If 5 record retrieved than List has more than 1 row for assignment to SObject
Now this mean whenever you make any query with sObject then it will aspect 1 record other its an error.
How to handle it:
Now instead of using sObject use List<sObject> and repharse above scenario.
List<Account> accList= [SELECT Id FROM Account]; //Absolutely fine no Problem because list can be empty
Consider, second scenario,
List<Account> accList = [SELECT Id FROM Account]; //Absolutely fine no Problem because list can handle one record
Consider, last scenario,
List<Account> accList= [SELECT Id FROM Account]; ///Absolutely fine no Problem because list handle more than one records as well.
So the conclusion is to try to capture SOQL query in list<SObject> and then use if a condition like below:
if(accList.size()==1) { //Then do whatever you want }
Go through this article:
Apex error 'List has no rows for assignment to SObject' (https://help.salesforce.com/articleView?id=000328824&type=1&mode=1)
Thanks,
Ashish Singh
reg1=[SELECT Id,Name, FirstName__c, LastName__c, Email__c
FROM Registration1__c where id=:editid];
hotel=[SELECT Id,Name, Check_Out_Date__c, Check_In_Date__c, Hotel_Commands__c FROM Hotel__c where id=:editid];
air=[SELECT Id,Name, Arrival__c, Departure__c, Air_Commands__c FROM AirTravel__c where id=:editid];
Any one of these SOQL is not returning any record and as per Line 23 I suspect its hotel record. Now you need to decide if you want to correct data in the system, or you want to Change sObject to List<sObject>.
How EditId can be same for all three objects?
You need to correct your visualforce logic and you need to create two more apex Param for hotel and air then grab that Id from VF to your above query where clause.