• SFDC 18
  • NEWBIE
  • 80 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 21
    Replies
My lex component
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
   <lightning:button label="PDF" onclick ="{!c.handleClick}"/>
   <aura:attribute name="recordId" type="String"/> 
</aura:component>

controller:

({
	handleClick : function(component, event, helper) {
        
        var recId = component.get('v.recordId');
        var retURL = component.get('v.pdf');
        retURL = window.open("apex/TTDLetter?recordId="+recordID);
        	
	}
})

when i have clicked on the lightning button from record page I got a error 'URL doesn't exist".
My VF Page:
 
<apex:page controller="MyController" renderAs="{!isPDF}" applyBodyTag="false" >

<head>
    <style> 
    body { font-family: 'Arial Unicode MS'; }

@page{
        size: letter;
        margin:20%;
        @top-center{
            content: "My Content";
            font-family: Helvetica, Arial, sans-serif;
            font-size: 24px;
            font-weight: bolder;
        }
        @bottom-right{
            content: "Yours Sincerely,";
            font-family: Helvetica, Arial, sans-serif;
            font-size: 10px;
        }
   }
body {
        font-family: Helvetica, Arial, sans-serif;
        font-size: 14px;
}
    </style>
</head>
    <div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
    <div align="left">Dear,</div>
 <p>My Text</p>

    <p>My Text</p>    

</apex:page>


The above VF page renders as PDF, a custom button PDF is created for it.

window.open("apex/Letter?Id={!Letter__c.Id}","_blank"); 

This shoes a PDF of the VF page req when the button is clicked. Now I need the same pdf in print view (CTRL+P) when the pdf button is clicked.
So I have changed window.open to window.print("apex/Letter?Id={!Letter__c.Id}","_blank"); , but the print view which i got is of the current page not the pdf rendered.
 

Can anyone just help or guide me on how to generate print view when my pdf button is clicked

I have written a lightning cmp and controller for a button which calls a VF pagw which renders PDF

CMP
<aura:component implements="force:lightningQuickAction" >
   <lightning:button label="PDF" 
        onclick="{!c.PDF}" />
</aura:component>

Controller :
/* Component controller */
({
 PDF : function(sforce.one.navigateToURL('/apex/Letter?Parameter1=data1'));

})

I'm unable to save my controller as its throwing an error msg

VF page
<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">
<head>
<style>
body { font-family: 'Arial Unicode MS'; }

@page{
    size: letter;
    margin:10%;
    @top-left{
        content: "Dear,";
        font-family: Helvetica, Arial, sans-serif;
        font-size: 12px;
    }
    @bottom-right{
        content: "Yours Sincerely,";
        font-family: Helvetica, Arial, sans-serif;
        font-size: 10px;
    }
}

body {
        font-family: Helvetica, Arial, sans-serif;
        font-size: 11px;
}
    </style>
</head>
    <div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
    <h1> Letter</h1>
    </center>
    <p>{!custom_object__C.Name__C}</p>    
</apex:page>

​Custom Button:


window.open("apex/Letter?Id={!Letter__c.Id}","_blank");
This is my VF page code for Rendering a PDF for custom Object as below
<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">
<head>
    <style>
    body { font-family: 'Arial Unicode MS'; }

@page{
        size: letter;
        margin:10%;
        @top-left{
        	content: "Dear,";
        	font-family: Helvetica, Arial, sans-serif;
			font-size: 12px;
		}
        @bottom-right{
        	content: "Yours Sincerely,";
        	font-family: Helvetica, Arial, sans-serif;
			font-size: 10px;
		}
   }
body {
        font-family: Helvetica, Arial, sans-serif;
		font-size: 11px;
}
    </style>
</head>
	<div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
    <h1> Letter</h1>
    </center>
    <p>{!custom_object__C.Name__C</p>    
</apex:page>

Controller page
public class MyController {
    
    private final custom_object__c customobject;
        
        public MyController(){
            customobject = [SELECT Id, Name__c FROM custom_object__c 
                        LIMIT 1];
        }
        public custom_object__c getcustom_object__c(){
            return customobject;
        }
        public PageReference save() {
            update customobject;
            return null;
        }
    }

I got the error Unknown property 'MyController.custom_object__C' in my VF page​​

Due to this compile error, in the preview screen I got the display of only top left, bottom right, centre but no data related to "<p>{!custom_object__C.Name__C</p>" line
Hi,

I wrote a batch to update the fields, i got the below errors for my code

User-added image
Code
global class updatezone implements Database.Batchable<sObject>,Database.stateful{
    
    //Start Method....   
    global Database.querylocator start(Database.BatchableContext bc){
        Query = 'SELECT id,No_of_Agents__c,No_of_Female_Agents__c,No_of_Male_Agents__c,Agents_40_years_and_above__c,Agents_below_40_years__c,X1_star_Agents__c,X2_star_Agents__c,X3_star_Agents__c,X4_star_Agents__c,X5_star_Agents__c'+
            				' FROM Zone__C ';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext bc, List<Zone__C> scope){
                 for(zone__c z : [SELECT Id,Name__C,No_of_Agents__c,No_of_Female_Agents__c,No_of_Male_Agents__c,Agents_40_years_and_above__c,Agents_below_40_years__c,X1_star_Agents__c,X2_star_Agents__c,X3_star_Agents__c,X4_star_Agents__c,X5_star_Agents__c FROM 
                         Zone__C]){
                              z.No_of_Agents__C = [SELECT count() FROM Agent__C WHERE Zones__C =: z.Name__C];
                              z.Agents_below_40_years__C = [SELECT count() FROM Agent__C WHERE Age__C <=40 AND Zones__C =: z.Name__C ];
                              z.Agents_40_years_and_above__c = [SELECT count() FROM Agent__C WHERE Age__C > 40 AND Zones__C =: z.Name__C ];
                              z.No_of_Male_Agents__C = [SELECT count() FROM Agent__C WHERE Gender__C =: 'Male' AND Zones__C =: z.Name__C ];
                              z.No_of_Female_Agents__C = [SELECT count() FROM Agent__C WHERE Gender__C =: 'Female' AND Zones__C =: z.Name__C];
                              z.X1_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =1 AND Zones__C =: z.Name__C ];
                              z.X2_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =2 AND Zones__C =: z.Name__C ];
                              z.X3_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =3 AND Zones__C =: z.Name__C ];
                              z.X4_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =4 AND Zones__C =: z.Name__C ];
                              z.X5_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =5 AND Zones__C =: z.Name__C ];
                         }
upsert z;
    }
    public void finish(Database.BatchableContext bc){
         Id job= bc.getJobId();
         }
}

 
I need to update a field on zone called total sales which display the total sales on agent object in that region

 
public class TotalSales {
    
     public TotalSales(){
         
         for(zone__c z : [SELECT Id,Total_Sales__C FROM Zone__C WHERE Name__c = 'North']){
             
             z.Total_Sales__C = [SELECT Sum() FROM Agent__C WHERE Total_Sales__c ='0' ];
            
            upsert z;

}
     }
}


 
Hi 

I got this error when i tried to execute the below code in anonymous window
 
public class NoofMaleAgents {
    
    public NoofMaleAgents(){
        
        for(zone__c z : [SELECT Id,No_of_Male_Agents__C FROM Zone__C]){
            
            z.No_of_Male_Agents__C = [SELECT count() FROM Agent__C WHERE Gender__C =: 'Male' AND Zones__C =: z.Name__C ];
            
            upsert z;
        
    }
        for(zone__c z : [SELECT Id,No_of_Female_Agents__C FROM Zone__C]){
            
            z.No_of_Female_Agents__C = [SELECT count() FROM Agent__C WHERE Gender__C =: 'Female' AND Zones__C =: z.Name__C];
            
            upsert z;
            
        }

    }
}

 
Hi, 
I need to update a field called No of Agents with the count of agents in that zone (North, South, East, West). The zone field is on agent object and no of agents is on zone object. I have written the below logic.

I'm stuck with the if clause part. Can anyone help me with this?

Name is a field on zone object with picklist values of zone

On No of Agents field,
public class NoofAgents {
    List<Zone> zonestoupdate = [SELECT Id,Zones__C FROM Agent__C];  
    for(Zone z:zonestoupdate)       
    {       
        Integer NoofAgents = [SELECT count() FROM Agent__C WHERE Zones__C == North];
        if (Name__c == North)
        {
            
        }
    }        
}

it should show the count of agents in that zone

 
public class RenewOpportunity implements Database.Batchable<sObject>{
    
	private string query;
 //Start Method....   
    public Database.querylocator start(Database.BatchableContext bc){
        Query = 'SELECT id, name, CloseDate ' +
            'FROM Opportunity' +
            'WHERE CloseDate = CloseDate()-30';
        return Database.getQueryLocator(query);
    }
 //Execute Method...   
    public void execute(Database.BatchableContext bc, List<Opportunity> scope){
        List<Opportunity> opportunities = new List<Opportunity>();
        List<Opportunity> oppList = (List<Opportunity>)scope ;

        for (Opportunity opp : oppList ) {
         
            if (opp.CloseDate <= opp.CloseDate - 30) {
                Opportunity renewal = new Opportunity();
                renewal.AccountId   = opp.AccountId;
                renewal.Name        = opp.Name + 'Renewal';
                renewal.CloseDate   = opp.CloseDate + 365;
                renewal.StageName   = 'Open';
                renewal.OwnerId     = opp.OwnerId;
                opportunities.add(renewal);
                
            }       
            insert opportunities; 
        }
    }
//Finish Method....    
    public void finish(Database.BatchableContext bc){
         Id job= bc.getJobId();
        System.debug(job);
    }
}

 
Hi,
I have written the below apex batch code to renew the oportunity before 30 days of close date. I'm unable to run the code. Can anyone help me with the below code.
 
global class UpdateOpportunity implements
	Database.Batchable<sObject>, Database.stateful{

    string query;

    global Database.querylocator start(Database.BatchableContext bc){
        Query = 'SELECT id, name, Amount__c, Man_Power_Amount__c,Stage__c ' +
                'FROM Opportunity__c ' +
                'WHERE CloseDate = CloseDate()-30';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext bc, List<Opportunity__c> scope){
        List<Opportunity> opportunities = new List<Opportunity>();
               for (Opportunity opp : Scope ) {
 
    if (opp.CloseDate <= opp.CloseDate - 30) {
       Opportunity renewal = new Opportunity();
       renewal.AccountId   = 'opp.AccountId';
       renewal.Name        = opp.Name + 'Renewal';
       renewal.CloseDate   = opp.CloseDate + 365;
       renewal.StageName   = 'Open';
       renewal.RecordType  = 'Renewal';
       renewal.OwnerId     = opp.OwnerId;
       renewals.put(renewal.Id, renewal);

        }       
        update p; 
    }

    global void finish(Database.BatchableContext bc){
        System.debug(recordsprocessed + '' );
        AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, 
            JobItemsProcessed,
            TotalJobItems, CreatedBy.Email
            FROM AsyncApexJob
            WHERE Id = :bc.getJobId()];
          EmailUtils.sendMessage(a, recordsProcessed);
    }
}
    }

 
trigger CreateRenewal on Opportunity (before update) {

  Map<Id, Opportunity> renewals = new Map<Id, Opportunity>();

  for (Opportunity opp : Trigger.new) {
 
    if (opp.CloseDate <= opp.CloseDate - 30) {
       Opportunity renewal = new Opportunity();
       renewal.AccountId   = 'opp.AccountId';
       renewal.Name        = opp.Name + 'Renewal';
       renewal.CloseDate   = opp.CloseDate + 365;
       renewal.StageName   = 'Open';
       renewal.RecordType  = 'Renewal';
       renewal.OwnerId     = opp.OwnerId;
       renewals.put(renewal.Id, renewal);
    }
  }

   insert renewals;
}

 
Hi, 
I need to update a field called No of Agents with the count of agents in that zone (North, South, East, West). The zone field is on agent object and no of agents is on zone object. I have written the below logic.

I'm stuck with the if clause part. Can anyone help me with this?

Name is a field on zone object with picklist values of zone

On No of Agents field,
public class NoofAgents {
    List<Zone> zonestoupdate = [SELECT Id,Zones__C FROM Agent__C];  
    for(Zone z:zonestoupdate)       
    {       
        Integer NoofAgents = [SELECT count() FROM Agent__C WHERE Zones__C == North];
        if (Name__c == North)
        {
            
        }
    }        
}

it should show the count of agents in that zone

 
I have written a lightning cmp and controller for a button which calls a VF pagw which renders PDF

CMP
<aura:component implements="force:lightningQuickAction" >
   <lightning:button label="PDF" 
        onclick="{!c.PDF}" />
</aura:component>

Controller :
/* Component controller */
({
 PDF : function(sforce.one.navigateToURL('/apex/Letter?Parameter1=data1'));

})

I'm unable to save my controller as its throwing an error msg

VF page
<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">
<head>
<style>
body { font-family: 'Arial Unicode MS'; }

@page{
    size: letter;
    margin:10%;
    @top-left{
        content: "Dear,";
        font-family: Helvetica, Arial, sans-serif;
        font-size: 12px;
    }
    @bottom-right{
        content: "Yours Sincerely,";
        font-family: Helvetica, Arial, sans-serif;
        font-size: 10px;
    }
}

body {
        font-family: Helvetica, Arial, sans-serif;
        font-size: 11px;
}
    </style>
</head>
    <div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
    <h1> Letter</h1>
    </center>
    <p>{!custom_object__C.Name__C}</p>    
</apex:page>

​Custom Button:


window.open("apex/Letter?Id={!Letter__c.Id}","_blank");
This is my VF page code for Rendering a PDF for custom Object as below
<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">
<head>
    <style>
    body { font-family: 'Arial Unicode MS'; }

@page{
        size: letter;
        margin:10%;
        @top-left{
        	content: "Dear,";
        	font-family: Helvetica, Arial, sans-serif;
			font-size: 12px;
		}
        @bottom-right{
        	content: "Yours Sincerely,";
        	font-family: Helvetica, Arial, sans-serif;
			font-size: 10px;
		}
   }
body {
        font-family: Helvetica, Arial, sans-serif;
		font-size: 11px;
}
    </style>
</head>
	<div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
    <h1> Letter</h1>
    </center>
    <p>{!custom_object__C.Name__C</p>    
</apex:page>

Controller page
public class MyController {
    
    private final custom_object__c customobject;
        
        public MyController(){
            customobject = [SELECT Id, Name__c FROM custom_object__c 
                        LIMIT 1];
        }
        public custom_object__c getcustom_object__c(){
            return customobject;
        }
        public PageReference save() {
            update customobject;
            return null;
        }
    }

I got the error Unknown property 'MyController.custom_object__C' in my VF page​​

Due to this compile error, in the preview screen I got the display of only top left, bottom right, centre but no data related to "<p>{!custom_object__C.Name__C</p>" line
Hi,

I wrote a batch to update the fields, i got the below errors for my code

User-added image
Code
global class updatezone implements Database.Batchable<sObject>,Database.stateful{
    
    //Start Method....   
    global Database.querylocator start(Database.BatchableContext bc){
        Query = 'SELECT id,No_of_Agents__c,No_of_Female_Agents__c,No_of_Male_Agents__c,Agents_40_years_and_above__c,Agents_below_40_years__c,X1_star_Agents__c,X2_star_Agents__c,X3_star_Agents__c,X4_star_Agents__c,X5_star_Agents__c'+
            				' FROM Zone__C ';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext bc, List<Zone__C> scope){
                 for(zone__c z : [SELECT Id,Name__C,No_of_Agents__c,No_of_Female_Agents__c,No_of_Male_Agents__c,Agents_40_years_and_above__c,Agents_below_40_years__c,X1_star_Agents__c,X2_star_Agents__c,X3_star_Agents__c,X4_star_Agents__c,X5_star_Agents__c FROM 
                         Zone__C]){
                              z.No_of_Agents__C = [SELECT count() FROM Agent__C WHERE Zones__C =: z.Name__C];
                              z.Agents_below_40_years__C = [SELECT count() FROM Agent__C WHERE Age__C <=40 AND Zones__C =: z.Name__C ];
                              z.Agents_40_years_and_above__c = [SELECT count() FROM Agent__C WHERE Age__C > 40 AND Zones__C =: z.Name__C ];
                              z.No_of_Male_Agents__C = [SELECT count() FROM Agent__C WHERE Gender__C =: 'Male' AND Zones__C =: z.Name__C ];
                              z.No_of_Female_Agents__C = [SELECT count() FROM Agent__C WHERE Gender__C =: 'Female' AND Zones__C =: z.Name__C];
                              z.X1_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =1 AND Zones__C =: z.Name__C ];
                              z.X2_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =2 AND Zones__C =: z.Name__C ];
                              z.X3_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =3 AND Zones__C =: z.Name__C ];
                              z.X4_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =4 AND Zones__C =: z.Name__C ];
                              z.X5_star_Agents__c = [SELECT count() FROM Agent__C WHERE Ranking_Stars__C =5 AND Zones__C =: z.Name__C ];
                         }
upsert z;
    }
    public void finish(Database.BatchableContext bc){
         Id job= bc.getJobId();
         }
}

 
I need to update a field on zone called total sales which display the total sales on agent object in that region

 
public class TotalSales {
    
     public TotalSales(){
         
         for(zone__c z : [SELECT Id,Total_Sales__C FROM Zone__C WHERE Name__c = 'North']){
             
             z.Total_Sales__C = [SELECT Sum() FROM Agent__C WHERE Total_Sales__c ='0' ];
            
            upsert z;

}
     }
}


 
Hi 

I got this error when i tried to execute the below code in anonymous window
 
public class NoofMaleAgents {
    
    public NoofMaleAgents(){
        
        for(zone__c z : [SELECT Id,No_of_Male_Agents__C FROM Zone__C]){
            
            z.No_of_Male_Agents__C = [SELECT count() FROM Agent__C WHERE Gender__C =: 'Male' AND Zones__C =: z.Name__C ];
            
            upsert z;
        
    }
        for(zone__c z : [SELECT Id,No_of_Female_Agents__C FROM Zone__C]){
            
            z.No_of_Female_Agents__C = [SELECT count() FROM Agent__C WHERE Gender__C =: 'Female' AND Zones__C =: z.Name__C];
            
            upsert z;
            
        }

    }
}

 
Hi, 
I need to update a field called No of Agents with the count of agents in that zone (North, South, East, West). The zone field is on agent object and no of agents is on zone object. I have written the below logic.

I'm stuck with the if clause part. Can anyone help me with this?

Name is a field on zone object with picklist values of zone

On No of Agents field,
public class NoofAgents {
    List<Zone> zonestoupdate = [SELECT Id,Zones__C FROM Agent__C];  
    for(Zone z:zonestoupdate)       
    {       
        Integer NoofAgents = [SELECT count() FROM Agent__C WHERE Zones__C == North];
        if (Name__c == North)
        {
            
        }
    }        
}

it should show the count of agents in that zone

 
public class RenewOpportunity implements Database.Batchable<sObject>{
    
	private string query;
 //Start Method....   
    public Database.querylocator start(Database.BatchableContext bc){
        Query = 'SELECT id, name, CloseDate ' +
            'FROM Opportunity' +
            'WHERE CloseDate = CloseDate()-30';
        return Database.getQueryLocator(query);
    }
 //Execute Method...   
    public void execute(Database.BatchableContext bc, List<Opportunity> scope){
        List<Opportunity> opportunities = new List<Opportunity>();
        List<Opportunity> oppList = (List<Opportunity>)scope ;

        for (Opportunity opp : oppList ) {
         
            if (opp.CloseDate <= opp.CloseDate - 30) {
                Opportunity renewal = new Opportunity();
                renewal.AccountId   = opp.AccountId;
                renewal.Name        = opp.Name + 'Renewal';
                renewal.CloseDate   = opp.CloseDate + 365;
                renewal.StageName   = 'Open';
                renewal.OwnerId     = opp.OwnerId;
                opportunities.add(renewal);
                
            }       
            insert opportunities; 
        }
    }
//Finish Method....    
    public void finish(Database.BatchableContext bc){
         Id job= bc.getJobId();
        System.debug(job);
    }
}

 
Hi,
I have written the below apex batch code to renew the oportunity before 30 days of close date. I'm unable to run the code. Can anyone help me with the below code.
 
global class UpdateOpportunity implements
	Database.Batchable<sObject>, Database.stateful{

    string query;

    global Database.querylocator start(Database.BatchableContext bc){
        Query = 'SELECT id, name, Amount__c, Man_Power_Amount__c,Stage__c ' +
                'FROM Opportunity__c ' +
                'WHERE CloseDate = CloseDate()-30';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext bc, List<Opportunity__c> scope){
        List<Opportunity> opportunities = new List<Opportunity>();
               for (Opportunity opp : Scope ) {
 
    if (opp.CloseDate <= opp.CloseDate - 30) {
       Opportunity renewal = new Opportunity();
       renewal.AccountId   = 'opp.AccountId';
       renewal.Name        = opp.Name + 'Renewal';
       renewal.CloseDate   = opp.CloseDate + 365;
       renewal.StageName   = 'Open';
       renewal.RecordType  = 'Renewal';
       renewal.OwnerId     = opp.OwnerId;
       renewals.put(renewal.Id, renewal);

        }       
        update p; 
    }

    global void finish(Database.BatchableContext bc){
        System.debug(recordsprocessed + '' );
        AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, 
            JobItemsProcessed,
            TotalJobItems, CreatedBy.Email
            FROM AsyncApexJob
            WHERE Id = :bc.getJobId()];
          EmailUtils.sendMessage(a, recordsProcessed);
    }
}
    }

 
trigger CreateRenewal on Opportunity (before update) {

  Map<Id, Opportunity> renewals = new Map<Id, Opportunity>();

  for (Opportunity opp : Trigger.new) {
 
    if (opp.CloseDate <= opp.CloseDate - 30) {
       Opportunity renewal = new Opportunity();
       renewal.AccountId   = 'opp.AccountId';
       renewal.Name        = opp.Name + 'Renewal';
       renewal.CloseDate   = opp.CloseDate + 365;
       renewal.StageName   = 'Open';
       renewal.RecordType  = 'Renewal';
       renewal.OwnerId     = opp.OwnerId;
       renewals.put(renewal.Id, renewal);
    }
  }

   insert renewals;
}