You need to sign in to do that
Don't have an account?
Himanshu Ghate
Can someone please help me out,with the solution in my code.Error-->System.QueryException: List has no rows for assignment to SObject
System.QueryException: List has no rows for assignment to SObject
public class sendEmail {
public List<String> toList{get;set;}
public List<String> ccList{get;set;}
public String To{get;set;}
public String cc{get;set;}
public String Subject{get;set;}
public String EmailBody{get;set;}
public CustomOpportunity__c Customopp{get;set;}
public Id oppid{get;set;}
public sendEmail()
{
ApexPages.PageReference Pageref=ApexPages.CurrentPage();
oppid=Pageref.getParameters().get('Id');
Customopp=[Select id, Name , AccountName__c,AccountName__r.Name,ContactName__r.Name,AccountName__r.Emailid__c FROM CustomOpportunity__c WHERE Id=:oppid];
Subject='Opportunity Details For Account'+Customopp.AccountName__r.Name;
EmailBody='<p><b>Account Status Update</b></p>'+'</br></br>'+
'Dear'+'</br></br>'+Customopp.ContactName__r.Name+'</br></br>'+
'<p>We are happy to inform you that your Account Order is under process.Please Find Below Current Status of your Account Ordered Product by you:</p>'+
'<b>Account Name:</b>'+' '+Customopp.AccountName__r.Name+'<br/>'+
'<b>Contact Name:</b>'+' '+Customopp.ContactName__r.Name+'<br/>'+
'<b>Email ID:</b>'+' '+Customopp.AccountName__r.Emailid__c +'<br/><br/>'+
'Please Contact your Account Service Manager For any queries releated to this update.For any Concerns,You can write to us at himanshughate2999@gmail.com.<br/><br/>'+
'Regards,</br>'+
'<b>IBM Accounts Team.</b>';
}
public pagereference SendingEmail()
{
tolist=new List<String>();
tolist.add(To);
cclist=new List<String>();
tolist.add(cc);
List<Messaging.Email> EmailObjs=new List<Messaging.Email>();
Messaging.SingleEmailMessage Emailobj=new Messaging.SingleEmailMessage();
Emailobj.setToAddresses(tolist);
Emailobj.setToAddresses(cclist);
Emailobj.SetReplyTo('support@acme.com');
Emailobj.SetSenderDisplayName('Salesforce Support');
Emailobj.SetSubject(Subject);
Emailobj.Sethtmlbody(EmailBody);
//EmailObj.SetBccSender(false);
//EmailObj.SetUseSignature(false);
EmailObjs.add(Emailobj);
Messaging.sendEmail(EmailObjs);
pagereference pr = new pagereference('/');
return pr;
}
}
public class sendEmail {
public List<String> toList{get;set;}
public List<String> ccList{get;set;}
public String To{get;set;}
public String cc{get;set;}
public String Subject{get;set;}
public String EmailBody{get;set;}
public CustomOpportunity__c Customopp{get;set;}
public Id oppid{get;set;}
public sendEmail()
{
ApexPages.PageReference Pageref=ApexPages.CurrentPage();
oppid=Pageref.getParameters().get('Id');
Customopp=[Select id, Name , AccountName__c,AccountName__r.Name,ContactName__r.Name,AccountName__r.Emailid__c FROM CustomOpportunity__c WHERE Id=:oppid];
Subject='Opportunity Details For Account'+Customopp.AccountName__r.Name;
EmailBody='<p><b>Account Status Update</b></p>'+'</br></br>'+
'Dear'+'</br></br>'+Customopp.ContactName__r.Name+'</br></br>'+
'<p>We are happy to inform you that your Account Order is under process.Please Find Below Current Status of your Account Ordered Product by you:</p>'+
'<b>Account Name:</b>'+' '+Customopp.AccountName__r.Name+'<br/>'+
'<b>Contact Name:</b>'+' '+Customopp.ContactName__r.Name+'<br/>'+
'<b>Email ID:</b>'+' '+Customopp.AccountName__r.Emailid__c +'<br/><br/>'+
'Please Contact your Account Service Manager For any queries releated to this update.For any Concerns,You can write to us at himanshughate2999@gmail.com.<br/><br/>'+
'Regards,</br>'+
'<b>IBM Accounts Team.</b>';
}
public pagereference SendingEmail()
{
tolist=new List<String>();
tolist.add(To);
cclist=new List<String>();
tolist.add(cc);
List<Messaging.Email> EmailObjs=new List<Messaging.Email>();
Messaging.SingleEmailMessage Emailobj=new Messaging.SingleEmailMessage();
Emailobj.setToAddresses(tolist);
Emailobj.setToAddresses(cclist);
Emailobj.SetReplyTo('support@acme.com');
Emailobj.SetSenderDisplayName('Salesforce Support');
Emailobj.SetSubject(Subject);
Emailobj.Sethtmlbody(EmailBody);
//EmailObj.SetBccSender(false);
//EmailObj.SetUseSignature(false);
EmailObjs.add(Emailobj);
Messaging.sendEmail(EmailObjs);
pagereference pr = new pagereference('/');
return pr;
}
}
Try this updated code
Basically, the error is occurring because the SOQL query is not returning any records for the specified oppid. You can handle this situation by checking if the query returned any records using the List.isEmpty() method
If this information helps, please mark the answer as best. Thank you
All Answers
Try this updated code
Basically, the error is occurring because the SOQL query is not returning any records for the specified oppid. You can handle this situation by checking if the query returned any records using the List.isEmpty() method
If this information helps, please mark the answer as best. Thank you
Account Status Update
'+''+ 'Dear'+''+Customopp.ContactName__r.Name+''+ 'We are happy to inform you that your Account Order is under process.Please Find Below Current Status of your Account Ordered Product by you:
'+ 'Account Name:'+' '+Customopp.AccountName__r.Name+''+ 'Contact Name:'+' '+Customopp.ContactName__r.Name+'
'+ 'Email ID:'+' '+Customopp.AccountName__r.Emailid__c +'
'+ 'Please Contact your Account Service Manager For any queries releated to this update.For any Concerns,You can write to us at himanshughate2999@gmail.com.
'+ 'Regards,'+ 'IBM Accounts Team.'; } } public pagereference SendingEmail() { tolist=new List(); tolist.add(To); cclist=new List(); tolist.add(cc); List EmailObjs=new List(); Messaging.SingleEmailMessage Emailobj=new Messaging.SingleEmailMessage(); Emailobj.setToAddresses(tolist); Emailobj.setToAddresses(cclist); Emailobj.SetReplyTo('support@acme.com'); Emailobj.SetSenderDisplayName('Salesforce Support'); Emailobj.SetSubject(Subject); Emailobj.Sethtmlbody(EmailBody); //EmailObj.SetBccSender(false); //EmailObj.SetUseSignature(false); EmailObjs.add(Emailobj); Messaging.sendEmail(EmailObjs); pagereference pr = new pagereference('/'); return pr; } }