You need to sign in to do that
Don't have an account?
Akanksha sharma 15
my scenario is when i will click on new opportunity button a new opportunity page should open where i fill the details and click on save then it will redirect to the list page of opportunity where records save with edit and delete link when click on edit link edit page should open i have done till that but when i click on delete link it should deleted i am not abe to do for delete when i am deleting record a new bank page open
When i clicked on record on delete commandlink record is not deleted
my scenario is when i will click on new opportunity button a new opportunity page should open where i fill the details and click on save then it will redirect to the list page of opportunity where records save with edit and delete link when click on edit link edit page should open i have done till that but when i click on delete link it should deleted i am not abe to do for delete when i am deleting record a new bank page open
<apex:page StandardController="Opportunity" Extensions="secondpage" > <apex:form > <apex:pageBlock > <apex:pageBlockButtons location="Top" > <apex:commandButton value="Save" action="{!saverec}"/> <br/><br/> <apex:commandLink action="{!editOpp}" value="Edit"/> <apex:param value="{!opp.id}" assignTo="{!selectedAccId}" name="selectedAccId"/> <apex:commandLink action="{!deleteOpp}" value="Delete" /> <apex:param value="{!opp.id}" assignTo="{!selectedAccId}" name="selectedAccId"/> </apex:pageBlockButtons> <apex:pageblockSection > <apex:inputfield value="{!opp.Name}" /> <apex:inputfield value="{!opp.StageName}"/> <apex:inputfield value="{!opp.AccountId}"/> <apex:inputfield value="{!opp.Amount}"/> <apex:inputfield value="{!opp.closeDate}"/> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page> ---- public class secondpage { Public Opportunity opp{get;set;} Public String op1; public id accid{set;get;} public String selectedAccId {get;set;} public String selectedoppId{get;set;} public secondpage(ApexPages.StandardController stdController) { Opp= (Opportunity)stdController.getRecord(); } public PageReference saverec() { insert opp; pagereference pr = new pagereference('https://c.ap6.visual.force.com/apex/Opp2'); return pr; } public Pagereference editOpp() { PageReference ref = new PageReference('/'+selectedAccId+'/e?retURL=%2F'+selectedAccId); return ref; } public Pagereference deleteOpp() { return null; } } ---- <apex:page Controller="mycontroller1"> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:pageBlockTable value="{!Opportunitylst}" var="op"> <apex:column value="{!op.Name}"/> <apex:column value="{!op.StageName}"/> <apex:column value="{!op.Amount}" /> <apex:column value="{!op.accountId}"/> <apex:column value="{!op.CloseDate}"/> <apex:column headerValue="Action" > <apex:commandLink value="Edit /" action="{!editOpp}"> <apex:param value="{!op.id}" assignTo="{!selectedAccId}" name="selectedAccId"/> </apex:commandLink> <apex:commandLink action="{!deleteOpp}" value="Delete"/> <apex:param value="{!op.id}" assignTo="{!selectedAccId}" name="selectedAccId"/> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> ---- public class mycontroller1 { public List<Opportunity> Opp{get;set;} Public List<Opportunity> Opportunitylst{get;set;} public String selectedAccId {get;set;} public PageReference deleteOpp() { opportunitylst=[select Name,AccountId,Amount,CloseDate,StageName from Opportunity where id=:selectedAccId]; delete opportunitylst; return null; } public mycontroller1(){ Opportunitylst=[select Name,AccountId,Amount,CloseDate,StageName from Opportunity order by createdDate DESC limit 10 ]; } public Pagereference editOpp() { p PageReference ref = new PageReference('/'+selectedAccId+'/e?retURL=%2F'+selectedAccId); return ref; } }
List has no rows for assignment to SObject
Error is in expression '{!deleteOpp}' in page opp2: Class.mycontroller1.deleteOpp: line 10, column 1
An unexpected error has occurred. Your development organization has been notified.
Update your delete button code with this--
<apex:commandLink action="{!deleteOpp}" value="Delete">
<apex:param value="{!op.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
</apex:commandLink>
its working in my org.
I think you should do this using Wrapper Class Concept.
List has no rows for assignment to SObject
but your query seems to correct.
let's check the query result in debug log
Hello Akanksha,
Update deleteOpp method in controller
Hope, it will help you.
Thank You