• Chidanand Magadum 24
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 30
    Questions
  • 13
    Replies
Hi folks,

Could you plz tell me how to add custom vf page as a related list in standard object?
Hi friends,

The lines after If condition  if(numberDaysDue<=60) (NOTE: Condition is Meeting)  in my APEX code are not getting covered (These lines r shown in red color) . Any workaround Plz.


My Test Class
@isTest (seeAllData=true)  

public class RenewalTest{

public static String CRON_EXP = '0 0 0 15 3 ? 2022';

    RenewalOpportunity r= new RenewalOpportunity();
    
    static testmethod void RenewalTest() {
   // Test.startTest();
    
    String jobId = System.schedule('Chidanand',CRON_EXP,new RenewalOpportunity ());
                        
                        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered,
         NextFireTime
         FROM CronTrigger WHERE id = :jobId];
         
         System.assertEquals(CRON_EXP,
         ct.CronExpression);
         
         System.assertEquals(0, ct.TimesTriggered);
         System.assertEquals('2022-03-15 00:00:00',
         String.valueOf(ct.NextFireTime));
                        
    
    Date d = Date.Today();
    Date dueDate = date.newInstance(2015, 3, 20);
   // CSM__c csm= new CSM__c(Name='Chidanand',Customer_Success_Manager__c='Chidanand',Email='Chidanand@knstek.com');  
   // insert csm;
    Campaign c = new Campaign(Name='Chidanand');
    insert c;
    
    Product2 prod = new Product2(Name = 'Laptop X200',
            Family = 'Hardware');
        insert prod;
        
        
    
    
    Account a = new Account(Name='KNS',Service_End_Date__c=dueDate,Customer_Success_Manager__c='Jeff Tucker',ARR__c=500);
    insert a;
    Opportunity o = new Opportunity(Name='abc',AccountId=a.Id,CampaignId=c.Id,
                    StageName='Legal',Amount=5000,CloseDate=d,NextStep='Open',AutoCreatedFlag__c=false);
                    
    for(Account acc:[select Id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))]){
    
    if(a.Service_End_Date__c!=NULL){
    
        Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
        system.debug('Chidanand'+numberDaysDue);
        
        if(numberDaysDue<=60)  {
        
            Opportunity Op= new Opportunity();
            op.Name=a.Name;
            op.StageName='Legal';
            op.Amount=a.ARR__c;
            op.AccountId=a.ID;
            op.CloseDate=Date.today();
            op.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
            op.NextStep='Won';
           // op.OwnerID='005d0000001Kt9D';
            op.AutoCreatedFlag__c = true;
            insert op;
            
            System.debug('Hi Chidanand');
            
           // Id pricebookId = Test.getStandardPricebookId();
           List<PriceBookEntry> entryList = new List<PriceBookEntry>();
           Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true]; // Select Price Book
           PricebookEntry standardPrice = new PricebookEntry(
           Pricebook2Id = stdpb .Id, Product2Id = prod.Id,
           UnitPrice = 10, IsActive = true);
          // entryList.add(standardPrice );
           
           
           Integer counter = [select count()  FROM PriceBookEntry where Product2.Id=:prod.Id And
        PriceBook2.isStandard=true AND UnitPrice=10];
        
        entryList.add(standardPrice );
        if(counter==0){
        insert entryList;
        }
           
           
           
          // insert entryList;
           
           String z=prod.Id;
           
           
           List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry
           where (Product2.Id=:z) And (PriceBook2.isStandard=true) LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = op.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =10;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
           
           
        
        }
    
    }
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    }
    
    }



APEX CODE

global class RenewalOpportunity implements Schedulable {
       global void execute(SchedulableContext SC) {
           
                RenewalOpp R= new RenewalOpp();
           
           
       }
    
    public class RenewalOpp{

RenewalOpp(){
Date d = Date.Today();

for(Account a:[select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))])
{
    if(a.Service_End_Date__c!=NULL){
        
    // Difference between Service End date and Current date    
    Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
    
    if(numberDaysDue<=60)  {  
        
    // Creating a new opportunity  
    Opportunity O= new Opportunity();
    o.Name=a.Name;
    o.StageName='Legal';
    o.Amount=a.ARR__c;
    o.AccountId=a.ID;
    o.CloseDate=a.Service_End_Date__c;
    o.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
    o.NextStep='Won';
    o.OwnerID='005d0000001Kt9D';
    o.AutoCreatedFlag__c = true;
        insert o;
        
    
        
        List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry where Product2.Id='01td0000003SDB8' And
        PriceBook2.isStandard=true LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = o.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =a.ARR__c;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
                          
              }
    }
}
 }
 
 }
    
    
    
    }
Hi folks,
How to make visualforce page responsive?
Hi folks,

I am getting problem with test coverage.
I am getting test coverage of 0%
Actually i don't know how to link the test class with the Apex class.

Here is my APEX Code

global class RenewalOpportunity implements Schedulable {
       global void execute(SchedulableContext SC) {
           
                RenewalOpp R= new RenewalOpp();
           
           
       }
    
    public class RenewalOpp{

RenewalOpp(){
Date d = Date.Today();


for(Account a:[select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))])
{
    if(a.Service_End_Date__c!=NULL){
        
    // Difference between Service End date and Current date    
    Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
    
    if(numberDaysDue<=60)  {  
        
    // Creating a new opportunity  
    Opportunity O= new Opportunity();
    o.Name=a.Name;
    o.StageName='Legal';
    o.Amount=a.ARR__c;
    o.AccountId=a.ID;
    o.CloseDate=Date.today();
    o.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
    o.NextStep='Won';
    o.OwnerID='005d0000001Kt9D';
    o.AutoCreatedFlag__c = true;
        insert o;
        
       // Create a Pricebook Entry for Product
        
        List<OpportunityLineItem> oliList = new List <OpportunityLineItem>();
        Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true]; // Select Price Book
        List<PriceBookEntry> entryList = new List<PriceBookEntry>();
        PriceBookEntry pe= new PriceBookEntry();
        pe.Pricebook2Id=stdpb.Id;
        pe.Product2Id='01tJ0000003qkr0';
        pe.UnitPrice=10;  // Standard Price
        pe.IsActive=true;
        Integer counter = [select count()  FROM PriceBookEntry where Product2.Id='01tJ0000003qkr0' And
        PriceBook2.isStandard=true AND UnitPrice=10];
        
        entryList.add(pe);
        if(counter==0){
        insert entryList;
        }
        
        List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry where Product2.Id='01tJ0000003qkr0' And
        PriceBook2.isStandard=true LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = o.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =a.ARR__c;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
                          
              }
    }
}
 }
 
 }
    
    
    
    }



My Test Code

@isTest (seeAllData=true)  

public class RenewalTest{
    
    static testmethod void RenewalTest() {
    
    Date d = Date.Today();
    Date dueDate = date.newInstance(2015, 3, 20);
   // CSM__c csm= new CSM__c(Name='Chidanand',Customer_Success_Manager__c='Chidanand',Email='Chidanand@knstek.com');  
   // insert csm;
    Campaign c = new Campaign(Name='Chidanand');
    insert c;
    
    Product2 prod = new Product2(Name = 'Laptop X200',
            Family = 'Hardware');
        insert prod;
        
        
    
    
    Account a = new Account(Name='KNS',Service_End_Date__c=dueDate,Customer_Success_Manager__c='Jeff Tucker',ARR__c=500);
    insert a;
    Opportunity o = new Opportunity(Name='abc',AccountId=a.Id,CampaignId=c.Id,
                    StageName='Legal',Amount=5000,CloseDate=d,NextStep='Open',AutoCreatedFlag__c=false);
                    
    for(Account acc:[select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))]){
    
    if(a.Service_End_Date__c!=NULL){
    
        Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
        
        if(numberDaysDue<=60)  {
        
            Opportunity Op= new Opportunity();
            op.Name=a.Name;
            op.StageName='Legal';
            op.Amount=a.ARR__c;
            op.AccountId=a.ID;
            op.CloseDate=Date.today();
            op.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
            op.NextStep='Won';
            op.OwnerID='005d0000001Kt9D';
            op.AutoCreatedFlag__c = true;
            insert op;
            
           // Id pricebookId = Test.getStandardPricebookId();
           List<PriceBookEntry> entryList = new List<PriceBookEntry>();
           Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true]; // Select Price Book
           PricebookEntry standardPrice = new PricebookEntry(
           Pricebook2Id = stdpb .Id, Product2Id = prod.Id,
           UnitPrice = 10, IsActive = true);
          // entryList.add(standardPrice );
           
           
           Integer counter = [select count()  FROM PriceBookEntry where Product2.Id=:prod.Id And
        PriceBook2.isStandard=true AND UnitPrice=10];
        
        entryList.add(standardPrice );
        if(counter==0){
        insert entryList;
        }
           
           
           
          // insert entryList;
           
           String z=prod.Id;
           
           
           List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry
           where (Product2.Id=:z) And (PriceBook2.isStandard=true) LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = op.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =10;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
           
           
        
        }
    
    }
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    }
    
    }



 
Hi friends,

Is there any way to create a master-detail relationship between Product2 and Junction Object.
Hi folks,

On click of a custom link, i wanna open the new link. How can v achieve this? Any code help.
Hi folks,

I have a link within visualforce page. When i click on the link, it is opening in the same page. How to open the link on another new tab. Neeed code help.
Hi folks,
             can anyone tell me the Javascript/JQuery or apex code (or vf page) to drag and drop files from desktop to salesforce?



 
Hi folks,

Is it Possible to create related list within another related list? If so, How can v achieve this?
Hi all,
I am getting the following error for my code. Any workaround.

Line: 47, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, This price definition already exists in this price book: []

Code.

Date d = Date.Today();
 List<Account> AllAccounts= new List<Account>([select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c,(Select Name from Opportunities) from Account ]);
 Map<String,Set<String>> MapAccwithOpps =new Map<String,Set<String>>();
List<PriceBookEntry> entryList = new List<PriceBookEntry>();
for(Account a:AllAccounts)
 {
 Set<String> Oppnames = new Set<String>();
    //string Oppnames='';
    for(Opportunity opp:a.Opportunities)
        {
            Oppnames.add(opp.Name);
        }
    MapAccwithOpps.put(a.Name,Oppnames);
    }
    system.debug('MapAccwithOpps==='+MapAccwithOpps);
 for(Account a:AllAccounts)
 {
    //Integer numberDaysDue= a.Service_End_Date__c.daysBetween(d);
    if(a.Service_End_Date__c!=NULL){
    
        Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
    
 if(numberDaysDue<=60)
 {
    Opportunity O= new Opportunity();
    o.Name=a.Name;
    o.StageName='Legal';
    o.Amount=a.ARR__c;
    o.AccountId=a.ID;
    o.CloseDate=Date.today();
    o.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
    o.NextStep='Won';
    o.OwnerID='005d0000001Kt9D';
    if(!(MapAccwithOpps.get(a.Name).contains(o.Name))) {
        insert o;
    }
        List<Opportunity> AllOpps = new List<Opportunity>([select id,Name from Opportunity where Name='o.Name']);
        List<OpportunityLineItem> oliList = new List <OpportunityLineItem>();
        Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true];
        //List<PriceBookEntry> entryList = new List<PriceBookEntry>();
        PriceBookEntry pe= new PriceBookEntry();
        pe.Pricebook2Id=stdpb.Id;
        pe.Product2Id='01tJ0000003qkev';
        pe.UnitPrice=500;
        pe.IsActive=true;
        entryList.add(pe);
        insert pe;
     
        List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry where Product2.Id='01tJ0000003qkev' And
        PriceBook2.isStandard=true LIMIT 1 ];
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.OpportunityId = o.Id;
        oli.PricebookEntryId=priceBookList[0].Id;
        oli.UnitPrice = 500;
        oli.Quantity=5;
        insert oli;
        
    }
    }

 
 }





 
Hi guyz,
            when i run the below code, it is giving me the exception.(Line: 51, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId, unknown (versions 3.0 and higher must specify pricebook entry id, others must specify product id): [PricebookEntryId, unknown])




Date d = Date.Today();
 List<Account> AllAccounts= new List<Account>([select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c,(Select Name from Opportunities) from Account ]);
 Map<String,Set<String>> MapAccwithOpps =new Map<String,Set<String>>();
 for(Account a:AllAccounts)
 {
 Set<String> Oppnames = new Set<String>();
    //string Oppnames='';
    for(Opportunity opp:a.Opportunities)
        {
            Oppnames.add(opp.Name);
        }
    MapAccwithOpps.put(a.Name,Oppnames);
    }
    system.debug('MapAccwithOpps==='+MapAccwithOpps);
 for(Account a:AllAccounts)
 {
    //Integer numberDaysDue= a.Service_End_Date__c.daysBetween(d);
    if(a.Service_End_Date__c!=NULL){
    
        Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
    
 if(numberDaysDue<=60)
 {
    Opportunity O= new Opportunity();
    o.Name=a.Name;
    o.StageName='Legal';
    o.Amount=a.ARR__c;
    o.AccountId=a.ID;
    o.CloseDate=Date.today();
    o.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
    o.NextStep='Won';
    o.OwnerID='005d0000001Kt9D';
    if(!(MapAccwithOpps.get(a.Name).contains(o.Name))) {
        insert o;
        
        List<Opportunity> AllOpps = new List<Opportunity>([select id,Name from Opportunity where Name='o.Name']);
        List<OpportunityLineItem> oliList = new List <OpportunityLineItem>();
        Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true];
        List<PriceBookEntry> entryList = new List<PriceBookEntry>();
        PriceBookEntry pe= new PriceBookEntry();
        pe.Pricebook2Id=stdpb.Id;
        pe.Product2Id='01tJ0000003qkck';
        pe.UnitPrice=500;
        //entryList.add(pe);
        insert entryList;
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.OpportunityId = o.Id;
        oli.PricebookEntryId=pe.Id;
        oli.UnitPrice = 500;
        oli.Quantity=5;
        insert oli;
        //PriceBookEntry pe= new PriceBookEntry();
        //List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry where Product2.Id='01tJ0000003qkck' And
       // PriceBook2.isStandard=true LIMIT 1];
        //OpportunityLineItem oli = new OpportunityLineItem();
        //oli.OpportunityId = o.Id;
        //oli.PricebookEntryId=priceBookList[0].Id;
        //oli.PricebookEntryId=stdpb.Id;
        //priceBookList[0].UnitPrice=100;
        //oli.UnitPrice = a.ARR__c;
        //oli.UnitPrice = 500;
        //oli.Quantity=5;
        //oliList.add(oli);
        //AllOpps.add(oliList);
        //update(AllOpps);
        //insert oli;
        
        }
        
        
    }
    }
// system.debug('Diff==='+numberDaysDue);
 
 }
Hi guys,
How to create an Opportunity Line Item for an opportunity Using API?(Apex)
Hi guys,

What is google analytics and how is it related to salesforce?
Hi guys,

What is the relationship between Opportunity,OpportunityLineItem, Opportunity Products and Products?
Is opportunityLineItem same as that of the Opportunity Products?
Hi folks,

Is it possible to set a value to the Rollup summary field through Apex?
Hi Guys,

Is it possible to change the owner of the record through Apex code? If so, how to achieve it?
HI all,

This is my code
Date d = Date.Today();
 List<Account> AllAccounts= new List<Account>([select id,Name,Relationship_Start_Date__c,ARR__c,(Select Name from Opportunities) from Account ]);
 Map<String,Set<String>> MapAccwithOpps =new Map<String,Set<String>>();
 for(Account a:AllAccounts)
 {
 Set<String> Oppnames = new Set<String>();
    //string Oppnames='';
    for(Opportunity opp:a.Opportunities)
        {
            Oppnames.add(opp.Name);
        }
    MapAccwithOpps.put(a.Name,Oppnames);
    }
    system.debug('MapAccwithOpps==='+MapAccwithOpps);
 for(Account a:AllAccounts)
 {
    Integer numberDaysDue= a.Relationship_Start_Date__c.daysBetween(d);
 if(numberDaysDue<=60)
 {
    Opportunity O= new Opportunity();
    o.Name=a.Name;
    o.StageName='Legal';
    o.Amount=a.ARR__c;
    o.AccountId=a.ID;
    o.CloseDate=Date.today();
    o.NextStep='Won';
    if(!(MapAccwithOpps.get(a.Name).contains(o.Name)))
        insert o;
    }
 system.debug('Diff==='+numberDaysDue);
 
 }


How to create a scheduled job for this. I want to run this code every day Automatically.
Hi Guyz,
I am creating an opportunity whose name is same as that of the Account based on the criteria.
Now After creating an opportunity,Again when we run the script it should not create another opportunity if the opportunity name whose name which is same as that of the account name is found.

How to Proceed further to achieve this.
Here is My code.

Date  d = Date.Today();
List<Account> AllAccounts= new List<Account>([select id,Name,ARR__c,Relationship_Start_Date__c,
                                              (Select Id,Account.Id from Opportunities) from Account]);
                                              

for(Account a:AllAccounts)
{
    
    Integer numberDaysDue= a.Relationship_Start_Date__c.daysBetween(d);
    if(numberDaysDue<=60){
       
        Opportunity O= new Opportunity();
        o.Name=a.Name;
        o.StageName='Legal';
        o.Amount=a.ARR__c;
        o.AccountId=a.ID;
        o.CloseDate=Date.today();
        o.NextStep='Won';
        system.debug('Account Id'+o.AccountId);
        insert o;
      
    }
}
Hi friends,

I how do i check if the record already exists or not in the database.
If the perticular record already exists then no need to insert it.
Else, insert the record.

Here is my code

Date  d = Date.Today();
List<Account> AllAccounts= new List<Account>([select id,Name,ARR__c,Relationship_Start_Date__c,
                                              (Select Id,Account.Id from Opportunities) from Account]);
for(Account a:AllAccounts)
{
    
    Integer numberDaysDue= a.Relationship_Start_Date__c.daysBetween(d);
    if(numberDaysDue<=60){
       
        Opportunity O= new Opportunity();
        o.StageName='Legal';
        o.Amount=a.ARR__c;
        o.AccountId=a.ID;
        o.Name=o.AccountId  +'Opportunity';
        o.CloseDate=Date.today();
        o.NextStep='Won';
        system.debug('Account Id'+o.AccountId);
        insert o;
      
    }
   
    
    system.debug('Diff==='+numberDaysDue);
 
}
Hi,
I am getting null Pointer exception in this code while finding difference between two dates. Any workaround

Date d = Date.Today();
system.debug(d);
List<Account> AllAccounts= new List<Account>([select id,ARR__c,Relationship_Start_Date__c from Account]);
for(Account a:AllAccounts)
{

system.debug('Date==='+d);
system.debug('Trans Date'+a.Relationship_Start_Date__c);
Integer numberDaysDue= d.daysBetween(a.Relationship_Start_Date__c);
system.debug('Diff==='+numberDaysDue);
}
Hey Friends,
     Is it Possible to override 'New' button of standard object 'Product' with visualforce page.?
     Plz tell me itz very urgent.
 
Hi friends,

The lines after If condition  if(numberDaysDue<=60) (NOTE: Condition is Meeting)  in my APEX code are not getting covered (These lines r shown in red color) . Any workaround Plz.


My Test Class
@isTest (seeAllData=true)  

public class RenewalTest{

public static String CRON_EXP = '0 0 0 15 3 ? 2022';

    RenewalOpportunity r= new RenewalOpportunity();
    
    static testmethod void RenewalTest() {
   // Test.startTest();
    
    String jobId = System.schedule('Chidanand',CRON_EXP,new RenewalOpportunity ());
                        
                        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered,
         NextFireTime
         FROM CronTrigger WHERE id = :jobId];
         
         System.assertEquals(CRON_EXP,
         ct.CronExpression);
         
         System.assertEquals(0, ct.TimesTriggered);
         System.assertEquals('2022-03-15 00:00:00',
         String.valueOf(ct.NextFireTime));
                        
    
    Date d = Date.Today();
    Date dueDate = date.newInstance(2015, 3, 20);
   // CSM__c csm= new CSM__c(Name='Chidanand',Customer_Success_Manager__c='Chidanand',Email='Chidanand@knstek.com');  
   // insert csm;
    Campaign c = new Campaign(Name='Chidanand');
    insert c;
    
    Product2 prod = new Product2(Name = 'Laptop X200',
            Family = 'Hardware');
        insert prod;
        
        
    
    
    Account a = new Account(Name='KNS',Service_End_Date__c=dueDate,Customer_Success_Manager__c='Jeff Tucker',ARR__c=500);
    insert a;
    Opportunity o = new Opportunity(Name='abc',AccountId=a.Id,CampaignId=c.Id,
                    StageName='Legal',Amount=5000,CloseDate=d,NextStep='Open',AutoCreatedFlag__c=false);
                    
    for(Account acc:[select Id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))]){
    
    if(a.Service_End_Date__c!=NULL){
    
        Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
        system.debug('Chidanand'+numberDaysDue);
        
        if(numberDaysDue<=60)  {
        
            Opportunity Op= new Opportunity();
            op.Name=a.Name;
            op.StageName='Legal';
            op.Amount=a.ARR__c;
            op.AccountId=a.ID;
            op.CloseDate=Date.today();
            op.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
            op.NextStep='Won';
           // op.OwnerID='005d0000001Kt9D';
            op.AutoCreatedFlag__c = true;
            insert op;
            
            System.debug('Hi Chidanand');
            
           // Id pricebookId = Test.getStandardPricebookId();
           List<PriceBookEntry> entryList = new List<PriceBookEntry>();
           Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true]; // Select Price Book
           PricebookEntry standardPrice = new PricebookEntry(
           Pricebook2Id = stdpb .Id, Product2Id = prod.Id,
           UnitPrice = 10, IsActive = true);
          // entryList.add(standardPrice );
           
           
           Integer counter = [select count()  FROM PriceBookEntry where Product2.Id=:prod.Id And
        PriceBook2.isStandard=true AND UnitPrice=10];
        
        entryList.add(standardPrice );
        if(counter==0){
        insert entryList;
        }
           
           
           
          // insert entryList;
           
           String z=prod.Id;
           
           
           List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry
           where (Product2.Id=:z) And (PriceBook2.isStandard=true) LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = op.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =10;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
           
           
        
        }
    
    }
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    }
    
    }



APEX CODE

global class RenewalOpportunity implements Schedulable {
       global void execute(SchedulableContext SC) {
           
                RenewalOpp R= new RenewalOpp();
           
           
       }
    
    public class RenewalOpp{

RenewalOpp(){
Date d = Date.Today();

for(Account a:[select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))])
{
    if(a.Service_End_Date__c!=NULL){
        
    // Difference between Service End date and Current date    
    Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
    
    if(numberDaysDue<=60)  {  
        
    // Creating a new opportunity  
    Opportunity O= new Opportunity();
    o.Name=a.Name;
    o.StageName='Legal';
    o.Amount=a.ARR__c;
    o.AccountId=a.ID;
    o.CloseDate=a.Service_End_Date__c;
    o.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
    o.NextStep='Won';
    o.OwnerID='005d0000001Kt9D';
    o.AutoCreatedFlag__c = true;
        insert o;
        
    
        
        List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry where Product2.Id='01td0000003SDB8' And
        PriceBook2.isStandard=true LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = o.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =a.ARR__c;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
                          
              }
    }
}
 }
 
 }
    
    
    
    }
Hi folks,

I am getting problem with test coverage.
I am getting test coverage of 0%
Actually i don't know how to link the test class with the Apex class.

Here is my APEX Code

global class RenewalOpportunity implements Schedulable {
       global void execute(SchedulableContext SC) {
           
                RenewalOpp R= new RenewalOpp();
           
           
       }
    
    public class RenewalOpp{

RenewalOpp(){
Date d = Date.Today();


for(Account a:[select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))])
{
    if(a.Service_End_Date__c!=NULL){
        
    // Difference between Service End date and Current date    
    Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
    
    if(numberDaysDue<=60)  {  
        
    // Creating a new opportunity  
    Opportunity O= new Opportunity();
    o.Name=a.Name;
    o.StageName='Legal';
    o.Amount=a.ARR__c;
    o.AccountId=a.ID;
    o.CloseDate=Date.today();
    o.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
    o.NextStep='Won';
    o.OwnerID='005d0000001Kt9D';
    o.AutoCreatedFlag__c = true;
        insert o;
        
       // Create a Pricebook Entry for Product
        
        List<OpportunityLineItem> oliList = new List <OpportunityLineItem>();
        Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true]; // Select Price Book
        List<PriceBookEntry> entryList = new List<PriceBookEntry>();
        PriceBookEntry pe= new PriceBookEntry();
        pe.Pricebook2Id=stdpb.Id;
        pe.Product2Id='01tJ0000003qkr0';
        pe.UnitPrice=10;  // Standard Price
        pe.IsActive=true;
        Integer counter = [select count()  FROM PriceBookEntry where Product2.Id='01tJ0000003qkr0' And
        PriceBook2.isStandard=true AND UnitPrice=10];
        
        entryList.add(pe);
        if(counter==0){
        insert entryList;
        }
        
        List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry where Product2.Id='01tJ0000003qkr0' And
        PriceBook2.isStandard=true LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = o.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =a.ARR__c;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
                          
              }
    }
}
 }
 
 }
    
    
    
    }



My Test Code

@isTest (seeAllData=true)  

public class RenewalTest{
    
    static testmethod void RenewalTest() {
    
    Date d = Date.Today();
    Date dueDate = date.newInstance(2015, 3, 20);
   // CSM__c csm= new CSM__c(Name='Chidanand',Customer_Success_Manager__c='Chidanand',Email='Chidanand@knstek.com');  
   // insert csm;
    Campaign c = new Campaign(Name='Chidanand');
    insert c;
    
    Product2 prod = new Product2(Name = 'Laptop X200',
            Family = 'Hardware');
        insert prod;
        
        
    
    
    Account a = new Account(Name='KNS',Service_End_Date__c=dueDate,Customer_Success_Manager__c='Jeff Tucker',ARR__c=500);
    insert a;
    Opportunity o = new Opportunity(Name='abc',AccountId=a.Id,CampaignId=c.Id,
                    StageName='Legal',Amount=5000,CloseDate=d,NextStep='Open',AutoCreatedFlag__c=false);
                    
    for(Account acc:[select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))]){
    
    if(a.Service_End_Date__c!=NULL){
    
        Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
        
        if(numberDaysDue<=60)  {
        
            Opportunity Op= new Opportunity();
            op.Name=a.Name;
            op.StageName='Legal';
            op.Amount=a.ARR__c;
            op.AccountId=a.ID;
            op.CloseDate=Date.today();
            op.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
            op.NextStep='Won';
            op.OwnerID='005d0000001Kt9D';
            op.AutoCreatedFlag__c = true;
            insert op;
            
           // Id pricebookId = Test.getStandardPricebookId();
           List<PriceBookEntry> entryList = new List<PriceBookEntry>();
           Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true]; // Select Price Book
           PricebookEntry standardPrice = new PricebookEntry(
           Pricebook2Id = stdpb .Id, Product2Id = prod.Id,
           UnitPrice = 10, IsActive = true);
          // entryList.add(standardPrice );
           
           
           Integer counter = [select count()  FROM PriceBookEntry where Product2.Id=:prod.Id And
        PriceBook2.isStandard=true AND UnitPrice=10];
        
        entryList.add(standardPrice );
        if(counter==0){
        insert entryList;
        }
           
           
           
          // insert entryList;
           
           String z=prod.Id;
           
           
           List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry
           where (Product2.Id=:z) And (PriceBook2.isStandard=true) LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = op.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =10;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
           
           
        
        }
    
    }
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    }
    
    }



 
Hi folks,

On click of a custom link, i wanna open the new link. How can v achieve this? Any code help.
Hi folks,

Is it Possible to create related list within another related list? If so, How can v achieve this?
Hi guys,

What is the relationship between Opportunity,OpportunityLineItem, Opportunity Products and Products?
Is opportunityLineItem same as that of the Opportunity Products?
Hi Guys,

Is it possible to change the owner of the record through Apex code? If so, how to achieve it?
Hi friends,

I how do i check if the record already exists or not in the database.
If the perticular record already exists then no need to insert it.
Else, insert the record.

Here is my code

Date  d = Date.Today();
List<Account> AllAccounts= new List<Account>([select id,Name,ARR__c,Relationship_Start_Date__c,
                                              (Select Id,Account.Id from Opportunities) from Account]);
for(Account a:AllAccounts)
{
    
    Integer numberDaysDue= a.Relationship_Start_Date__c.daysBetween(d);
    if(numberDaysDue<=60){
       
        Opportunity O= new Opportunity();
        o.StageName='Legal';
        o.Amount=a.ARR__c;
        o.AccountId=a.ID;
        o.Name=o.AccountId  +'Opportunity';
        o.CloseDate=Date.today();
        o.NextStep='Won';
        system.debug('Account Id'+o.AccountId);
        insert o;
      
    }
   
    
    system.debug('Diff==='+numberDaysDue);
 
}
Hi Friends,

How to find out the difference between two dates in APEX which are in two different formats.
date1=dd/mm/yyyy
date2=mm/dd/yyyy
Hai All,

How to create new opportunity Using Apex Code. Any Code help Please.
Hi folks,

I wanna create a new record in my maintenance custom  object automatically when the status field of the standard Product object is changed to 'Out of maintenance'. So could any one please help me in writing trigger for the same. 
Hey Friends,
     Is it Possible to override 'New' button of standard object 'Product' with visualforce page.?
     Plz tell me itz very urgent.