• snehal waghmare 3
  • NEWBIE
  • 35 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 6
    Replies

wants to generate opportunity NO depend on firmBQ and sector picklist field Enquiry number should be auto generated and read only field.
Logic to generate Enquiry number will be as below.
Enquiry number for every sector should start with 1 for the first enquiry of every financial year.The year 2324 should come for enquiries generated from 1 April 2023 and same logic will continue for subsequent financial years 2425, 2526 and so on.
Example : GPE/D/2324/1, GPE/E/2324/1 will be the 1st enquiry number for Defence and Export sector of financial year 2223
GPE/D/2223/2 will be the 2nd enquiry generated in system for Defence sector of financial year 2223
Similarly 1st enquiry of Defence sector for BQ will be GPE/BQ/D/2223/1 for the same financial year(2223)
Here,
GPE stands for division name
D stands for sector name
2223 financial yr and needs to reset also for next financial year I have written below code its working properly but not followed by best practices i have called getautonumber method inside for loop so to avoid that how to modify code

 public void updateOpportunityNumbers(List<Opportunity> opportunities) {
    for (Opportunity opp : opportunities) {
       
        String divisionName = 'GPE';//division constant
        String firm = opp.Firm_BQ__c;
        String sectorInitial = opp.Sector__c.substring(0, 1);// To take sector initial letter
     
        // To get curent financial year
        String currentFiscalYear = [SELECT FiscalYearSettings.Name FROM Period WHERE Type = 'Year' AND StartDate <= TODAY AND EndDate >= TODAY].FiscalYearSettings.Name;
          // converting to integer
        Integer nextYear = Integer.ValueOf (currentFiscalYear )+ 1;
         // to get financial year in format 22-23
        String financialYear = currentFiscalYear.substring(2, 4) + String.valueOf(nextYear).substring(2, 4);
         // Depend on sector value need to get auto no.
        Integer autoNumber = getAutoNumberForSector(opp.Sector__c, financialYear,  sectorInitial,firm);
       
        // Depend on firm/BQ value need to change opportunity NO format
        if (opp.Firm_BQ__c == 'Firm') {
           
            opp.Opportunity_No__c = divisionName + '/' + sectorInitial + '/' + financialYear + '/' + String.valueOf(autoNumber);
            } else if (opp.Firm_BQ__c == 'BQ') {
                     
                       opp.Opportunity_No__c = divisionName + '/BQ/' + sectorInitial + '/' + financialYear + '/' + String.valueOf(autoNumber);
                       }
                       
                       }
   }
    //Added by snehal waghmare on 9th feb 2023
    //To reinitialize Opportunity No. for next financial year
    public static Integer getAutoNumberForSector(String sector,string financialYear, string sectorInitial, string firm) {
    // Query the Opportunity object to get the maximum auto number for the given sector
        List<Opportunity> oppList = New List<Opportunity>();
        If(firm == 'firm'){
            oppList = [SELECT Opportunity_No__c
                                       FROM Opportunity
                                       WHERE
                                       Opportunity_No__c LIKE :'%'+ sectorInitial + '/' + financialYear + '/%'
                                       ORDER BY CreatedDate DESC
                                       LIMIT 1];
        }
        else if(firm == 'BQ'){
              oppList = [SELECT Opportunity_No__c
                                       FROM Opportunity
                                       WHERE Opportunity_No__c LIKE :'%'+ firm + '/'+ sectorInitial + '/' + financialYear + '/%'
                                       
                                       ORDER BY CreatedDate DESC
                                       LIMIT 1];
        }
   
    // If there are no opportunities, return 1
        if (oppList.isEmpty()) {
            return 1;
        }

please give me modified code with best practices

need help to write a test class for below mwntioned controller.
public class InterioB2BQuotatationController {
   
    
    public Opportunity Opportunities {get; set;}
    public Quote Quotes {get; set;}
    public Account Accounts {get; set;}
    public Contact Contacts {get; set;}
    public List<QuotelineItem> quoteLineItems{get; set;}
 
    public Quote_Approval_History__c quoteApprovalHstry{get; set;}
    public List<Summation> lstSummations {get; set;}
   
    public InterioB2BQuotatationController(){
       
        Id QuoteId = Apexpages.currentPage().getparameters().get('Id');
        
     
       Quotes = [Select Id,Name,AccountId,OpportunityId,Approval_Submission_Date__c,CreatedById,CreatedBy.Name,ContactId,QuoteNumber,CreatedDate,Interio_Sub_Division__c,
                  Sales_Branch_Name__c,Scope_of_Architect__c,Strategy_to_Win__c,Transaction_through_WD_Dealer_Investment__c,
                  Reason_for_Discount__c,LD_Clause__c,Details_of_LD_Clause__c,Delivery_Period_in_weeks__c,Delivery_Location__c,
                  Validity_Period_Approved__c,Req_WD_Ret_Disc_Basic__c,Req_WD_Ret_Cons_Basic__c,Appr_WD_Ret_Disc_Basic__c,Appr_WD_Ret_Cons_Basic__c,Req_WD_CONT__c,
                 Req_WD_CONT_Cons_Basic__c,Appr_WD_CONT_Disc_Basic__c,Appr_WD_CONT_Cons_Basic__c,Req_Net_Rlizd_Disc_Cons_Basic__c,Appr_Net_Relzd_Bsc_Disc_On_Cons_Bsc__c
                  from Quote where Id =: QuoteId Limit 1];
       
        Accounts = [Select Is_Key_Account__c,Name from Account where Id =: Quotes.AccountId];
       Contacts =  [Select Title, Department From contact where Id =: Quotes.ContactId  Limit 1];
       
        quoteLineItems = [Select  ListPrice,Id,Product_Line_c__c,Quantity,Effective_Pricebook_Date__c,Description, Requested_Customer_Discount__c, UnitPrice,
                          Approved_Customer_Discount__c,Approved_Customer_Discounted_Basic_Price__c,Req_WD_Ret_SAC_OnReqDiscBasic__c,
                         Req_WD_Ret_Amt_SACConsBasic__c,Approved_WD_Retention_On_ReqDiscbasic__c,Apr_WD_Ret_Amt_SACConsBasic__c, Req_WD_CONT__c,
                          Req_WD_CONT_Amt_Consumer_Basic__c,Approved_WD_CONT__c,Approved_WD_CONT_Amt_Consumer_Basic__c,Req_Net_Rlizd_Bsc_Disc__c,
                          Req_Net_Realizd_BsicAmnt_Rate_Unit__c,Approved_Net_Realized_Basic_Discount__c,Approved_Net_Realized_Basic_Rate_Unit__c,
                          COP__c,Requested_COP_Factor__c,Approved_COP_Factor__c,Product_Name__c from QuoteLineItem  where QuoteId=: QuoteId ];
       
        Opportunities =[Select Name,Id,Segment__c,Transaction_Type__c,Account.Name,Primary_contact__r.Name,End_Customer__r.name,Product_Loyality__c,Influencer__c,Competitor__c,Competitor_If_Other__c,
                    Order_Type__c ,Dealer_Involved_Y_N__c,Payment_Terms__c,Dealer_Name__r.Name,AccountId From Opportunity where Id=: Quotes.OpportunityId LIMIT 1];
         quoteApprovalHstry = [Select Id,Quote__c, Approval_Comments__c,Status__c From Quote_Approval_History__c
                               where Quote__r.Id =: QuoteId LIMIT 1];
String strJson = Quotes.sumTotal__c;
  lstSummations =(List<Summation> )JSON.deserialize(strJson,List<Summation>.class);
}
    // wrapper class
    public class Summation{
        public String LOB  {get; set;}
        public String summation_listPrice  {get; set;}
        public string summation_unitPrice  {get; set;}
        public string summationApprovedCustomerDiscountedBasicPrice  {get; set;}
        public string summationReqWDRetSACOnReqDiscBasic  {get; set;}
        public string summationAppWDRetReqDiscbasic  {get; set;}
        public string summationReqWDCONT  {get; set;}
        public string summationApprovedWDCONT  {get; set;}
        public string summationReqNetRealizdBsicAmntRateUnit  {get; set;}
        public string summationApprovedNetRealizedBasicRateUnit  {get; set;}
        public string summationCOPperUnit  {get; set;}
         public string summationRequestedCOPFactor  {get; set;}
         public string summationApprovedCOPFactor  {get; set;}
       
    }
 
}

Thank you
For Vf page controller i want to write a logic when quotelinte items are greater than 1 and product line picklist field which is from QLI is simillar wants to group and depend on that want to show grand total for other fields. please help me with this.

thank you
snehal
hi team,

I want to create approval steps for RM(MUM),RM(pun),WPS . teher are different different ranges
wpsprofit %RM(MUM) profit %RM(PUN)profit %approver
    
0 to 2 %0 to 7.5 %0 to 2%ver Head
>2 - 5 %>7.5 - 10 %>2-4%Opr team
>5>10-12 %>4-6%manager
 >12>6enggineer
please give me suggestion how to create approval steps

thank you
snehal waghmare
Hi team

I want to know how to give self approval?

condition is when BDE submitting its going for approval to manager(BDM)

when BDM is submitting want approval from BDM only

Please suggest
on Lead creation and updation if lead status is qualified or unqualified want current date . i have written below trigger but its not working

trigger LeadTrigger on Lead (before insert,Before update) {
   if(trigger.isBefore && trigger.isUpdate){
LeadTriggerHandler.befUpdt(trigger.new , trigger.oldMap);
   }

}
------------------------------------------------------------------------------------
public class LeadTriggerHandler {
    
    public static void befUpdt(List<Lead> newLd, map<Id,Lead> oldMapLd){
        
        for(Lead ld : newLd){
           if (oldMapLd != Null && ld.status != oldMapLd.get(ld.Id).status ){
                if(ld.status == 'qualified' && ld.status ==' unqualified'){
                    ld.CreatedDate = system.now() ;
                }
            }
        }
        
    }

}

thank you,
snehal
I want to write validation rule on quote object, Whenever Order Type is 'Direct billing to customer' And transaction Type is 'Scheme' , 'VLC' then other 2 fields(Req_Cont__C, Retention__c)should be only read only while creation and updation
I have written this below validation but its not working

AND(ISPICKVAL( Order_Type__c, 'Direct Billing To Customer '),
ISPICKVAL(Transaction_Typee__c, 'scheme')||
ISPICKVAL(Transaction_Typee__c, 'VLC'),
AND(ISBLANK(Req_Cont__C), ISBLANK(Retention__c) ) )

Need solution

Thank you
i want to make quote object field required depend on opportunity order type picklist value need solution
public void bulkInsertRec(Integer days)
      {
          List<Opportunity> lstOppo = new List<Opportunity>();
          For(Integer i=1; i<=3; i++){
          Opportunity obj = new Opportunity();
          obj.Name ='got opportunity'+i;
          obj.StageName = 'Prospecting';
              
              
              Date oppoDate = obj.CreatedDate.date();
              obj.CloseDate = oppoDate.addDays(days);
          obj.CloseDate = date.today();
              
              lstOppo.add(obj);
          }
          insert lstOppo;
      }

// getting error while execution null pointer exception  on the line  
Date oppoDate = obj.CreatedDate.date();
need help to write a test class for below mwntioned controller.
public class InterioB2BQuotatationController {
   
    
    public Opportunity Opportunities {get; set;}
    public Quote Quotes {get; set;}
    public Account Accounts {get; set;}
    public Contact Contacts {get; set;}
    public List<QuotelineItem> quoteLineItems{get; set;}
 
    public Quote_Approval_History__c quoteApprovalHstry{get; set;}
    public List<Summation> lstSummations {get; set;}
   
    public InterioB2BQuotatationController(){
       
        Id QuoteId = Apexpages.currentPage().getparameters().get('Id');
        
     
       Quotes = [Select Id,Name,AccountId,OpportunityId,Approval_Submission_Date__c,CreatedById,CreatedBy.Name,ContactId,QuoteNumber,CreatedDate,Interio_Sub_Division__c,
                  Sales_Branch_Name__c,Scope_of_Architect__c,Strategy_to_Win__c,Transaction_through_WD_Dealer_Investment__c,
                  Reason_for_Discount__c,LD_Clause__c,Details_of_LD_Clause__c,Delivery_Period_in_weeks__c,Delivery_Location__c,
                  Validity_Period_Approved__c,Req_WD_Ret_Disc_Basic__c,Req_WD_Ret_Cons_Basic__c,Appr_WD_Ret_Disc_Basic__c,Appr_WD_Ret_Cons_Basic__c,Req_WD_CONT__c,
                 Req_WD_CONT_Cons_Basic__c,Appr_WD_CONT_Disc_Basic__c,Appr_WD_CONT_Cons_Basic__c,Req_Net_Rlizd_Disc_Cons_Basic__c,Appr_Net_Relzd_Bsc_Disc_On_Cons_Bsc__c
                  from Quote where Id =: QuoteId Limit 1];
       
        Accounts = [Select Is_Key_Account__c,Name from Account where Id =: Quotes.AccountId];
       Contacts =  [Select Title, Department From contact where Id =: Quotes.ContactId  Limit 1];
       
        quoteLineItems = [Select  ListPrice,Id,Product_Line_c__c,Quantity,Effective_Pricebook_Date__c,Description, Requested_Customer_Discount__c, UnitPrice,
                          Approved_Customer_Discount__c,Approved_Customer_Discounted_Basic_Price__c,Req_WD_Ret_SAC_OnReqDiscBasic__c,
                         Req_WD_Ret_Amt_SACConsBasic__c,Approved_WD_Retention_On_ReqDiscbasic__c,Apr_WD_Ret_Amt_SACConsBasic__c, Req_WD_CONT__c,
                          Req_WD_CONT_Amt_Consumer_Basic__c,Approved_WD_CONT__c,Approved_WD_CONT_Amt_Consumer_Basic__c,Req_Net_Rlizd_Bsc_Disc__c,
                          Req_Net_Realizd_BsicAmnt_Rate_Unit__c,Approved_Net_Realized_Basic_Discount__c,Approved_Net_Realized_Basic_Rate_Unit__c,
                          COP__c,Requested_COP_Factor__c,Approved_COP_Factor__c,Product_Name__c from QuoteLineItem  where QuoteId=: QuoteId ];
       
        Opportunities =[Select Name,Id,Segment__c,Transaction_Type__c,Account.Name,Primary_contact__r.Name,End_Customer__r.name,Product_Loyality__c,Influencer__c,Competitor__c,Competitor_If_Other__c,
                    Order_Type__c ,Dealer_Involved_Y_N__c,Payment_Terms__c,Dealer_Name__r.Name,AccountId From Opportunity where Id=: Quotes.OpportunityId LIMIT 1];
         quoteApprovalHstry = [Select Id,Quote__c, Approval_Comments__c,Status__c From Quote_Approval_History__c
                               where Quote__r.Id =: QuoteId LIMIT 1];
String strJson = Quotes.sumTotal__c;
  lstSummations =(List<Summation> )JSON.deserialize(strJson,List<Summation>.class);
}
    // wrapper class
    public class Summation{
        public String LOB  {get; set;}
        public String summation_listPrice  {get; set;}
        public string summation_unitPrice  {get; set;}
        public string summationApprovedCustomerDiscountedBasicPrice  {get; set;}
        public string summationReqWDRetSACOnReqDiscBasic  {get; set;}
        public string summationAppWDRetReqDiscbasic  {get; set;}
        public string summationReqWDCONT  {get; set;}
        public string summationApprovedWDCONT  {get; set;}
        public string summationReqNetRealizdBsicAmntRateUnit  {get; set;}
        public string summationApprovedNetRealizedBasicRateUnit  {get; set;}
        public string summationCOPperUnit  {get; set;}
         public string summationRequestedCOPFactor  {get; set;}
         public string summationApprovedCOPFactor  {get; set;}
       
    }
 
}

Thank you
hi team,

I want to create approval steps for RM(MUM),RM(pun),WPS . teher are different different ranges
wpsprofit %RM(MUM) profit %RM(PUN)profit %approver
    
0 to 2 %0 to 7.5 %0 to 2%ver Head
>2 - 5 %>7.5 - 10 %>2-4%Opr team
>5>10-12 %>4-6%manager
 >12>6enggineer
please give me suggestion how to create approval steps

thank you
snehal waghmare
i want to make quote object field required depend on opportunity order type picklist value need solution
public void bulkInsertRec(Integer days)
      {
          List<Opportunity> lstOppo = new List<Opportunity>();
          For(Integer i=1; i<=3; i++){
          Opportunity obj = new Opportunity();
          obj.Name ='got opportunity'+i;
          obj.StageName = 'Prospecting';
              
              
              Date oppoDate = obj.CreatedDate.date();
              obj.CloseDate = oppoDate.addDays(days);
          obj.CloseDate = date.today();
              
              lstOppo.add(obj);
          }
          insert lstOppo;
      }

// getting error while execution null pointer exception  on the line  
Date oppoDate = obj.CreatedDate.date();