• vishal kale
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
While i am connecting to the post is show authentication failure like this -
{
    "error": "invalid_grant",
    "error_description": "authentication failure"
}
I have also created the connected app.
I have fill the body data as form-data given below-:
1. end point url -: 'https://login.salesforce.com/services/oauth2/token'.
2. client_id - 'my clent id'.
3. client_secret -'my client secret'
4. grant_type - 'password'.
5.password- 'my salesforce org password'.

please see where i am wrong??
 
Ans:  Text, Text Area, Text Area Long, Rich Text Area, URL. Is this is the right answer or is there something else????

13. Can we change the data type from Text to Auto Number for the Name when we already have?

Ans: I feel the answer is yes. If yes, please do let me know the explanation . If no, let me know the reason as well. Thanks guys. 

 
Hi friends,

I could cover only 73% of code.
Code insde the for loop of pricebook entry is not covered.
Select query of opportunity is returning me 0 rows inside the test class.
Apex

global class RenewexistingOpp implements Schedulable 
{
   global void execute(SchedulableContext SC) 
   {
       NewOppFromexistingOpp Opp= new NewOppFromexistingOpp();
   }
   public class NewOppFromexistingOpp 
   {
       NewOppFromexistingOpp()
       {      
           Date d = Date.Today();
           Date ssdt= Date.newInstance(2014,1,1);
           User newUser=[select Id from user where Name='Jarin Stevens'];

            for(Opportunity oldOpp:[select Name,Amount,AccountId,Service_End_Date__c,Service_Start_Date__c,
            CloseDate,StageName,AutoProcessedFlag__c,Why_OP_Win_Details__c,Billing_Contact__c,Primary_Contact__c,
            Payment_Terms__c,Billing_Cycle__c from opportunity where StageName='Closed Won' And AutoProcessedFlag__c=false])
    {
   
    
                System.debug(oldOpp);
                if(oldOpp.Service_Start_Date__c!=NULL)
                {
        
                        if(oldOpp.Service_Start_Date__c >=ssdt && oldOpp.Service_End_Date__c>=d )  
                        {  
        
                            Opportunity newOpp= new Opportunity();
                            newOpp.Name=oldOpp.Name; 
                            newOpp.OwnerId=newUser.Id;
                            newOpp.CloseDate=oldOpp.Service_End_Date__c + 1;  
                            newOpp.StageName='Renewal - Decision';  

                            insert newOpp;
                             for(PriceBookEntry priceBookList:[select Id,UnitPrice,Pricebook2Id,Product2Id FROM PriceBookEntry where Product2.Name IN('Enterprise License','ObservePoint Platform - Contracted') And PriceBook2.isStandard=true])
                            {
                                OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
                                oli.OpportunityId = newOpp.Id;                           
                                oli.PricebookEntryId=priceBookList.Id;       
                                oli.UnitPrice =priceBookList.UnitPrice;                       
                                oli.Quantity=1;
                                insert oli;
                                
                            }
                            oldOpp.AutoProcessedFlag__c = true;
                           
                            upsert oldOpp;

                      }
                       
                 }
             
           }  
       }
    }
}
Test Class

@isTest (SeeAllData=false)

public class RenewexistingOppTest{

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

    
    static testmethod void RenewexistingOppTest() {
    Test.startTest();
    Date sed = Date.newInstance(2015, 9, 15);
    Date ssd= Date.newInstance(2014,1,1);
    Date cd= Date.newInstance(2017, 9, 15);
    Date d = Date.Today();
    List<PricebookEntry > pntr= new List<PricebookEntry >();
    
    Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
      User u = new User(Alias = 'standt', Email='standarduser@testorg.com', 
      EmailEncodingKey='UTF-8', LastName='wwy', LanguageLocaleKey='en_US',FirstName='wwx',
      LocaleSidKey='en_US', ProfileId = p.Id, 
      TimeZoneSidKey='America/Los_Angeles', UserName='abvc@gmail.com');
    
     insert u;
     
     User uid=[select Id from User where Name='wwx wwy' LIMIT 1];
    
    
      
    Account createAcc= new Account(Name='testAccount'); 
    insert createAcc;
    
    Campaign cmp = new Campaign(Name='Chidanand');
    insert cmp;
    
    Contact createCont=new Contact(FirstName='testContact1',LastName='testContact1',AccountId=createAcc.Id);
    insert createCont;
    
    
    Opportunity createOpp= new Opportunity(Name='TestNew2',Amount=500.00,AccountId=createAcc.Id,Service_End_Date__c=sed,
                                           Service_Start_Date__c=ssd,CampaignId=cmp.Id,NextStep='hi',CloseDate=cd,StageName='Closed Won',AutoProcessedFlag__c=false,
                                           Why_OP_Win_Details__c='Hi',Billing_Contact__c=createCont.Id,Primary_Contact__c=createCont.Id,
                                           Payment_Terms__c='Net 15',Billing_Cycle__c='Annual In Advance');  
    
                                  
    insert createOpp;
    
      
    Product2 createProd=new Product2(Name='ObservePoint Platform - Contracted');
    insert createProd; 
    
   // Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true]; 
        
        Id pricebookId = Test.getStandardPricebookId();                               
    
  //  PricebookEntry createPE=new PricebookEntry(Pricebook2Id=stdpb.Id,Product2Id=createProd.Id,UnitPrice=500,IsActive = true);
     
     PricebookEntry createPE=new PricebookEntry(Pricebook2Id=pricebookId,Product2Id=createProd.Id,UnitPrice=500,IsActive = true);
     insert createPE;
    
    String jobId = System.schedule('Schedule Opp From Opp',CRON_EXP,new RenewexistingOpp());
                        
    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));
         Test.stopTest();  
             
         for(Opportunity oldOpp:[select Id,Name,Amount,AccountId,Service_End_Date__c,Service_Start_Date__c,
           CloseDate,StageName,AutoProcessedFlag__c,NextStep,CampaignId,Why_OP_Win_Details__c,Billing_Contact__c,Primary_Contact__c,
           Payment_Terms__c,Billing_Cycle__c from opportunity where StageName=:'Closed Won' And AutoProcessedFlag__c=:false]){
           
           System.debug('hi1'); 
           if(oldOpp.Service_Start_Date__c!=NULL){
        
         System.debug('hi2'); 
                             if(oldOpp.Service_start_Date__c>=ssd && oldOpp.Service_End_Date__c>= d)  
                        {  
                        
                         System.debug('hi3'); 
                            Opportunity newOpp= new Opportunity();
                            newOpp.Name=oldOpp.Name; 
                            newOpp.StageName='Renewal - Decision'; 
                            
                            newOpp.OwnerId=uid.Id;
                           // newOpp.AccountId=oldOpp.AccountId; 
                            newOpp.CloseDate=oldOpp.Service_End_Date__c+1;    
                             insert newOpp;
                           
                           System.debug('hello');  
                           system.debug([select Id,UnitPrice,Pricebook2Id,Product2Id FROM PriceBookEntry where Product2.Name IN ('Enterprise License','ObservePoint Platform - Contracted')]);
                             
                             for(PriceBookEntry priceBookList:[select Id,UnitPrice,Pricebook2Id,Product2Id FROM PriceBookEntry])
                            {
                            
                                //system.debug([select Id,UnitPrice,Pricebook2Id,Product2Id FROM PriceBookEntry where Product2.Name IN ('Enterprise License','ObservePoint Platform - Contracted')]);
                            
                                OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
                                oli.OpportunityId = newOpp.Id;                           
                                oli.PricebookEntryId=priceBookList.Id; 
                               // oli.PricebookEntryId='00kJ0000008VXct';
                                oli.UnitPrice =priceBookList.UnitPrice;                       
                                oli.Quantity=1;
                                insert oli;
                                
                            }
                             
                            oldOpp.AutoProcessedFlag__c = true;
                              
                            upsert oldOpp;
                        
                        }
           }
           
           }
         
                 
    
    
    }
     
    }