• Pritesh Jose
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

My requirement is that on click of a custom button in contract object  an email needs to be generated.
 The button is not embedded in the visual force but is present at the contract header.When user goes to the contract Tab and clicks any valid contract the "Email" button comes next standard "Edit" "Delete" and clone buttons as expected for the specific contract.Have been succesfull till here.A dummy email gets triggered.

The next part of the requirement is retrieve the current contract number and pass it in the email subject .
I used SOQL to retrieve the current id but I'm getting null value "List has no rows for assignment to SObject 
An unexpected error has occurred. Your development organization has been notified.".
This indicates my SOQL query has not retrieved any value for the current id.wanted to now where I have gone wrong.
Any advice on the syntax and code to be used would be of great help.

Indiacted below is my entire apex class code below :
// below is the email triggerring apex class
public class emailsend_class{

string email_body {get {return 'this is contractemail'; } set;}
string email_subject {get;set;}

public String currentRecordId {get;set;}
public String parameterValue {get;set;}

 public Contract con{get;set;}


list<string> emails = new list<string>{'pritesh.curicad@fci.com'};

//  Below method code will retrieve the current record 

public emailsend_class(){
currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
 con = [select ContractNumber from Contract where id =: currentRecordId ];

}

 
  public Contract getContract(){
    return con; }
  
public PageReference send() {

  Messaging.singleEmailmessage email = new Messaging.singleEmailmessage();
   email.setSubject(email_subject);
   email.setPlainTextBody(email_body);
   email.setToAddresses (emails);
  Messaging.SendEmailResult[] r = Messaging.SendEmail( new Messaging.singleEmailmessage[] {email} ); 
   
   return null;
   
    }

}

The visualforce page has only the below basic code

<apex:page controller="emailsend_class" action="{!send}">
  
 
</apex:page>

My requirement is that on click of a custom button in contract object  an email needs to be generated.
 The button is not embedded in the visual force but is present at the contract header.When user goes to the contract Tab and clicks any valid contract the "Email" button comes next standard "Edit" "Delete" and clone buttons as expected for the specific contract.Have been succesfull till here.A dummy email gets triggered.

The next part of the requirement is retrieve the current contract number and pass it in the email subject .
I used SOQL to retrieve the current id but I'm getting null value "List has no rows for assignment to SObject 
An unexpected error has occurred. Your development organization has been notified.".
This indicates my SOQL query has not retrieved any value for the current id.wanted to now where I have gone wrong.
Any advice on the syntax and code to be used would be of great help.

Indiacted below is my entire apex class code below :
// below is the email triggerring apex class
public class emailsend_class{

string email_body {get {return 'this is contractemail'; } set;}
string email_subject {get;set;}

public String currentRecordId {get;set;}
public String parameterValue {get;set;}

 public Contract con{get;set;}


list<string> emails = new list<string>{'pritesh.curicad@fci.com'};

//  Below method code will retrieve the current record 

public emailsend_class(){
currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
 con = [select ContractNumber from Contract where id =: currentRecordId ];

}

 
  public Contract getContract(){
    return con; }
  
public PageReference send() {

  Messaging.singleEmailmessage email = new Messaging.singleEmailmessage();
   email.setSubject(email_subject);
   email.setPlainTextBody(email_body);
   email.setToAddresses (emails);
  Messaging.SendEmailResult[] r = Messaging.SendEmail( new Messaging.singleEmailmessage[] {email} ); 
   
   return null;
   
    }

}

The visualforce page has only the below basic code

<apex:page controller="emailsend_class" action="{!send}">
  
 
</apex:page>