• sudhIr Narayan
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 11
    Replies
Hi, 

  How to add multiple IF condition  Please suggest am getting error
 
IF
(
ISPICKVAL(StageName,'Closed Won') ||
ISPICKVAL(StageName,'Closed Other') ||
ISPICKVAL(StageName,'Closed Direct') ||
ISPICKVAL(StageName,'Closed VAR') ||
ISPICKVAL(StageName,'Closed Partial') ||
ISPICKVAL(StageName,'Closed Received') ||
ISPICKVAL(StageName,'Closed End User to VAR') ||
ISPICKVAL(StageName,'Closed VAR to Disty') ||
ISPICKVAL(StageName,'Closed Disty to Meru') 
)
IF( NSP_Not_Appoved_Count__c  > 0 )

 
Hi, 

 I need a clarification on access. 

How to give account access to another user on termination of user Please let me know

Thanks
Sudhir
Hi,

 Please suggest me am find challenge in improving performance in code coverage. Please advice me if this code is correct or not how to modify to get more code coverage. 

 Below code is working perfect only issue is with code coverage. 
 
trigger NewDiscountProgramUpdate on Opportunity (Before Update) 
{
// ******** Trigger Created By Sudhir ************  
// Loop through the incoming records

  list<opportunity> opp = new list<opportunity>();


for (Opportunity o : Trigger.new) {       
    
        
   // Check for Deal Reg Not Null
 if ( o.FORCE_NSP__c == NULL && o.discount_program__c <> 'NSP' && o.Deal_Registration__c <> NULL ) 
   {
     if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'No' && o.K_12__c == 'No'  ) 
      {
        o.discount_program__c = 'DEALREG/PI';
        o.Abbv_Discount_Program__c = 'DR/PI';        
      }
     else if ( o.Partner_Driven__c == 'No'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No'  ) 
     {
        o.discount_program__c = 'DEALREG/PL';
        o.Abbv_Discount_Program__c = 'DR/PL';    
     }
     else if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No'  ) 
     {
       o.discount_program__c = 'DEALREG/PI/PL';
       o.Abbv_Discount_Program__c = 'DR/PI/PL';  
     }
     else if ( o.Partner_Driven__c == 'No'  && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' ) 
     {
       o.discount_program__c = 'DEALREG/K-12';
       o.Abbv_Discount_Program__c = 'DR/K12';    
     }
     else if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' )
     {
       o.discount_program__c = 'DEALREG/PI/K-12';
       o.Abbv_Discount_Program__c = 'DR/PI/K12';    
     }
     else if (   o.Partner_Driven__c == 'No'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes'  )
     {
       o.discount_program__c = 'DEALREG/PL/K-12';
       o.Abbv_Discount_Program__c = 'DR/PL/K12';   
     }
     else if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes' )
     {
       o.discount_program__c = 'DEALREG/PI/PL/K-12';
       o.Abbv_Discount_Program__c = 'DR/PI/PL/K12';   
     }
    else  
     {
     o.discount_program__c = 'DEALREG';
     o.Abbv_Discount_Program__c = 'DR';     
     } 
    }
     opp.add(o);
 }   
     
 
}


Please advice me also how to write test class for above trigger I wrote a test class which is giving only 14% code coverage. 

Thanks

Sudhir

Hi

I wrote a trigger on opportunity to update a custom field called discount program 
 
trigger NewDiscountProgramUpdate on Opportunity (After Insert, Before Update) 
{
// ******** Trigger Created By Sudhir ************  
// Loop through the incoming records

  list<opportunity> opp = new list<opportunity>();


for (Opportunity o : Trigger.new) {       
    
        
   // Check for Deal Reg Not Null
 if ( o.FORCE_NSP__c == NULL && o.discount_program__c <> 'NSP' && o.Deal_Registration__c <> NULL ) 
   {
     if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'No' && o.K_12__c == 'No'  ) 
      {
        o.discount_program__c = 'DEALREG/PI';
        o.Abbv_Discount_Program__c = 'DR/PI';        
      }
     else if ( o.Partner_Driven__c == 'No'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No'  ) 
     {
        o.discount_program__c = 'DEALREG/PL';
        o.Abbv_Discount_Program__c = 'DR/PL';    
     }
     else if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No'  ) 
     {
       o.discount_program__c = 'DEALREG/PI/PL';
       o.Abbv_Discount_Program__c = 'DR/PI/PL';  
     }
     else if ( o.Partner_Driven__c == 'No'  && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' ) 
     {
       o.discount_program__c = 'DEALREG/K-12';
       o.Abbv_Discount_Program__c = 'DR/K12';    
     }
     else if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' )
     {
       o.discount_program__c = 'DEALREG/PI/K-12';
       o.Abbv_Discount_Program__c = 'DR/PI/K12';    
     }
     else if (   o.Partner_Driven__c == 'No'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes'  )
     {
       o.discount_program__c = 'DEALREG/PL/K-12';
       o.Abbv_Discount_Program__c = 'DR/PL/K12';   
     }
     else if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes' )
     {
       o.discount_program__c = 'DEALREG/PI/PL/K-12';
       o.Abbv_Discount_Program__c = 'DR/PI/PL/K12';   
     }
    else  
     {
     o.discount_program__c = 'DEALREG';
     o.Abbv_Discount_Program__c = 'DR';     
     } 
    }
     opp.add(o);
 }   
     
 
}

For the above trigger I wrote a test class to get code coverage its showing only 14% Please suggest me how to get more code coverage please suggest me how to modify the code
 
@isTest(SeeAllData = true)
private class   Test_Insert_Opp {

    public static testmethod void testopp()
    {    
      
 test.startTest();

Opportunity opp = new Opportunity (Name='Test Opp', closeDate=system.today(),recordtypeId = '0123000000094yH',
                                    accountId = '0013000000DULXG',ForecastCategoryName = 'Pipeline',Government_Contract__c = 'None',
                                    StageName ='Renewal',Type='Existing Customer',Pricebook2Id='01s60000000AKxZAAW',
                                    Primary_Competitor__c = 'No Competitor', LeadSource='Renewal', 
                                    ownerid='00560000001vfE5AAI',Channel_Source__c='Distributor',Discount_Program__c='NSP'
                                    ); 
                                     
        insert opp;

 test.stopTest();

} 

}

Thanks
Sudhir

Hi, 

 I am not able update opportunity SyncedQuoteId with quote Please suggest me some steps this is new method for me


trigger update_quote_id on Quote (after insert) {
 
 List <Quote> Qo= [ select id,opportunityid from quote where id = :Trigger.newMap.keySet()];
 
 for ( Quote Qt : Qo)
  {
   
     if ( Qt.opportunityid <> null ) 
     {
     
    list <opportunity> op = [select id,SyncedQuoteId from opportunity where id = :Qt.opportunityid];  
      
     
     for ( opportunity opp: op )
      {
       
       opp.SyncedQuoteId = Qt.id;              
       
       update opp;
      }
       
   
     }
  }
  
}


Thanks

Sudhir

Hi, 

 I want to save only 80 character in a text field if user enters more than 80 i want to cut remaining and add only 80 characters please suggest me how to do this 

Thanks
Sudhir
Hi, 

  I am getting error while update values in opportunity I am trying to update I get below error

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Public_Opportunity_View_trg caused an unexpected exception, contact your administrator: Public_Opportunity_View_trg: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.Public_Opportunity_View_trg: line 48, column 1

trigger Public_Opportunity_View_trg on Opportunity (After Insert, After Update,After Delete) {

/* Fires during INSERT */
if(trigger.isInsert)
{
   List<Public_Opportunity_View__c> POVi = new list<Public_Opportunity_View__c>();
  
for(Opportunity opp :trigger.new)
  {
   Public_Opportunity_View__c POV = new Public_Opportunity_View__c();
      POV.Account_ID__c = opp.accountid;
      POV.Opportunity_ID__c    =  opp.ID;
      POV.Close_Date__c        =  opp.CloseDate;
      POV.Opportunity_Name__c  =  opp.Name;
      POV.Stage__c             =  opp.StageName;
      POVi.add(POV);
  
    }
    
     Insert POVi;
  
   }

/* Fires during UPDATE */
if(trigger.isUpdate)
   {
   Set<ID> Oppid = Trigger.newMap.keySet();
     
   List<Opportunity> OppUp = new List<Opportunity >();  
     
   OppUp = [SELECT  Id,accountid, CloseDate, Name, StageName FROM Opportunity WHERE id in :Oppid];
  
    List<Public_Opportunity_View__c> POVu = new list<Public_Opportunity_View__c>();
   
     for(Opportunity oppu :OppUp)
      {
       Public_Opportunity_View__c POVV = new Public_Opportunity_View__c();
        POVV.Account_ID__c        =  oppu.accountid;
        POVV.Opportunity_ID__c    =  oppu.ID;
        POVV.Close_Date__c        =  oppu.CloseDate;
        POVV.Opportunity_Name__c  =  oppu.Name;
        POVV.Stage__c             =  oppu.StageName;
        POVu.add(POVV);
       }
      
       if(POVu.size()>0)
       {
       Update POVu;
        }
    } 
 
/* Fires during DELETE*/
if(Trigger.isDelete)
{
   List<Id> DoppId = new List<Id>();
   for(Opportunity opp: Trigger.old) { 
      DoppId.add(opp.id);
   }
  
     List<Public_Opportunity_View__c> existopp = [Select Id from Public_Opportunity_View__c where Opportunity_ID__c in :DoppId];
    
     Delete  existopp;
  
  

  }


       
       
    }

Please suggest me how to fix this issue. 

Thanks
Sudhir
Hi,

 Can we prepare report based on appoved time how much time user is taking to approve user wants to see time in 12hours Please suggest.

Thanks
Sudhir
Hi,

 There is a request from user he s asking question as below is this possible to give access please let me know

Please allow Henry access to my SFDC profile howellasd@zest.com so he can view the team forecast while I am on holiday
Im happy for this to be a permanent change in his profile



Thanks
Sudhir

Hi, 

 I am trying to update a triggr in production which has no error and 100% code coverage but while deploying it gives error of another trigger which is having 0% code coverage error Please suggest me how to deploy 

Thanks

Sudhir

Hi, 

 Created a custom object in fullcopy with name Temp_Assets__c have created few formula fields on this object  created a trigger on this object to insert data into this object also wrote a test class on this trigger which is 100% code coverage

 Problem am facing is am not able to deploy this to production i get error 
trigger Temp_Asset2_Opp on Temp_Assets__c (after insert )
{
    List<OpportunityLineItem> OppLineItems = new List<OpportunityLineItem>();
    
    List<Temp_Assets__c> CurrentAsset = [Select Id, Name, PriceBook_Name__c, Asset_Id__c, Serial_Number__c, AccountId__c, Product__c, Service_Start_Date__c,
                                              Service_End_Date__c ,Install_Date__c ,Reseller__c,Distributor__c,
                                              Incumbent_Reseller__c,Education__c,Expiry_Date__c,Existing_Opportunity__c,
                                              New_Opportunity__c,Expiry_Term__c,Bundle_Support__c, X5_Year_SKU_Code__c, X3_Year_SKU_Code__c,
                                              X1_Year_SKU_Code__c, Monthly_SKU_Code__c, X5_year_SKU__c ,X3_year_SKU__c, X1_year_SKU__c,
                                              Total_in_Months__c, Support_Only_5_Year_SKU__c, Support_Only_3_Year_SKU__c, Support_Only_1_Year_SKU__c,
                                              Support_Only_Monthly_SKU__c, DaysRemaining_Months__c, Monthly_Quote__c, Total_Monthly_Quote_term__c
                                         From Temp_Assets__c 
                                         Where CreatedById = :userinfo.getUserId()];
                                         
    List<Temp_Assets__c> CurrentAsset1 = [Select Id, Name, PriceBook_Name__c, Opp_Close_Date__c, Asset_Id__c, Serial_Number__c, AccountId__c, Product__c, Service_Start_Date__c,
                                              Service_End_Date__c ,Install_Date__c ,Reseller__c,Distributor__c ,
                                              Incumbent_Reseller__c,Education__c,Expiry_Date__c,Existing_Opportunity__c,
                                              New_Opportunity__c,Expiry_Term__c,Bundle_Support__c, X5_Year_SKU_Code__c, X3_Year_SKU_Code__c,
                                              X1_Year_SKU_Code__c, Monthly_SKU_Code__c, X5_year_SKU__c ,X3_year_SKU__c, X1_year_SKU__c,
                                              Total_in_Months__c, Support_Only_5_Year_SKU__c, Support_Only_3_Year_SKU__c, Support_Only_1_Year_SKU__c,
                                              Support_Only_Monthly_SKU__c, DaysRemaining_Months__c
                                         From Temp_Assets__c 
                                         Where CreatedById = :userinfo.getUserId() Limit 1];
    
    //Pricebook2 prBook1= [select id from Pricebook2 where Name=: 'NAM Price Book'];
   
    RecordType renewal_RT = [Select id, Name, sObjectType from RecordType where sObjectType= 'Opportunity' and Name = 'Renewal Opportunity' ];
    set<id> existingOppId= new Set<id>();
    List<Opportunity> opport = new List<Opportunity>();
    set<id> newOppId = new set<id>();
    //String variable to store the name of the pricebook for this Opportunity
    String priceBookName;
    
    for (Temp_Assets__c temp: currentAsset1) {
        existingOppId.add(temp.Existing_Opportunity__c);
        priceBookName = temp.priceBook_Name__c;
    }
    
    Map<Id, String> productNameToId = new Map<Id, String>();
    //Get the Pricebook2 Id 
    
    Pricebook2 prBook1= [select id, Name from Pricebook2 where Name =: priceBookName];
    System.debug('=== pricebook is: '+ prbook1);
    List<Opportunity> OpptUp = [select Id from Opportunity where id IN:existingOppId ];
   
    for ( Temp_Assets__c TA : currentAsset1)
    {        
        
         // If New Opportunity is Created  
         if ( TA.Existing_Opportunity__c == NULL && TA.New_Opportunity__c != NULL )    
          {
             // Insert Opportunity with all mandatory fields
            Opportunity Opp = new Opportunity(); 
             Opp.Name      = TA.New_Opportunity__c;             
             Opp.Type      = 'Existing Customer';
             Opp.AccountId = TA.AccountId__c;
             //Opp.CloseDate = TA.Expiry_Date__c; // default Sysdate + 30
             opp.closeDate = TA.Opp_close_Date__c;
             opp.Support_Expiry_Date__c = TA.Expiry_Date__c; //new addition
             Opp.Government_Contract__c = 'None';
             Opp.Renewal_Opportunity__c = 'Yes';
             Opp.StageName = 'Renewal';
             //Opp.Lost_Reason__c = 'Other'; // not required 
             Opp.Primary_Competitor__c = 'No Competitor';
             Opp.ForecastCategoryName = 'Pipeline';
             Opp.LeadSource = 'Renewal';
             Opp.Primary_Reseller__c    = TA.Reseller__c;
             Opp.Primary_Distributor__c = TA.Distributor__c;
             Opp.Renewal_Incumbant_Reseller__c = TA.Incumbent_Reseller__c;
             Opp.Renewal_K_12__c   =  TA.Education__c; 
             Opp.Opportunity_Driver__c ='Renewals';
             //Assigning the new Opportunity to the Renewal Record Type
             opp.recordtypeId = renewal_RT.id;
             opport.add(opp);
           }
           else if ( TA.Existing_Opportunity__c != NULL && TA.New_Opportunity__c == NULL )    
           {
               // List<Opportunity> OpptUp = [select Id from Opportunity where id =  :TA.Existing_Opportunity__c ];
                
                for ( Opportunity OppUpd : OpptUp ) {
                    OppUpd.Primary_Reseller__c    = TA.Reseller__c;
                    OppUpd.Primary_Distributor__c =  TA.Distributor__c;
                    OppUpd.Renewal_Incumbant_Reseller__c =  TA.Incumbent_Reseller__c;
                    OppUpd.Renewal_K_12__c   =  TA.Education__c;
                    OppUpd.Support_Expiry_Date__c = TA.Expiry_Date__c;  //new addition
                    //change the RecordType of this existing Opportunity to Renewal Opportunity Record Type
                    OppUpd.recordtypeId = renewal_RT.id; 
                    OppUpd.Opportunity_Driver__c ='Renewals';
                    Opport.add(OppUpd);
                }
            }
    }  
    
    if (Opport.size() > 0) {
        upsert Opport; 
    }
    
   // for (Opportunity Opport1: Opport) {
    for ( Temp_Assets__c TA : CurrentAsset )
    {
        for (Opportunity Opport1: Opport) {
            //Grab the Service End Date Value of this Asset
            Date currentServiceDate = TA.Service_End_Date__c;
            
            /************New condition added below*********************************************/
            //if Monthly Quote is not selected by the user then it will calculate all the SKU's
           // if (TA.Monthly_Quote__c == false) {             
                //Check if the Renewals need 5 years renewals
                 if (TA.X5_year_SKU__c > 0 && (TA.Support_Only_5_Year_SKU__c!=null || TA.X5_Year_SKU_Code__c!=null)) {
       
                    //Insert into Opportunity Lines    
                    OpportunityLineItem OppL_5yr = new OpportunityLineItem();
                        OppL_5yr.OpportunityId = Opport1.Id;
                        //check if the Renew is for Bundle Support or Support only
                        if (TA.Bundle_Support__c == true && TA.X5_Year_SKU_Code__c!= null) {
                            System.debug('#### Checkpoint #1');
                            //Retrieve the priceBookEntryId for Bundle support 5 years Renewals SKU Code
                            OppL_5yr.PricebookEntryId = currentPriceBook(TA.X5_Year_SKU_Code__c );
                            System.debug('#### Checkpoint #2');
                            //OppL_5yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.X5_Year_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                        }
                        else if (TA.Bundle_Support__c != true && TA.Support_Only_5_Year_SKU__c!= null) {  
                            //Retrieve the priceBookEntryId for CO or SO support 5 years Renewals SKU Code
                            System.debug('#### Checkpoint #1.1');
                            OppL_5yr.PricebookEntryId = currentPriceBook(TA.Support_Only_5_Year_SKU__c);
                            //OppL_5yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_5_Year_SKU__c AND priceBook2Id=:prBook.id].Id;
                            System.debug('#### Checkpoint #2.2');
                        }                   
                        //OppL_5yr.PricebookEntryId = prBookEntry.Id;
                        OppL_5yr.Quantity = TA.X5_year_SKU__c;    
                        OppL_5yr.Start_Date__c= currentServiceDate.addDays(1);
                        OppL_5yr.End_Date__c = currentServiceDate.addYears(Integer.valueOf(5* TA.X5_year_SKU__c));
                        OppL_5yr.Asset__c = TA.Asset_Id__c;
                        
                        currentServiceDate = currentServiceDate.addYears(Integer.valueOf(5* TA.X5_year_SKU__c));
                      
                    //Adding to the list
                    OppLineItems.add(OppL_5yr);
                     
                     //Insert OppL_5yr;   
                  }       
                if (TA.X3_year_SKU__c > 0 && (TA.Support_Only_3_Year_SKU__c!=null || TA.X3_Year_SKU_Code__c!=null)) {
                    
                    //Insert into Opportunity Lines 
                    OpportunityLineItem OppL_3yr = new OpportunityLineItem();
                    OppL_3yr.OpportunityId = Opport1.Id;
                    //check if the Renew is for Bundle Support or Support only
                    if (TA.Bundle_Support__c == true && TA.X3_Year_SKU_Code__c!= null) {
                        //Retrieve the priceBookEntryId for Bundle support 3 years Renewals SKU Code
                        OppL_3yr.PricebookEntryId = currentPriceBook(TA.X3_Year_SKU_Code__c );
                        //OppL_3yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.X3_Year_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                    }
                    else if (TA.Bundle_Support__c != true && TA.Support_Only_3_Year_SKU__c!= null) {  
                        //Retrieve the priceBookEntryId for CO or SO support 3 years Renewals SKU Code
                        OppL_3yr.PricebookEntryId = currentPriceBook(TA.Support_Only_3_Year_SKU__c );
                        //OppL_3yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_3_Year_SKU__c AND priceBook2Id=:prBook.id].Id;
                    }  
                    //OppL_3yr.PricebookEntryId = prBookEntry.Id;
                    OppL_3yr.Quantity=TA.X3_year_SKU__c;
                    OppL_3yr.Start_Date__c= currentServiceDate.addDays(1);
                    OppL_3yr.End_Date__c = currentServiceDate.addYears(Integer.valueOf(3* TA.X3_year_SKU__c));
                    OppL_3yr.Asset__c = TA.Asset_Id__c;
                    
                    currentServiceDate = currentServiceDate.addYears(Integer.valueOf(3* TA.X3_year_SKU__c));       
                      
                    OppLineItems.add(OppL_3yr);
                    //Insert OppL_3yr;   
                }
                if (TA.Monthly_Quote__c == false) { 
                if (TA.X1_year_SKU__c > 0 && (TA.Support_Only_1_Year_SKU__c!=null || TA.X1_Year_SKU_Code__c!=null)) {
    
                    //Insert into Opportunity Lines 
                    OpportunityLineItem OppL_1yr = new OpportunityLineItem();
                    OppL_1yr.OpportunityId = Opport1.Id;
                    //check if the Renew is for Bundle Support or Support only
                    if (TA.Bundle_Support__c == true && TA.X1_Year_SKU_Code__c!= null) {
                        //Retrieve the priceBookEntryId for Bundle support 1 year Renewals SKU Code
                        OppL_1yr.PricebookEntryId = currentPriceBook(TA.X1_Year_SKU_Code__c );
                        //OppL_1yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.X1_Year_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                    }
                    else if (TA.Bundle_Support__c != true && TA.Support_Only_1_Year_SKU__c!= null) {  
                        //Retrieve the priceBookEntryId for CO or SO support 1 years Renewals SKU Code                   
                        OppL_1yr.PricebookEntryId = currentPriceBook(TA.Support_Only_1_Year_SKU__c );
                        //OppL_1yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_1_Year_SKU__c AND priceBook2Id=:prBook.id].Id;
                    } 
                    //OppL_1yr.PricebookEntryId = prBookEntry.Id;
                    OppL_1yr.Quantity=TA.X1_year_SKU__c;
                    OppL_1yr.Start_Date__c= currentServiceDate.addDays(1);
                    OppL_1yr.End_Date__c = currentServiceDate.addYears(Integer.valueOf(1* TA.X1_year_SKU__c));
                    OppL_1yr.Asset__c = TA.Asset_Id__c;
                   
                    currentServiceDate = currentServiceDate.addYears(Integer.valueOf(1* TA.X1_year_SKU__c));  
        
                    OppLineItems.add(OppL_1yr);
                    //Insert OppL_1yr;   
                }  
                if (TA.Total_in_Months__c > 0 && (TA.Support_Only_Monthly_SKU__c!=null || TA.Monthly_SKU_Code__c!=null)) {
    
                    //Insert into Opportunity Lines 
                    OpportunityLineItem OppL_Months = new OpportunityLineItem();
                    OppL_Months.OpportunityId = Opport1.Id;
                    //check if the Renew is for Bundle Support or Support only
                    if (TA.Bundle_Support__c == true && TA.Monthly_SKU_Code__c!= null) {
                        //Retrieve the priceBookEntryId for Bundle support Monthly Renewals SKU Code
                        OppL_Months.PricebookEntryId = currentPriceBook(TA.Monthly_SKU_Code__c );
                        //OppL_Months.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Monthly_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                    }
                    else if (TA.Bundle_Support__c != true && TA.Support_Only_Monthly_SKU__c!= null) {  
                        //Retrieve the priceBookEntryId for CO or SO support Monthly Renewals SKU Code
                        OppL_Months.PricebookEntryId = currentPriceBook(TA.Support_Only_Monthly_SKU__c);
                        //OppL_Months.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_Monthly_SKU__c AND priceBook2Id=:prBook.id].Id;
                    }
                    //OppL_Months.PricebookEntryId = prBookEntry.Id;
                    OppL_Months.Quantity=TA.Total_in_Months__c;          
                    OppL_Months.Start_Date__c= currentServiceDate.addDays(1);
                    OppL_Months.End_Date__c = currentServiceDate.addDays(Integer.valueOf(TA.DaysRemaining_Months__c));
                    OppL_Months.Asset__c = TA.Asset_Id__c;
                    
                    //currentServiceDate = currentServiceDate.addMonths(Integer.valueOf(1* TA.Total_in_Months__c));  
                    
                    OppLineItems.add(OppL_Months);
                    //Insert OppL_Months;   
                }   
            } //end of this new condition for Monthly Quote
            
            //If Monthly Quote is true then only monthly SKU should be created
            else if ((TA.Monthly_Quote__c == true && TA.Total_Monthly_Quote_term__c > 0)){
                if (TA.Total_Monthly_Quote_term__c > 0 && (TA.Support_Only_Monthly_SKU__c!=null || TA.Monthly_SKU_Code__c!=null)) {

                //Insert into Opportunity Lines 
                OpportunityLineItem OppL_Months = new OpportunityLineItem();
                OppL_Months.OpportunityId = Opport1.Id;
                //check if the Renew is for Bundle Support or Support only
                if (TA.Bundle_Support__c == true && TA.Monthly_SKU_Code__c!= null) {
                    //Retrieve the priceBookEntryId for Bundle support Monthly Renewals SKU Code
                    OppL_Months.PricebookEntryId = currentPriceBook(TA.Monthly_SKU_Code__c );
                    //OppL_Months.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Monthly_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                }
                else if (TA.Bundle_Support__c != true && TA.Support_Only_Monthly_SKU__c!= null) {  
                    //Retrieve the priceBookEntryId for CO or SO support Monthly Renewals SKU Code
                    OppL_Months.PricebookEntryId = currentPriceBook(TA.Support_Only_Monthly_SKU__c);
                    //OppL_Months.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_Monthly_SKU__c AND priceBook2Id=:prBook.id].Id;
                }
                //OppL_Months.PricebookEntryId = prBookEntry.Id;
                OppL_Months.Quantity=TA.Total_Monthly_Quote_term__c ;          
                OppL_Months.Start_Date__c= currentServiceDate.addDays(1);
                //OppL_Months.End_Date__c = currentServiceDate.addDays(Integer.valueOf(TA.DaysRemaining_Months__c));
                OppL_Months.End_Date__c = TA.Expiry_Date__c;
                OppL_Months.Asset__c = TA.Asset_Id__c;
                
                //currentServiceDate = currentServiceDate.addMonths(Integer.valueOf(1* TA.Total_in_Months__c));  
                
                OppLineItems.add(OppL_Months);
                //Insert OppL_Months;   
                }   
            }              
    }   
  //end of new for loop
  }
  public String currentPriceBook(String SKU_Code) {
      List<product2> prId = [Select id from Product2 where Name =:SKU_Code];
      System.debug('=== product id is : '+ prId[0].id);
      for (Product2 pr: prId) {
          ProductNameToId.put(pr.id, SKU_Code);
      }
      System.debug('#### map results in: ' + productNameToId);
      System.debug('#### map Keyset results in: ' + productNameToId.keyset());
      //String prBookEntry= [Select id from PriceBookEntry where product2.Name =:SKU_Code AND priceBook2Id=:prBook1.id].Id;
      String prBookEntry = [Select id from PricebookEntry where Product2Id IN:prId AND product2.id =: ProductNameToId.keyset() AND priceBook2Id =: prBook1.id].Id;
      
      System.debug('#### PricebookEntry is: ' + prBookEntry);
      return prBookEntry;         
  }
    
  System.debug('== Opp Line Items in the list are: ' + oppLineItems);
  if (OppLineItems.size()>0) {
      insert OppLineItems;
  }
  
 List<Temp_Assets__c> TempAsset = [SELECT Id From Temp_Assets__c Where CreatedById = :userinfo.getUserId()];
  delete TempAsset ;
  
}
@isTest(SeeAllData = true)
private class   Test_Temp_Asset2_Opp {

    public static testmethod void testopp()
    {     
        Account acc = new Account (Name = 'Test Acc',RecordTypeId ='0123000000090Hd',Phone = '1234567809', website = 'test@merunetworks.com'/*type = 'Reseller',Program_Level__c = 'Authorized',Status__c = 'Approved',Preferred_Distributor__c = 'Catalyst'*/);
        insert acc;
        
        Account accDisti = new Account (Name = 'Test Disti',RecordTypeId ='0123000000090Hi',Phone = '1234567809',type = 'Distributor',Program_Level__c = 'Authorized',Status__c = 'Approved');
        insert accDisti;
        
        Account accRes = new Account (Name = 'Test Reseller',RecordTypeId ='0123000000090Hi',Phone = '1234567809',type = 'Reseller',Program_Level__c = 'Authorized',Status__c = 'Approved');
        insert accRes;
        
        Opportunity opp = new Opportunity (Name='Test Opp', closeDate=system.today(),recordtypeId = '0123000000094yH',
                                    accountId = acc.id,ForecastCategoryName = 'Pipeline',Government_Contract__c = 'None',
                                    StageName ='Renewal', Primary_Competitor__c = 'No Competitor', LeadSource='Renewal' );
        insert opp;
        
        Contract c = new Contract(Name='Test Contract', AccountId=acc.id, status= 'Draft', Contract_Number__c='MERU-1234');
        insert c;
        
        Pricebook2 standardPb= [select id, name, isActive from Pricebook2 where Name= 'NAM Price Book' limit 1];
        
        Product2 prd = [Select id, name, isActive, cost_price__c, productCode from Product2 where isActive = true Limit 1];
        System.assert (prd != null);
        //Product2 prd = [Select id, name from Product2 where isActive = true and ]);
        //Product2 prd = new Product2(Name='test Product', isActive = true, cost_Price__c =0.00, productCode='E1-MC1550-VE');
       //insert prd;
        
        PricebookEntry pbe = [select id from PricebookEntry where product2Id =: prd.id AND pricebook2id =: standardPb.id];
        //PricebookEntry pbe = new PricebookEntry (Product2ID=prd.id,Pricebook2ID=standardPb.id,UnitPrice=50, isActive=true,UseStandardPrice=false);
       // insert pbe; 
        
        Asset ast = new Asset(Name='Test Asset', AccountId= acc.id, Last_Contract_Id__c= c.id, serialNumber='1234567890', 
                        product2Id= prd.id, Serial_Number_ID__c = '000011412MC152033', Service_End_Date_Max__c = Date.valueOf('2014-05-25'));
        insert ast;
        
        test.startTest();
        
        Temp_Assets__c tast = new Temp_Assets__c(
                                            Name    = 'Test Temp object',
                                            AccountId__c    = acc.Id,
                                            Bundle_Support__c   = FALSE,        
                                            Distributor__c  = accDisti.id,
                                            Monthly_Quote__c  =  FALSE,
                                            Existing_Opportunity__c = null,
                                            Expiry_Date__c  = Date.valueOf('2023-12-15'),
                                            Opp_Close_Date__c =  Date.today(),
                                            Install_Date__c =  Date.valueOf('2013-12-15'), 
                                            Last_Contract_Number__c = c.contract_Number__c,    
                                            New_Opportunity__c  = 'Test Opp',
                                            Product__c  = prd.id,
                                            Product_lookup__c  = prd.id,
                                            Reseller__c = accRes.Id,
                                            Serial_Number__c = ast.serial_Number_ID__c,
                                            Service_End_Date__c = ast.Service_End_Date_Max__c,
                                            Service_Start_Date__c  =  Date.today(),                                         
                                            Incumbent_Reseller__c    = 'Yes',
                                            Education__c    = 'K-12',
                                            //PriceBook_Name__c ='NAM Price Book',
                                            PriceBook_Name__c =standardPb.name,
                                            Asset_Id__c = ast.id);
        
        insert tast; //Sudhir commented
        //System.debug('==> ' + tast.X1_Year_SKU_Code__c);
        
        //System.AssertEquals(tast.Monthly_Quote__c,false);
        test.stopTest();
    
    }    
    
   
        }
    }
Run Failures:
  Test_Temp_Asset2_Opp.testopp System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Temp_Asset2_Opp: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The changes you have made required the Discount Schedule to be recalculated. SFDC is unable to locate a Discount Schedule. Please contact your System Administrator.: []

Trigger.Temp_Asset2_Opp: line 277, column 1: []
  Test_Temp_Asset2_Opp.testopp2 System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Temp_Asset2_Opp: execution of AfterInsert



Please suggest me how to migrate this to production

Thanks

Sudhir

 

Hi 

 I wrote a trigger on appointment object which will update lead status in lead which is working fine. I wrote a test class for trigger as mentioned below it is still showing me same 0% please suggest me how to fix

Trigger
======
trigger Update_Lead_Status on Appointment_Detail__c (After Insert, After Update) 
{
 set<id> ADId = new set<id>();
 
 for(Appointment_Detail__c AD : trigger.new) 
 {
     ADId.add(AD.ID);
     Appointment_Detail__c ApptDt = [ SELECT  Completed__c,Lead_Id__c  FROM Appointment_Detail__c where id in :ADId ]; 
     
    If ( ApptDt.Lead_Id__c <> null && ApptDt.Completed__c == 'Yes' ) 
    {
      Lead ld = [select staTus from Lead where id = :ApptDt.Lead_Id__c]; 
        ld.status = 'SQL';
        update ld;      
          }         
      }
}

Test Class
==========

@isTest(SeeAllData = true) 
private class test_appointment_leadstatus
{
  public static testmethod void testlead()
    {   
    test.startTest();

    Appointment_Detail__c ApptDt = [ SELECT  Completed__c,Lead_Id__c  FROM Appointment_Detail__c where id = 'a1gm000000001GJ'];   
    
  If ( ApptDt.Lead_Id__c <> null && ApptDt.Completed__c == 'Yes' ) 
    {
      Lead ld = [select status from Lead where id = :ApptDt.Lead_Id__c]; 
        ld.status = 'SQL';
        update ld;  
    } 
   
    test.stopTest();
   
   }  
           

}


Thanks

Sudhir

Hi, 

 I need a suggestion on changing lead status on click of a button. 

 I need to add a button on lead page when user click on button lead status must be updated to "Completed" Please suggest me how to implement this feature.

Thanks

Sudhir

Hi, 

  I wrote below trigger to update lead status. when appoinment is created. But I am getting below error 

  trigger Update_Appointment_SQL on Lead (After Insert, After Update) 
{
set<id> leadId=new set<id>();
for(Lead ts : trigger.new)
{
leadId.add(ts.id);
Lead ld=[Select status,Appointment_Created_Date__c from Lead where id in :leadId];
if( ld.Appointment_Created_Date__c <> null)
{
ld.Status='SQL';
update ld;
}
}
}
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Update_Appointment_SQL caused an unexpected exception, contact your administrator: Update_Appointment_SQL: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00Q6000000myNGaEAM; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Update_Appointment_SQL: maximum trigger depth exceeded Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa] Lead trigger event AfterUpdate for [00Q6000000myNGa]: []: Trigger.Update_Appointment_SQL: line 11, column 1
 Please suggest me 


Thanks
Sudhir

Hi ,

  I am adding a workflow rule on Lead. When Appoinment_Created_date is not null then update Lead Status to SQL.

  Updating am doing through field update. But below forumla is not working Please suggest me how to fix.

 NOT(ISBLANK(Appointment_Created_Date__c)) 

  I even tried NOT(ISNULL(Appointment_Created_Date__c))


Thanks

Sudhir

Hi,

   There are two visualforce pages CS_Home and CS_Product.  I want to set a hyper link from CS_Home to CS_Product Page. 

   Please suggest me how to set hyper link between visualforce page.


Thanks

Sudhir

Hi,

 Please suggest me am find challenge in improving performance in code coverage. Please advice me if this code is correct or not how to modify to get more code coverage. 

 Below code is working perfect only issue is with code coverage. 
 
trigger NewDiscountProgramUpdate on Opportunity (Before Update) 
{
// ******** Trigger Created By Sudhir ************  
// Loop through the incoming records

  list<opportunity> opp = new list<opportunity>();


for (Opportunity o : Trigger.new) {       
    
        
   // Check for Deal Reg Not Null
 if ( o.FORCE_NSP__c == NULL && o.discount_program__c <> 'NSP' && o.Deal_Registration__c <> NULL ) 
   {
     if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'No' && o.K_12__c == 'No'  ) 
      {
        o.discount_program__c = 'DEALREG/PI';
        o.Abbv_Discount_Program__c = 'DR/PI';        
      }
     else if ( o.Partner_Driven__c == 'No'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No'  ) 
     {
        o.discount_program__c = 'DEALREG/PL';
        o.Abbv_Discount_Program__c = 'DR/PL';    
     }
     else if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No'  ) 
     {
       o.discount_program__c = 'DEALREG/PI/PL';
       o.Abbv_Discount_Program__c = 'DR/PI/PL';  
     }
     else if ( o.Partner_Driven__c == 'No'  && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' ) 
     {
       o.discount_program__c = 'DEALREG/K-12';
       o.Abbv_Discount_Program__c = 'DR/K12';    
     }
     else if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' )
     {
       o.discount_program__c = 'DEALREG/PI/K-12';
       o.Abbv_Discount_Program__c = 'DR/PI/K12';    
     }
     else if (   o.Partner_Driven__c == 'No'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes'  )
     {
       o.discount_program__c = 'DEALREG/PL/K-12';
       o.Abbv_Discount_Program__c = 'DR/PL/K12';   
     }
     else if ( o.Partner_Driven__c == 'Yes'  && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes' )
     {
       o.discount_program__c = 'DEALREG/PI/PL/K-12';
       o.Abbv_Discount_Program__c = 'DR/PI/PL/K12';   
     }
    else  
     {
     o.discount_program__c = 'DEALREG';
     o.Abbv_Discount_Program__c = 'DR';     
     } 
    }
     opp.add(o);
 }   
     
 
}


Please advice me also how to write test class for above trigger I wrote a test class which is giving only 14% code coverage. 

Thanks

Sudhir

Hi, 

 I want to save only 80 character in a text field if user enters more than 80 i want to cut remaining and add only 80 characters please suggest me how to do this 

Thanks
Sudhir
Hi, 

  I am getting error while update values in opportunity I am trying to update I get below error

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Public_Opportunity_View_trg caused an unexpected exception, contact your administrator: Public_Opportunity_View_trg: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.Public_Opportunity_View_trg: line 48, column 1

trigger Public_Opportunity_View_trg on Opportunity (After Insert, After Update,After Delete) {

/* Fires during INSERT */
if(trigger.isInsert)
{
   List<Public_Opportunity_View__c> POVi = new list<Public_Opportunity_View__c>();
  
for(Opportunity opp :trigger.new)
  {
   Public_Opportunity_View__c POV = new Public_Opportunity_View__c();
      POV.Account_ID__c = opp.accountid;
      POV.Opportunity_ID__c    =  opp.ID;
      POV.Close_Date__c        =  opp.CloseDate;
      POV.Opportunity_Name__c  =  opp.Name;
      POV.Stage__c             =  opp.StageName;
      POVi.add(POV);
  
    }
    
     Insert POVi;
  
   }

/* Fires during UPDATE */
if(trigger.isUpdate)
   {
   Set<ID> Oppid = Trigger.newMap.keySet();
     
   List<Opportunity> OppUp = new List<Opportunity >();  
     
   OppUp = [SELECT  Id,accountid, CloseDate, Name, StageName FROM Opportunity WHERE id in :Oppid];
  
    List<Public_Opportunity_View__c> POVu = new list<Public_Opportunity_View__c>();
   
     for(Opportunity oppu :OppUp)
      {
       Public_Opportunity_View__c POVV = new Public_Opportunity_View__c();
        POVV.Account_ID__c        =  oppu.accountid;
        POVV.Opportunity_ID__c    =  oppu.ID;
        POVV.Close_Date__c        =  oppu.CloseDate;
        POVV.Opportunity_Name__c  =  oppu.Name;
        POVV.Stage__c             =  oppu.StageName;
        POVu.add(POVV);
       }
      
       if(POVu.size()>0)
       {
       Update POVu;
        }
    } 
 
/* Fires during DELETE*/
if(Trigger.isDelete)
{
   List<Id> DoppId = new List<Id>();
   for(Opportunity opp: Trigger.old) { 
      DoppId.add(opp.id);
   }
  
     List<Public_Opportunity_View__c> existopp = [Select Id from Public_Opportunity_View__c where Opportunity_ID__c in :DoppId];
    
     Delete  existopp;
  
  

  }


       
       
    }

Please suggest me how to fix this issue. 

Thanks
Sudhir
Hi,

 There is a request from user he s asking question as below is this possible to give access please let me know

Please allow Henry access to my SFDC profile howellasd@zest.com so he can view the team forecast while I am on holiday
Im happy for this to be a permanent change in his profile



Thanks
Sudhir
Hi, 

 Created a custom object in fullcopy with name Temp_Assets__c have created few formula fields on this object  created a trigger on this object to insert data into this object also wrote a test class on this trigger which is 100% code coverage

 Problem am facing is am not able to deploy this to production i get error 
trigger Temp_Asset2_Opp on Temp_Assets__c (after insert )
{
    List<OpportunityLineItem> OppLineItems = new List<OpportunityLineItem>();
    
    List<Temp_Assets__c> CurrentAsset = [Select Id, Name, PriceBook_Name__c, Asset_Id__c, Serial_Number__c, AccountId__c, Product__c, Service_Start_Date__c,
                                              Service_End_Date__c ,Install_Date__c ,Reseller__c,Distributor__c,
                                              Incumbent_Reseller__c,Education__c,Expiry_Date__c,Existing_Opportunity__c,
                                              New_Opportunity__c,Expiry_Term__c,Bundle_Support__c, X5_Year_SKU_Code__c, X3_Year_SKU_Code__c,
                                              X1_Year_SKU_Code__c, Monthly_SKU_Code__c, X5_year_SKU__c ,X3_year_SKU__c, X1_year_SKU__c,
                                              Total_in_Months__c, Support_Only_5_Year_SKU__c, Support_Only_3_Year_SKU__c, Support_Only_1_Year_SKU__c,
                                              Support_Only_Monthly_SKU__c, DaysRemaining_Months__c, Monthly_Quote__c, Total_Monthly_Quote_term__c
                                         From Temp_Assets__c 
                                         Where CreatedById = :userinfo.getUserId()];
                                         
    List<Temp_Assets__c> CurrentAsset1 = [Select Id, Name, PriceBook_Name__c, Opp_Close_Date__c, Asset_Id__c, Serial_Number__c, AccountId__c, Product__c, Service_Start_Date__c,
                                              Service_End_Date__c ,Install_Date__c ,Reseller__c,Distributor__c ,
                                              Incumbent_Reseller__c,Education__c,Expiry_Date__c,Existing_Opportunity__c,
                                              New_Opportunity__c,Expiry_Term__c,Bundle_Support__c, X5_Year_SKU_Code__c, X3_Year_SKU_Code__c,
                                              X1_Year_SKU_Code__c, Monthly_SKU_Code__c, X5_year_SKU__c ,X3_year_SKU__c, X1_year_SKU__c,
                                              Total_in_Months__c, Support_Only_5_Year_SKU__c, Support_Only_3_Year_SKU__c, Support_Only_1_Year_SKU__c,
                                              Support_Only_Monthly_SKU__c, DaysRemaining_Months__c
                                         From Temp_Assets__c 
                                         Where CreatedById = :userinfo.getUserId() Limit 1];
    
    //Pricebook2 prBook1= [select id from Pricebook2 where Name=: 'NAM Price Book'];
   
    RecordType renewal_RT = [Select id, Name, sObjectType from RecordType where sObjectType= 'Opportunity' and Name = 'Renewal Opportunity' ];
    set<id> existingOppId= new Set<id>();
    List<Opportunity> opport = new List<Opportunity>();
    set<id> newOppId = new set<id>();
    //String variable to store the name of the pricebook for this Opportunity
    String priceBookName;
    
    for (Temp_Assets__c temp: currentAsset1) {
        existingOppId.add(temp.Existing_Opportunity__c);
        priceBookName = temp.priceBook_Name__c;
    }
    
    Map<Id, String> productNameToId = new Map<Id, String>();
    //Get the Pricebook2 Id 
    
    Pricebook2 prBook1= [select id, Name from Pricebook2 where Name =: priceBookName];
    System.debug('=== pricebook is: '+ prbook1);
    List<Opportunity> OpptUp = [select Id from Opportunity where id IN:existingOppId ];
   
    for ( Temp_Assets__c TA : currentAsset1)
    {        
        
         // If New Opportunity is Created  
         if ( TA.Existing_Opportunity__c == NULL && TA.New_Opportunity__c != NULL )    
          {
             // Insert Opportunity with all mandatory fields
            Opportunity Opp = new Opportunity(); 
             Opp.Name      = TA.New_Opportunity__c;             
             Opp.Type      = 'Existing Customer';
             Opp.AccountId = TA.AccountId__c;
             //Opp.CloseDate = TA.Expiry_Date__c; // default Sysdate + 30
             opp.closeDate = TA.Opp_close_Date__c;
             opp.Support_Expiry_Date__c = TA.Expiry_Date__c; //new addition
             Opp.Government_Contract__c = 'None';
             Opp.Renewal_Opportunity__c = 'Yes';
             Opp.StageName = 'Renewal';
             //Opp.Lost_Reason__c = 'Other'; // not required 
             Opp.Primary_Competitor__c = 'No Competitor';
             Opp.ForecastCategoryName = 'Pipeline';
             Opp.LeadSource = 'Renewal';
             Opp.Primary_Reseller__c    = TA.Reseller__c;
             Opp.Primary_Distributor__c = TA.Distributor__c;
             Opp.Renewal_Incumbant_Reseller__c = TA.Incumbent_Reseller__c;
             Opp.Renewal_K_12__c   =  TA.Education__c; 
             Opp.Opportunity_Driver__c ='Renewals';
             //Assigning the new Opportunity to the Renewal Record Type
             opp.recordtypeId = renewal_RT.id;
             opport.add(opp);
           }
           else if ( TA.Existing_Opportunity__c != NULL && TA.New_Opportunity__c == NULL )    
           {
               // List<Opportunity> OpptUp = [select Id from Opportunity where id =  :TA.Existing_Opportunity__c ];
                
                for ( Opportunity OppUpd : OpptUp ) {
                    OppUpd.Primary_Reseller__c    = TA.Reseller__c;
                    OppUpd.Primary_Distributor__c =  TA.Distributor__c;
                    OppUpd.Renewal_Incumbant_Reseller__c =  TA.Incumbent_Reseller__c;
                    OppUpd.Renewal_K_12__c   =  TA.Education__c;
                    OppUpd.Support_Expiry_Date__c = TA.Expiry_Date__c;  //new addition
                    //change the RecordType of this existing Opportunity to Renewal Opportunity Record Type
                    OppUpd.recordtypeId = renewal_RT.id; 
                    OppUpd.Opportunity_Driver__c ='Renewals';
                    Opport.add(OppUpd);
                }
            }
    }  
    
    if (Opport.size() > 0) {
        upsert Opport; 
    }
    
   // for (Opportunity Opport1: Opport) {
    for ( Temp_Assets__c TA : CurrentAsset )
    {
        for (Opportunity Opport1: Opport) {
            //Grab the Service End Date Value of this Asset
            Date currentServiceDate = TA.Service_End_Date__c;
            
            /************New condition added below*********************************************/
            //if Monthly Quote is not selected by the user then it will calculate all the SKU's
           // if (TA.Monthly_Quote__c == false) {             
                //Check if the Renewals need 5 years renewals
                 if (TA.X5_year_SKU__c > 0 && (TA.Support_Only_5_Year_SKU__c!=null || TA.X5_Year_SKU_Code__c!=null)) {
       
                    //Insert into Opportunity Lines    
                    OpportunityLineItem OppL_5yr = new OpportunityLineItem();
                        OppL_5yr.OpportunityId = Opport1.Id;
                        //check if the Renew is for Bundle Support or Support only
                        if (TA.Bundle_Support__c == true && TA.X5_Year_SKU_Code__c!= null) {
                            System.debug('#### Checkpoint #1');
                            //Retrieve the priceBookEntryId for Bundle support 5 years Renewals SKU Code
                            OppL_5yr.PricebookEntryId = currentPriceBook(TA.X5_Year_SKU_Code__c );
                            System.debug('#### Checkpoint #2');
                            //OppL_5yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.X5_Year_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                        }
                        else if (TA.Bundle_Support__c != true && TA.Support_Only_5_Year_SKU__c!= null) {  
                            //Retrieve the priceBookEntryId for CO or SO support 5 years Renewals SKU Code
                            System.debug('#### Checkpoint #1.1');
                            OppL_5yr.PricebookEntryId = currentPriceBook(TA.Support_Only_5_Year_SKU__c);
                            //OppL_5yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_5_Year_SKU__c AND priceBook2Id=:prBook.id].Id;
                            System.debug('#### Checkpoint #2.2');
                        }                   
                        //OppL_5yr.PricebookEntryId = prBookEntry.Id;
                        OppL_5yr.Quantity = TA.X5_year_SKU__c;    
                        OppL_5yr.Start_Date__c= currentServiceDate.addDays(1);
                        OppL_5yr.End_Date__c = currentServiceDate.addYears(Integer.valueOf(5* TA.X5_year_SKU__c));
                        OppL_5yr.Asset__c = TA.Asset_Id__c;
                        
                        currentServiceDate = currentServiceDate.addYears(Integer.valueOf(5* TA.X5_year_SKU__c));
                      
                    //Adding to the list
                    OppLineItems.add(OppL_5yr);
                     
                     //Insert OppL_5yr;   
                  }       
                if (TA.X3_year_SKU__c > 0 && (TA.Support_Only_3_Year_SKU__c!=null || TA.X3_Year_SKU_Code__c!=null)) {
                    
                    //Insert into Opportunity Lines 
                    OpportunityLineItem OppL_3yr = new OpportunityLineItem();
                    OppL_3yr.OpportunityId = Opport1.Id;
                    //check if the Renew is for Bundle Support or Support only
                    if (TA.Bundle_Support__c == true && TA.X3_Year_SKU_Code__c!= null) {
                        //Retrieve the priceBookEntryId for Bundle support 3 years Renewals SKU Code
                        OppL_3yr.PricebookEntryId = currentPriceBook(TA.X3_Year_SKU_Code__c );
                        //OppL_3yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.X3_Year_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                    }
                    else if (TA.Bundle_Support__c != true && TA.Support_Only_3_Year_SKU__c!= null) {  
                        //Retrieve the priceBookEntryId for CO or SO support 3 years Renewals SKU Code
                        OppL_3yr.PricebookEntryId = currentPriceBook(TA.Support_Only_3_Year_SKU__c );
                        //OppL_3yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_3_Year_SKU__c AND priceBook2Id=:prBook.id].Id;
                    }  
                    //OppL_3yr.PricebookEntryId = prBookEntry.Id;
                    OppL_3yr.Quantity=TA.X3_year_SKU__c;
                    OppL_3yr.Start_Date__c= currentServiceDate.addDays(1);
                    OppL_3yr.End_Date__c = currentServiceDate.addYears(Integer.valueOf(3* TA.X3_year_SKU__c));
                    OppL_3yr.Asset__c = TA.Asset_Id__c;
                    
                    currentServiceDate = currentServiceDate.addYears(Integer.valueOf(3* TA.X3_year_SKU__c));       
                      
                    OppLineItems.add(OppL_3yr);
                    //Insert OppL_3yr;   
                }
                if (TA.Monthly_Quote__c == false) { 
                if (TA.X1_year_SKU__c > 0 && (TA.Support_Only_1_Year_SKU__c!=null || TA.X1_Year_SKU_Code__c!=null)) {
    
                    //Insert into Opportunity Lines 
                    OpportunityLineItem OppL_1yr = new OpportunityLineItem();
                    OppL_1yr.OpportunityId = Opport1.Id;
                    //check if the Renew is for Bundle Support or Support only
                    if (TA.Bundle_Support__c == true && TA.X1_Year_SKU_Code__c!= null) {
                        //Retrieve the priceBookEntryId for Bundle support 1 year Renewals SKU Code
                        OppL_1yr.PricebookEntryId = currentPriceBook(TA.X1_Year_SKU_Code__c );
                        //OppL_1yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.X1_Year_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                    }
                    else if (TA.Bundle_Support__c != true && TA.Support_Only_1_Year_SKU__c!= null) {  
                        //Retrieve the priceBookEntryId for CO or SO support 1 years Renewals SKU Code                   
                        OppL_1yr.PricebookEntryId = currentPriceBook(TA.Support_Only_1_Year_SKU__c );
                        //OppL_1yr.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_1_Year_SKU__c AND priceBook2Id=:prBook.id].Id;
                    } 
                    //OppL_1yr.PricebookEntryId = prBookEntry.Id;
                    OppL_1yr.Quantity=TA.X1_year_SKU__c;
                    OppL_1yr.Start_Date__c= currentServiceDate.addDays(1);
                    OppL_1yr.End_Date__c = currentServiceDate.addYears(Integer.valueOf(1* TA.X1_year_SKU__c));
                    OppL_1yr.Asset__c = TA.Asset_Id__c;
                   
                    currentServiceDate = currentServiceDate.addYears(Integer.valueOf(1* TA.X1_year_SKU__c));  
        
                    OppLineItems.add(OppL_1yr);
                    //Insert OppL_1yr;   
                }  
                if (TA.Total_in_Months__c > 0 && (TA.Support_Only_Monthly_SKU__c!=null || TA.Monthly_SKU_Code__c!=null)) {
    
                    //Insert into Opportunity Lines 
                    OpportunityLineItem OppL_Months = new OpportunityLineItem();
                    OppL_Months.OpportunityId = Opport1.Id;
                    //check if the Renew is for Bundle Support or Support only
                    if (TA.Bundle_Support__c == true && TA.Monthly_SKU_Code__c!= null) {
                        //Retrieve the priceBookEntryId for Bundle support Monthly Renewals SKU Code
                        OppL_Months.PricebookEntryId = currentPriceBook(TA.Monthly_SKU_Code__c );
                        //OppL_Months.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Monthly_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                    }
                    else if (TA.Bundle_Support__c != true && TA.Support_Only_Monthly_SKU__c!= null) {  
                        //Retrieve the priceBookEntryId for CO or SO support Monthly Renewals SKU Code
                        OppL_Months.PricebookEntryId = currentPriceBook(TA.Support_Only_Monthly_SKU__c);
                        //OppL_Months.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_Monthly_SKU__c AND priceBook2Id=:prBook.id].Id;
                    }
                    //OppL_Months.PricebookEntryId = prBookEntry.Id;
                    OppL_Months.Quantity=TA.Total_in_Months__c;          
                    OppL_Months.Start_Date__c= currentServiceDate.addDays(1);
                    OppL_Months.End_Date__c = currentServiceDate.addDays(Integer.valueOf(TA.DaysRemaining_Months__c));
                    OppL_Months.Asset__c = TA.Asset_Id__c;
                    
                    //currentServiceDate = currentServiceDate.addMonths(Integer.valueOf(1* TA.Total_in_Months__c));  
                    
                    OppLineItems.add(OppL_Months);
                    //Insert OppL_Months;   
                }   
            } //end of this new condition for Monthly Quote
            
            //If Monthly Quote is true then only monthly SKU should be created
            else if ((TA.Monthly_Quote__c == true && TA.Total_Monthly_Quote_term__c > 0)){
                if (TA.Total_Monthly_Quote_term__c > 0 && (TA.Support_Only_Monthly_SKU__c!=null || TA.Monthly_SKU_Code__c!=null)) {

                //Insert into Opportunity Lines 
                OpportunityLineItem OppL_Months = new OpportunityLineItem();
                OppL_Months.OpportunityId = Opport1.Id;
                //check if the Renew is for Bundle Support or Support only
                if (TA.Bundle_Support__c == true && TA.Monthly_SKU_Code__c!= null) {
                    //Retrieve the priceBookEntryId for Bundle support Monthly Renewals SKU Code
                    OppL_Months.PricebookEntryId = currentPriceBook(TA.Monthly_SKU_Code__c );
                    //OppL_Months.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Monthly_SKU_Code__c AND priceBook2Id=:prBook.id].Id;
                }
                else if (TA.Bundle_Support__c != true && TA.Support_Only_Monthly_SKU__c!= null) {  
                    //Retrieve the priceBookEntryId for CO or SO support Monthly Renewals SKU Code
                    OppL_Months.PricebookEntryId = currentPriceBook(TA.Support_Only_Monthly_SKU__c);
                    //OppL_Months.PricebookEntryId = [Select id from PriceBookEntry where product2.Name =:TA.Support_Only_Monthly_SKU__c AND priceBook2Id=:prBook.id].Id;
                }
                //OppL_Months.PricebookEntryId = prBookEntry.Id;
                OppL_Months.Quantity=TA.Total_Monthly_Quote_term__c ;          
                OppL_Months.Start_Date__c= currentServiceDate.addDays(1);
                //OppL_Months.End_Date__c = currentServiceDate.addDays(Integer.valueOf(TA.DaysRemaining_Months__c));
                OppL_Months.End_Date__c = TA.Expiry_Date__c;
                OppL_Months.Asset__c = TA.Asset_Id__c;
                
                //currentServiceDate = currentServiceDate.addMonths(Integer.valueOf(1* TA.Total_in_Months__c));  
                
                OppLineItems.add(OppL_Months);
                //Insert OppL_Months;   
                }   
            }              
    }   
  //end of new for loop
  }
  public String currentPriceBook(String SKU_Code) {
      List<product2> prId = [Select id from Product2 where Name =:SKU_Code];
      System.debug('=== product id is : '+ prId[0].id);
      for (Product2 pr: prId) {
          ProductNameToId.put(pr.id, SKU_Code);
      }
      System.debug('#### map results in: ' + productNameToId);
      System.debug('#### map Keyset results in: ' + productNameToId.keyset());
      //String prBookEntry= [Select id from PriceBookEntry where product2.Name =:SKU_Code AND priceBook2Id=:prBook1.id].Id;
      String prBookEntry = [Select id from PricebookEntry where Product2Id IN:prId AND product2.id =: ProductNameToId.keyset() AND priceBook2Id =: prBook1.id].Id;
      
      System.debug('#### PricebookEntry is: ' + prBookEntry);
      return prBookEntry;         
  }
    
  System.debug('== Opp Line Items in the list are: ' + oppLineItems);
  if (OppLineItems.size()>0) {
      insert OppLineItems;
  }
  
 List<Temp_Assets__c> TempAsset = [SELECT Id From Temp_Assets__c Where CreatedById = :userinfo.getUserId()];
  delete TempAsset ;
  
}
@isTest(SeeAllData = true)
private class   Test_Temp_Asset2_Opp {

    public static testmethod void testopp()
    {     
        Account acc = new Account (Name = 'Test Acc',RecordTypeId ='0123000000090Hd',Phone = '1234567809', website = 'test@merunetworks.com'/*type = 'Reseller',Program_Level__c = 'Authorized',Status__c = 'Approved',Preferred_Distributor__c = 'Catalyst'*/);
        insert acc;
        
        Account accDisti = new Account (Name = 'Test Disti',RecordTypeId ='0123000000090Hi',Phone = '1234567809',type = 'Distributor',Program_Level__c = 'Authorized',Status__c = 'Approved');
        insert accDisti;
        
        Account accRes = new Account (Name = 'Test Reseller',RecordTypeId ='0123000000090Hi',Phone = '1234567809',type = 'Reseller',Program_Level__c = 'Authorized',Status__c = 'Approved');
        insert accRes;
        
        Opportunity opp = new Opportunity (Name='Test Opp', closeDate=system.today(),recordtypeId = '0123000000094yH',
                                    accountId = acc.id,ForecastCategoryName = 'Pipeline',Government_Contract__c = 'None',
                                    StageName ='Renewal', Primary_Competitor__c = 'No Competitor', LeadSource='Renewal' );
        insert opp;
        
        Contract c = new Contract(Name='Test Contract', AccountId=acc.id, status= 'Draft', Contract_Number__c='MERU-1234');
        insert c;
        
        Pricebook2 standardPb= [select id, name, isActive from Pricebook2 where Name= 'NAM Price Book' limit 1];
        
        Product2 prd = [Select id, name, isActive, cost_price__c, productCode from Product2 where isActive = true Limit 1];
        System.assert (prd != null);
        //Product2 prd = [Select id, name from Product2 where isActive = true and ]);
        //Product2 prd = new Product2(Name='test Product', isActive = true, cost_Price__c =0.00, productCode='E1-MC1550-VE');
       //insert prd;
        
        PricebookEntry pbe = [select id from PricebookEntry where product2Id =: prd.id AND pricebook2id =: standardPb.id];
        //PricebookEntry pbe = new PricebookEntry (Product2ID=prd.id,Pricebook2ID=standardPb.id,UnitPrice=50, isActive=true,UseStandardPrice=false);
       // insert pbe; 
        
        Asset ast = new Asset(Name='Test Asset', AccountId= acc.id, Last_Contract_Id__c= c.id, serialNumber='1234567890', 
                        product2Id= prd.id, Serial_Number_ID__c = '000011412MC152033', Service_End_Date_Max__c = Date.valueOf('2014-05-25'));
        insert ast;
        
        test.startTest();
        
        Temp_Assets__c tast = new Temp_Assets__c(
                                            Name    = 'Test Temp object',
                                            AccountId__c    = acc.Id,
                                            Bundle_Support__c   = FALSE,        
                                            Distributor__c  = accDisti.id,
                                            Monthly_Quote__c  =  FALSE,
                                            Existing_Opportunity__c = null,
                                            Expiry_Date__c  = Date.valueOf('2023-12-15'),
                                            Opp_Close_Date__c =  Date.today(),
                                            Install_Date__c =  Date.valueOf('2013-12-15'), 
                                            Last_Contract_Number__c = c.contract_Number__c,    
                                            New_Opportunity__c  = 'Test Opp',
                                            Product__c  = prd.id,
                                            Product_lookup__c  = prd.id,
                                            Reseller__c = accRes.Id,
                                            Serial_Number__c = ast.serial_Number_ID__c,
                                            Service_End_Date__c = ast.Service_End_Date_Max__c,
                                            Service_Start_Date__c  =  Date.today(),                                         
                                            Incumbent_Reseller__c    = 'Yes',
                                            Education__c    = 'K-12',
                                            //PriceBook_Name__c ='NAM Price Book',
                                            PriceBook_Name__c =standardPb.name,
                                            Asset_Id__c = ast.id);
        
        insert tast; //Sudhir commented
        //System.debug('==> ' + tast.X1_Year_SKU_Code__c);
        
        //System.AssertEquals(tast.Monthly_Quote__c,false);
        test.stopTest();
    
    }    
    
   
        }
    }
Run Failures:
  Test_Temp_Asset2_Opp.testopp System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Temp_Asset2_Opp: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The changes you have made required the Discount Schedule to be recalculated. SFDC is unable to locate a Discount Schedule. Please contact your System Administrator.: []

Trigger.Temp_Asset2_Opp: line 277, column 1: []
  Test_Temp_Asset2_Opp.testopp2 System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Temp_Asset2_Opp: execution of AfterInsert



Please suggest me how to migrate this to production

Thanks

Sudhir

 

Hi ,

  I am adding a workflow rule on Lead. When Appoinment_Created_date is not null then update Lead Status to SQL.

  Updating am doing through field update. But below forumla is not working Please suggest me how to fix.

 NOT(ISBLANK(Appointment_Created_Date__c)) 

  I even tried NOT(ISNULL(Appointment_Created_Date__c))


Thanks

Sudhir

Hi,

   There are two visualforce pages CS_Home and CS_Product.  I want to set a hyper link from CS_Home to CS_Product Page. 

   Please suggest me how to set hyper link between visualforce page.


Thanks

Sudhir