• Rahul
  • NEWBIE
  • 355 Points
  • Member since 2017

  • Chatter
    Feed
  • 2
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 88
    Questions
  • 95
    Replies
trigger mobileUpdate on APEX_TEST__c (before insert, after insert, after update, before update) {
    List<APEX_TEST__c> mobile = new List<APEX_TEST__c>();
    
    for(APEX_TEST__c m : mobile){
        m.mobile__c = '9413836278';
    }
    insert mobile;
}

I want to update mobile filed for all record. any help??
User-added image

This is my detail page and when i click on skip to milestone it will open a visual force page which looks like below

User-added image

How can i remove the extra portions like setup in the head part?

the button code for skip to milestone is

{!REQUIRESCRIPT("/xdomain/xdomain.js")}
{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")}
{!REQUIRESCRIPT("/support/console/39.0/integration.js")}

var status='{!Program_Member_MVN__c.Status_MVN__c}';
var PmId='{!JSENCODE(Program_Member_MVN__c.Id)}'; 
var url;
if (sforce.console.isInConsole()) {
if(status == 'On Therapy')
{
url = "/apex/Milestone_skip?id="+PmId;
window.open(url,'_blank','toolbar=0,location=0,menubar=0'); 
}  
else
{
alert("Patient must be ‘On-Therapy’ before skipping to a milestone");
}
}

var showTabId = function showTabId(thisVal) {
  sforce.console.refreshPrimaryTabById(thisVal.id, true, '');
};
if (sforce.console != null && sforce.console.isInConsole()) {
    setTimeout(function(){ 
  sforce.console.getFocusedPrimaryTabId(showTabId);
},9500);
}

i am just referring the visual force page link in the button how can modify it show only my visual force part?
Person object is parent object and premium period is child. There are 1 million premium period records for the year 2022. There is a field premium period amount on premium period object. Iam trying to get the sum of premium period amount for all the unique person IDs. Person ID is the field on person object.

I tried but I am not able to get it. Please, I need your help. Waiting for your reply. Thanks in advance.
  • June 16, 2023
  • Like
  • 0
public class caseController {
    @AuraEnabled
    public static List<Organizational_Payment__c> getCaseList(Id recordId){
        
        Id orgId;
        List<Case> org = [select ContactId from Case WHERE Id=:recordId];
        for(Case c:org){
            orgId=c.ContactId;
        }
        
        List<Organizational_Payment__c> orgPaylst = [SELECT Id,Name,Receiving_organization__r.Name,Payment_Status__c,Payment_Date__c,Payable_Amount__c,  Bank_Account_Number__c,Concerning_Person_ID__c
                              FROM Organizational_Payment__c WHERE Concerning_Person_ID__c = :orgId and Payment_Date__c > LAST_N_MONTHS:6
                                                    ORDER BY Payment_date__c DESC];
        return orgPaylst;
    }
    
    @AuraEnabled
    public static void updateRecord(List<String> lstRecordId) {
        List<Organizational_Payment__c> lstOrgPayUpdate = new   List<Organizational_Payment__c>() ;
        for(Organizational_Payment__c orgPay :[SELECT Id,Payment_Status__c FROM  Organizational_Payment__c where id = : lstRecordId] ){
            orgPay.Payment_Status__c= 'Bounced payment';
            lstOrgPayUpdate.add(orgPay);
            System.debug('Success');
            
        }
       
        if(!lstOrgPayUpdate.isEmpty()){
            update lstOrgPayUpdate;
        }
       
    }
     @AuraEnabled
    public static List<Payment_Result__c> getPayResultList(Id recordId){
        
        Id perId;
        List<Case> per = [select ContactId from Case WHERE Id=:recordId];
        for(Case c:per){
            perId=c.ContactId;
        }
        
        List<Payment_Result__c> PayReslst = [SELECT Id,Name,Payment_Status__c,Payment_Date__c,Person_ID__c,Bank_Number__c,Total_Amount_Net__c
                              FROM Payment_Result__c WHERE Person_ID__c = :perId and Payment_Date__c > LAST_N_MONTHS:6
                                                    ORDER BY Payment_Date__c DESC];
        return PayReslst;
    }
     @AuraEnabled
    public static void updatePaymentRecord(List<String> lstPayId) {
        List<Payment_Result__c> lstPayResUpdate = new   List<Payment_Result__c>() ;
        for(Payment_Result__c Pay :[SELECT Id,Payment_Status__c FROM  Payment_Result__c where id = : lstPayId] ){
            Pay.Payment_Status__c= 'Bounced payment';
            lstPayResUpdate.add(Pay);
            System.debug('Success');
            
        }
       
        if(!lstPayResUpdate.isEmpty()){
            update lstPayResUpdate;
        }
       
    }
}

What i have implemented is this :-
@isTest
public class CaseAuraControllerTest {
    public static void setupData(){   
        Account acc = TestDataFactory.createAccount();
        Contact con = TestDataFactory.createContactWithBasicInfo(acc.Id);
        Case cas = TestDataFactory.createCase(con.Id);
  
    }

}

Can you help what to do after this?
                   
  • February 22, 2022
  • Like
  • 0
 public static void insertOrderProducts(Order order, Id serviceFormId,boolean isDealerConsumption){
      /* if(isDealerConsumption == true){
         order.Pricebook2Id ='01s2h000000DQSAAA4'; 
       } */
        system.debug('@@@OrderProducts');
        List<OrderItem> orderProductsToInsert = new List<OrderItem>();
        Set<Id> productIds = new Set<Id>();
        system.debug('@@@productIds '+productIds);
        Map<Id, PricebookEntry> productIdVsPBE = new Map<Id, PricebookEntry>();
        //Added by sumith sharma on 10 -march-2021
        string strProductType = (isDealerConsumption ? GlobalConstants.PRODUCT_TYPE_DC : GlobalConstants.PRODUCT_TYPE_INCLUSION);
        List<SR_Products__c> srProducts = [Select id,Product__c,Service_Form__r.Order__r.Pricebook2Id,Quantify__c, Service_Form__c 
                                           From SR_Products__c 
                                           Where Service_Form__c =: serviceFormId 
                                                And Product__c != null 
                                            //  And Product_Type__c = :GlobalConstants.PRODUCT_TYPE_INCLUSION 
                                                And Product_Type__c = :strProductType 
                                                And isConverted__c = false];
        system.debug('@@@OrderProducts2 '+srProducts);
        for(SR_Products__c srp : srProducts){
                productIds.add(srp.Product__c);  
        }
        
        for(PricebookEntry pbe : [Select Id, Product2Id,Pricebook2Id, UnitPrice From PricebookEntry Where Pricebook2Id =: order.Pricebook2Id AND Product2Id IN: productIds]){
           system.debug('@@1234');
           system.debug(pbe);

            productIdVsPBE.put(pbe.Product2Id, pbe);
        }
        
        if(!productIdVsPBE.isEmpty()){
            for(SR_Products__c srp : srProducts){
                if(productIdVsPBE.containsKey(srp.Product__c)){
                    OrderItem item = new OrderItem(OrderId = order.Id,
                                                   Product2Id = srp.Product__c,
                                                   Quantity = srp.Quantify__c != null ? srp.Quantify__c : 1,
                                                   PriceBookEntryId = productIdVsPBE.get(srp.Product__c).Id,
                                                   ListPrice = productIdVsPBE.get(srp.Product__c).UnitPrice,
                                                   UnitPrice = productIdVsPBE.get(srp.Product__c).UnitPrice,
                                                   Line_Discount__c = 100);
                    orderProductsToInsert.add(item);
                    system.debug('@@@orderproductsize '+orderProductsToInsert);
                }
            }
        }
       // if(orderProductsToInsert.Size() > 0){
            system.debug('@@@orderproductsize '+orderProductsToInsert );

            Insert orderProductsToInsert;
      //  }
    }
 
  • May 31, 2021
  • Like
  • 0
public without sharing class MaterialRequestManager {
public void validateOrderProducts(Map<Id, OrderItem> newItems, Map<Id,OrderItem> oldItems){
        List<OrderItem> orderItems = new List<OrderItem>();
        for(OrderItem oi : newItems.values()){
            if((oi.Quantity != oldItems.get(oi.Id).Quantity)
               || (oi.Product2Id != oldItems.get(oi.Id).Product2Id)){
                orderItems.add(oi);
            }
 public void validateOrderProducts(List<OrderItem> newLineItems){
        List<Id> orderIds = new List<Id>();
        Set<Id> productIds = new Set<Id>();
        for(OrderItem oi : newLineItems){
            orderIds.add(oi.OrderId);
            productIds.add(oi.Product2Id);
        }
        
        List<Id> serviceFormIds = new List<Id>();
        Map<Id, Id> orderIdVsServiceFormId = new Map<Id, Id>();
        for(Order od: [Select Id, Service_Form__c from Order Where Id IN: orderIds And Service_Form__c != null]){
            serviceFormIds.add(od.Service_Form__c);
            orderIdVsServiceFormId.put(od.Id, od.Service_Form__c);
        }
        
        
        Map<Id, Map<Id, SR_Products__c>> srFormIdVsSRProductsMap = new Map<Id, Map<Id,SR_Products__c>>();
        for(SR_Products__c srp : [Select Id, Service_Form__c, Product__c, Quantify__c From SR_Products__c Where Service_Form__c IN: serviceFormIds And Product__c IN: productIds]){
            if(srFormIdVsSRProductsMap.containsKey(srp.Service_Form__c)){
                srFormIdVsSRProductsMap.get(srp.Service_Form__c).put(srp.Product__c, srp);
            }else{
                srFormIdVsSRProductsMap.put(srp.Service_Form__c, new Map<Id, SR_Products__c>{srp.Product__c => srp});
            }
        }
        
        Boolean isProductPresent = false;
        if(!orderIdVsServiceFormId.isEmpty()){
            for(OrderItem oi : newLineItems){
                if(orderIdVsServiceFormId.containsKey(oi.OrderId)){
                    Id serviceFormId = orderIdVsServiceFormId.get(oi.OrderId);
                    if(srFormIdVsSRProductsMap.containsKey(serviceFormId)){
                        Map<Id, SR_Products__c> idVsSRProduct = srFormIdVsSRProductsMap.get(serviceFormId);
                        if(idVsSRProduct.containsKey(oi.Product2Id)){
                            isProductPresent = true;
                        }
                        if(idVsSRProduct.containsKey(oi.Product2Id)){
                            Double srQty = idVsSRProduct.get(oi.Product2Id).Quantify__c;
                            if(oi.Quantity > srQty){
                                oi.addError(System.Label.Validate_OrderItem_Quantity_From_SR_Products +' ' + srQty);
                            }
                        }
                    }
                    
                    if(isProductPresent == false){
                        oi.addError(System.Label.Validate_OrderItem_Product_From_SR_Products);
                    }
                }
            }
        }      
    }

        }
        if(orderItems.size() > 0)
            validateOrderProducts(orderItems);
    }
   } 
  • May 11, 2021
  • Like
  • 0
Iam getting this error :-


System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.
Stack Trace: External entry point

@isTest(seealldata = true)
public class QuoteTrigger_PayTerms_GenerateDoc_Test{
             
         Static testMethod Void testMethod2(){
           
             Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             Contact con = new contact();
             con.lastname='test contact';
             con.LeadSource = 'Inbound';
             con.Contact_Status__c='Open';
             con.accountid=acc.id;
             insert con;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             opp.Contact_Name__c=con.id;
             insert opp;  
             
             OpportunityContactRole ocr = new OpportunityContactRole();
                ocr.ContactId = con.Id;
                ocr.OpportunityId = opp.Id;
                ocr.IsPrimary = TRUE;
                ocr.Role = 'Decision Maker';
                insert ocr;
             
             SBQQ__Quote__c oldquote2 = new SBQQ__Quote__c();
             oldquote2.SBQQ__Primary__c = true;
             oldquote2.SBQQ__Opportunity2__c = opp.id;
             oldquote2.SBQQ__StartDate__c = system.today();
             oldquote2.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote2.SBQQ__SubscriptionTerm__c=1;
             oldquote2.Status_Of_Approval__c='Pending';
             oldquote2.Document_Template__c= 'Auto Renew 3';
             oldquote2.SBQQ__PaymentTerms__c= 'monthly';
             oldquote2.SBQQ__BillingCountry__c ='United States';
             oldquote2.Long_Form__c=false;
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'No';
             insert oldquote2;
   //--------------------------------------------------------------------------Annual Starts here----------------
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';      
             update oldquote2;   
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';      
             update oldquote2;   
         

         }
             
               
             Static testMethod Void testMethod3(){

//----------------------------------------------Standard saas------------------------------------------------
           

             Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             Contact con = new contact();
             con.lastname='test contact';
             con.LeadSource = 'Inbound';
             con.Contact_Status__c='Open';
             con.accountid=acc.id;
             insert con;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             opp.Contact_Name__c=con.id;

             insert opp;  
             
              OpportunityContactRole ocr = new OpportunityContactRole();
              ocr.ContactId = con.Id;
              ocr.OpportunityId = opp.Id;
              ocr.IsPrimary = TRUE;
              ocr.Role = 'Decision Maker';
              insert ocr;
             
             SBQQ__Quote__c oldquote2 = new SBQQ__Quote__c();
             oldquote2.SBQQ__Primary__c = true;
             oldquote2.SBQQ__Opportunity2__c = opp.id;
             oldquote2.SBQQ__StartDate__c = system.today();
             oldquote2.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote2.SBQQ__SubscriptionTerm__c=1;
             oldquote2.Status_Of_Approval__c='Pending';
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'monthly';
             oldquote2.SBQQ__BillingCountry__c ='United States';
             oldquote2.Long_Form__c=false;
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'No';
             insert oldquote2;

             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';      
             update oldquote2;   
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';      
             update oldquote2;   
         

         }
            
    
        
    }
  • March 31, 2020
  • Like
  • 0
Iam unable to create look Relationship on user object as it doesnot  allow. I have created a Relationship on User database object.

1. Create a User lookup field on the Heroku User Database object.
- I have created it

2. Whenever the User is inserted create a copy of the user in Heroku User Database object and also update when the user is updated.
- when user is inserted its creating a copy but Iam unable to update when user is updated. Please look at my code

trigger UpdateHerokuUser on User (after insert, after update) {
    
    set<id> setid = new set<id>();
    
    set<id> updatedset = new set<id>();
    
    
    map<string ,id> mapid = new map<string,id>();
    
    list<Heroku_User_Database__c> hudlist = new list<Heroku_User_Database__c>();
    
    if(Trigger.isInsert && Trigger.isAfter){
        
        for(user u : Trigger.new){
            
            setid.add(u.id);
            
        }
         list<user> usr =[select id, name, Email,Username from user where id IN: setid];
     
        for(user u : usr){
        
        Heroku_User_Database__c hu = new Heroku_User_Database__c();
        hu.name= u.name;
        hu.Email__c= u.Email;
        hu.User__c=  u.id;
        hu.Username__c = u.Username ;   
        
        hudlist.add(hu);
        
    
        }

       insert hudlist;
           
       system.debug('hudid2'+hudlist);
 
    }
     
           
        
    if(Trigger.isUpdate && Trigger.isAfter){
    
      for(user u : trigger.new){
      
      updatedset.add(u.id);
      
      
      }

    
    }
     
       
}
  • March 16, 2020
  • Like
  • 0
public class QuoteHandler_PayTerms_GenerateDoc {

            Public void Documenttemplate(list<SBQQ__Quote__c> newlist) {
            
            list<SBQQ__QuoteTemplate__c> qt = [select id,Name,SBQQ__Default__c  from SBQQ__QuoteTemplate__c];
            Map<String, SBQQ__QuoteTemplate__c> quoteMap1 = new Map<String, SBQQ__QuoteTemplate__c>();
             for(SBQQ__QuoteTemplate__c q :qt) {
              quoteMap1.put(q.Name, q);
             }
            SBQQ__QuoteTemplate__c qt0 = quoteMap1.get('Auto Renew');
            Map<string, SBQQ__QuoteTemplate__c> quoteMap = new Map<String, SBQQ__QuoteTemplate__c>();
            
                 for(SBQQ__Quote__c ss : newlist) 
                 {
                 
                        if(qt0 != null) {
                            qt0.SBQQ__Default__c = false;
                            quoteMap.put('qt0',qt0);
                        }
                }
                if(ss.Document_Template__c=='Auto Renew' && ( ss.SBQQ__PaymentTerms__c=='Monthly' ||  ss.SBQQ__PaymentTerms__c=='Quarterly') && ss.SBQQ__TotalCustomerDiscountAmount__c > 0 && ss.Long_Form__c==False && ss.Logo__c == True) 
                  {
                      if(qt0 != null)
                      qt0.SBQQ__Default__c = true;
                      qt0.SBQQ__LogoDocumentId__c = '015540000001owj';
                      quoteMap.put('qt0',qt0);
                  }                
                
                                     try{
                            update quoteMap.values();            
                        }
                        catch(exception e) {
                            system.debug('error:'+e);
                        }
        
            }

}

test class:-
@isTest(seeAllData = true)
public class QuoteTrigger_PayTerms_GenerateDoc_Test{
         Static testMethod Void testMethod2(){
           Test.starttest();
            Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             insert opp;  
             
            
             SBQQ__Quote__c oldquote = new SBQQ__Quote__c();
             oldquote.SBQQ__Primary__c = true;
             oldquote.SBQQ__Opportunity2__c = opp.id;          
             oldquote.SBQQ__StartDate__c = system.today();
             oldquote.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote.SBQQ__SubscriptionTerm__c=1;
             oldquote.Status_Of_Approval__c='Pending';
             oldquote.Document_Template__c= 'Auto Renew';
             oldquote.SBQQ__PaymentTerms__c= 'monthly';
             oldquote.SBQQ__BillingCountry__c ='United States';
             oldquote.Long_Form__c = false;
             oldquote.Logo__c = true;
             
             insert oldquote;
             SBQQ__QuoteTemplate__c qt0 = new SBQQ__QuoteTemplate__c();

               qt0.Name='Auto renew';
               qt0.SBQQ__Default__c=false;
               qt0.SBQQ__PageWidth__c= 8.5;
               qt0.SBQQ__TopMargin__c =0.50;
               qt0.SBQQ__LeftMargin__c = 0.50;
               qt0.SBQQ__PageHeight__c  =11.00;
               qt0.SBQQ__BottomMargin__c = 0.50;   
               qt0.SBQQ__RightMargin__c = 0.50;
               qt0.SBQQ__FontFamily__c = 'Helvetica';
               qt0.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt0.SBQQ__BorderColor__c = '000000';
               qt0.SBQQ__FontSize__c = 9.0;
               qt0.SBQQ__LogoDocumentId__c = '015540000001owj';
               insert qt0;

}
 
  • January 16, 2020
  • Like
  • 0
I have converted the visualforce page into lightning using Lightning experience configuration convertor It shows upload files button instead of the New note button in the Notes related list in lightning. In classic its displaying fine as New Notes.
Iam using          
 <apex:relatedList list="AttachedContentNotes" rendered="{! $Profile.Name != 'Customer' }"/> 
in the Visualforce Page. Please find the Image below.User-added imageUser-added image
  • November 28, 2019
  • Like
  • 0
Test class:-

@isTest
public class QuoteTrigger_PayTerms_GenerateDoc_Test{
         Static testMethod Void testMetho
d2(){
           Test.starttest();

             Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             insert opp;  
             
             //  Quote Templates-------------------------------------------------------
             
             SBQQ__QuoteTemplate__c qt10 = new SBQQ__QuoteTemplate__c();

               qt10.Name='Auto Renew without Discount';
               qt10.SBQQ__Default__c=false;
               qt10.SBQQ__PageWidth__c= 8.5;
               qt10.SBQQ__TopMargin__c =0.50;
               qt10.SBQQ__LeftMargin__c = 0.50;
               qt10.SBQQ__PageHeight__c  =11.00;
               qt10.SBQQ__BottomMargin__c = 0.50;   
               qt10.SBQQ__RightMargin__c = 0.50;
               qt10.SBQQ__FontFamily__c = 'Helvetica';
               qt10.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt10.SBQQ__BorderColor__c = '000000';
               qt10.SBQQ__FontSize__c = 9.0;
               insert qt10;
            
             SBQQ__QuoteTemplate__c qt9 = new SBQQ__QuoteTemplate__c();

               qt9.Name='Basic Template without Discount';
               qt9.SBQQ__Default__c=false;
               qt9.SBQQ__PageWidth__c= 8.5;
               qt9.SBQQ__TopMargin__c =0.50;
               qt9.SBQQ__LeftMargin__c = 0.50;
               qt9.SBQQ__PageHeight__c  =11.00;
               qt9.SBQQ__BottomMargin__c = 0.50;   
               qt9.SBQQ__RightMargin__c = 0.50;
               qt9.SBQQ__FontFamily__c = 'Helvetica';
               qt9.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt9.SBQQ__BorderColor__c = '000000';
               qt9.SBQQ__FontSize__c = 9.0;
               insert qt9;
            
             SBQQ__QuoteTemplate__c qt8 = new SBQQ__QuoteTemplate__c();

               qt8.Name='Auto Renew with 3% Annual Increment Without Discount';
               qt8.SBQQ__Default__c=false;
               qt8.SBQQ__PageWidth__c= 8.5;
               qt8.SBQQ__TopMargin__c =0.50;
               qt8.SBQQ__LeftMargin__c = 0.50;
               qt8.SBQQ__PageHeight__c  =11.00;
               qt8.SBQQ__BottomMargin__c = 0.50;   
               qt8.SBQQ__RightMargin__c = 0.50;
               qt8.SBQQ__FontFamily__c = 'Helvetica';
               qt8.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt8.SBQQ__BorderColor__c = '000000';
               qt8.SBQQ__FontSize__c = 9.0;
               insert qt8;
       
             SBQQ__QuoteTemplate__c qt7 = new SBQQ__QuoteTemplate__c();

               qt7.Name='Auto Renew with 3% Annual Increment with Autopay';
               qt7.SBQQ__Default__c=false;
               qt7.SBQQ__PageWidth__c= 8.5;
               qt7.SBQQ__TopMargin__c =0.50;
               qt7.SBQQ__LeftMargin__c = 0.50;
               qt7.SBQQ__PageHeight__c  =11.00;
               qt7.SBQQ__BottomMargin__c = 0.50;   
               qt7.SBQQ__RightMargin__c = 0.50;
               qt7.SBQQ__FontFamily__c = 'Helvetica';
               qt7.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt7.SBQQ__BorderColor__c = '000000';
               qt7.SBQQ__FontSize__c = 9.0;
               insert qt7;
            
            SBQQ__QuoteTemplate__c qt6 = new SBQQ__QuoteTemplate__c();

               qt6.Name='Auto Renew with 3% Annual Increment';
               qt6.SBQQ__Default__c=false;
               qt6.SBQQ__PageWidth__c= 8.5;
               qt6.SBQQ__TopMargin__c =0.50;
               qt6.SBQQ__LeftMargin__c = 0.50;
               qt6.SBQQ__PageHeight__c  =11.00;
               qt6.SBQQ__BottomMargin__c = 0.50;   
               qt6.SBQQ__RightMargin__c = 0.50;
               qt6.SBQQ__FontFamily__c = 'Helvetica';
               qt6.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt6.SBQQ__BorderColor__c = '000000';
               qt6.SBQQ__FontSize__c = 9.0;
               insert qt6;
            
             SBQQ__QuoteTemplate__c qt5 = new SBQQ__QuoteTemplate__c();

               qt5.Name='Auto Renew';
               qt5.SBQQ__Default__c=false;
               qt5.SBQQ__PageWidth__c= 8.5;
               qt5.SBQQ__TopMargin__c =0.50;
               qt5.SBQQ__LeftMargin__c = 0.50;
               qt5.SBQQ__PageHeight__c  =11.00;
               qt5.SBQQ__BottomMargin__c = 0.50;   
               qt5.SBQQ__RightMargin__c = 0.50;
               qt5.SBQQ__FontFamily__c = 'Helvetica';
               qt5.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt5.SBQQ__BorderColor__c = '000000';
               qt5.SBQQ__FontSize__c = 9.0;
               insert qt5;
               
             SBQQ__QuoteTemplate__c qt4 = new SBQQ__QuoteTemplate__c();

               qt4.Name='Basic Template with Auto Pay';
               qt4.SBQQ__Default__c=false;
               qt4.SBQQ__PageWidth__c= 8.5;
               qt4.SBQQ__TopMargin__c =0.50;
               qt4.SBQQ__LeftMargin__c = 0.50;
               qt4.SBQQ__PageHeight__c  =11.00;
               qt4.SBQQ__BottomMargin__c = 0.50;   
               qt4.SBQQ__RightMargin__c = 0.50;
               qt4.SBQQ__FontFamily__c = 'Helvetica';
               qt4.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt4.SBQQ__BorderColor__c = '000000';
               qt4.SBQQ__FontSize__c = 9.0;
               insert qt4;
               
             SBQQ__QuoteTemplate__c qt3 = new SBQQ__QuoteTemplate__c();

            qt3.Name='Basic Template';
               qt3.SBQQ__Default__c=false;
               qt3.SBQQ__PageWidth__c= 8.5;
               qt3.SBQQ__TopMargin__c =0.50;
               qt3.SBQQ__LeftMargin__c = 0.50;
               qt3.SBQQ__PageHeight__c  =11.00;
               qt3.SBQQ__BottomMargin__c = 0.50;   
               qt3.SBQQ__RightMargin__c = 0.50;
               qt3.SBQQ__FontFamily__c = 'Helvetica';
               qt3.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt3.SBQQ__BorderColor__c = '000000';
               qt3.SBQQ__FontSize__c = 9.0;
               insert qt3;
               
               qt3.SBQQ__Default__c=true;
               update qt3;
            
             SBQQ__Quote__c oldquote = new SBQQ__Quote__c();
             oldquote.SBQQ__Primary__c = true;
             oldquote.SBQQ__Opportunity2__c = opp.id;
             oldquote.SBQQ__StartDate__c = system.today();
             oldquote.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote.SBQQ__SubscriptionTerm__c=1;
             
             /*
             Document documentObj = new Document();
             documentObj.Body = Blob.valueOf('Some Document Text');
             documentObj.ContentType = 'application/pdf';
             documentObj.DeveloperName = 'my_document';
             documentObj.IsPublic = true;
             documentObj.Name = 'Recurring Payment Agreement Form';
             documentObj.FolderId = [select id from folder limit 1].id;
             insert documentObj; 
             */
             oldquote.Status_Of_Approval__c='Pending';
             oldquote.Document_Template__c= 'Auto Renew';

             oldquote.SBQQ__PaymentTerms__c= 'monthly';
             oldquote.SBQQ__BillingCountry__c ='United States';
             insert oldquote;
                
             oldquote.Document_Template__c= 'Auto Renew 3';
             oldquote.SBQQ__PaymentTerms__c= 'monthly';
             oldquote.SBQQ__BillingCountry__c ='Japan';

             update oldquote;
             
              SBQQ__QuoteTemplate__c qt11 = new SBQQ__QuoteTemplate__c();
               
             oldquote.Document_Template__c= 'Basic Template';
             oldquote.SBQQ__PaymentTerms__c= 'monthly';
             update oldquote;
                
            SBQQ__RelatedContent__c att = new SBQQ__RelatedContent__c();
            att.Name ='Recurring Payment Agreement Form_2.pdf';
          //att.Owner=Userinfo.getuserid();
          //att.SBQQ__TemplateSection__c
            att.SBQQ__Required__c=true;
          //att.SBQQ__QuoteTemplate__c
            att.SBQQ__Quote__c =oldquote.id;
           //att.SBQQ__Product__c
            att.SBQQ__Opportunity__c = opp.id;
            att.SBQQ__ExternalId__c='00P5400000254mHEAQ';
          //att.SBQQ__DocumentName__c='00P5400000254mHEAQ';
          //att.SBQQ__DisplayOrder__c
                
            insert att;

            SBQQ__Quote__c oldquote2 = new SBQQ__Quote__c();
            oldquote2.SBQQ__Primary__c = true;
            oldquote2.SBQQ__Opportunity2__c = opp.id;
            oldquote2.SBQQ__StartDate__c = system.today();
            oldquote2.SBQQ__EndDate__c= system.today().addmonths(3);
            oldquote2.SBQQ__SubscriptionTerm__c=1;
        
            oldquote2.Status_Of_Approval__c='Pending';
            oldquote2.Document_Template__c= 'Auto Renew';

            oldquote2.SBQQ__PaymentTerms__c= 'monthly';
            
            insert oldquote2;

         }
   
    }

 
  • August 28, 2019
  • Like
  • 0
Test class:-

@istest
public class AddAttachmentOnQuotes_Test{
     Static testMethod Void testMethod2(){
           Test.starttest();

             Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();

             opp.accountid=acc.id;
            insert opp;  
            
                SBQQ__Quote__c oldquote = new SBQQ__Quote__c();
                oldquote.SBQQ__Primary__c = true;
                oldquote.SBQQ__Opportunity2__c = opp.id;
                oldquote.SBQQ__StartDate__c = system.today();
                oldquote.SBQQ__EndDate__c= system.today().addmonths(3);
                oldquote.SBQQ__SubscriptionTerm__c=1;
            
                oldquote.Status_Of_Approval__c='Pending';
                oldquote.Document_Template__c= 'Auto Renew';

                oldquote.SBQQ__PaymentTerms__c= 'monthly';
               // oldquote.Contract_End_Date__c = system.today().addmonths(3);
                insert oldquote;
                
                oldquote.Document_Template__c= 'Auto Renew 3';
                oldquote.SBQQ__PaymentTerms__c= 'monthly';
                update oldquote;
                
                 oldquote.Document_Template__c= 'Basic Template';
                oldquote.SBQQ__PaymentTerms__c= 'monthly';
                update oldquote;
            
            
             
         }   
            
          
}



Apex handler:-

Public class AddAttachmentOnQuotes {
    public static void createAttachment(List<SBQQ__Quote__c> quotes){
        List<Attachment> attls = [select id, Name, body from Attachment where name like '%Recurring Payment Agreement Form_2%' limit 1];
        List<Attachment> newAttls = new List<Attachment>();
        
        if(attls.size() > 0) { 
            for(SBQQ__Quote__c q1 :quotes) {
               Attachment newFile = attls[0].clone();
               newFile.ParentId = q1.id;
               newAttls.add(newFile);
                
            }
        }
        if(newAttls.size() > 0) {
            insert newAttls;
        }
        
        List<SBQQ__RelatedContent__c> relConls = new List<SBQQ__RelatedContent__c>();
        for(Attachment newAtt :newAttls) {
            SBQQ__RelatedContent__c relCon = new SBQQ__RelatedContent__c();
            relCon.Name = newAtt.Name;
            relCon.SBQQ__Quote__c = newAtt.parentId;
            relCon.SBQQ__ExternalId__c = newAtt.Id;
            relCon.SBQQ__Required__c = true;
            relConls.add(relCon); 
        }
        if(relConls.size()>0) {
            insert relConls;
        }
    
    }
}

Apex trigger :-

trigger QuoteTrigger_PayTerms_GenerateDoc on SBQQ__Quote__c (after insert, after update) {


        if(Trigger.Isinsert) {
            pt.Documenttemplate(Trigger.new);
            AddAttachmentOnQuotes.createAttachment(Trigger.new);
        }
       
        // for quote creation...
        if(Trigger.IsUpdate) {
            List<SBQQ__Quote__c> quotels = new List<SBQQ__Quote__c>();
            Set<Id> quoteIds = new Set<Id>();
            
            for(SBQQ__Quote__c qt : trigger.new) {
                quoteIds.add(qt.id);
            }
            set<Id> existingQuoteIds = new Set<Id>();
            List<Attachment> attls = [select id, Name,parentId from Attachment where parentId = :quoteIds];
            for(Attachment att :attls) {
                existingQuoteIds.add(att.id);
            }
            for(SBQQ__Quote__c qt : trigger.new) {
            
                if((qt.Document_Template__c == 'Auto Renew' && ( qt.SBQQ__PaymentTerms__c=='Monthly' ||  qt.SBQQ__PaymentTerms__c=='Quarterly'))
                
                    ||(qt.Document_Template__c=='Auto Renew 3' && ( qt.SBQQ__PaymentTerms__c=='Quarterly' ||  qt.SBQQ__PaymentTerms__c=='Monthly'))
                    
                    ||(qt.Document_Template__c=='Basic Template' && ( qt.SBQQ__PaymentTerms__c=='Quarterly' ||  qt.SBQQ__PaymentTerms__c=='Monthly'))
                    
                    && qt.Document_Template__c != trigger.oldMap.get(qt.id).Document_Template__c
                    
                    && !existingQuoteIds.contains(qt.Id)) {
                    
                        quotels.add(qt);
                }
            }
            if(quotels.size() > 0) {
               AddAttachmentOnQuotes.createAttachment(Trigger.new); 
            }    
        }
            
}
 
  • July 18, 2019
  • Like
  • 0
//To get all the leads from housing
public class HousingHelper
{  
    public static void searchLead()
    {   
        //to check if lead is already created for today
        Set<String> setOfMobiles = new Set<String>();
        Set<String> setOfEmails = new Set<String>();
        //for error mail
        String errorBody = '';
        Boolean hasError = false ;
        //start date
        Date todayDate = System.today();
        DateTime startDateToday=Datetime.newInstance(todaydate.year(), todaydate.month(), todaydate.day(), 00, 00, 00);
        Long epochStartDate = (startDateToday.getTime()/1000);
        DateTime endDateToday=Datetime.newInstance(todaydate.year(), todaydate.month(), todaydate.day(), 23, 59, 59);
        Long epochEndDate = (endDateToday.getTime()/1000);
        String salt = String.valueOf((datetime.now().getTime()/1000));
        String key = 'b13cad2be5dde31ebca4c6f451e02abe';
        Blob mac = Crypto.generateMac('HmacSHA256', Blob.valueOf(salt), Blob.valueOf(key));
        String encripted = EncodingUtil.convertToHex(mac);
        String idValue = '171726';
        Http h = new Http();
        HttpRequest request = new HttpRequest();
        request.setMethod('GET');
        request.setEndPoint('https://leads.housing.com/api/v0/get-builder-leads?start_date='+epochStartDate+'&end_date='+epochEndDate+'&current_time='+salt+'&hash='+encripted+'&id='+idValue);
        HttpResponse response = new HttpResponse(); 
        response = h.send(request);
        system.debug('status code:'+response.getStatuscode());
        system.debug('code: '+response.getBody());
        try
        {
            List<HousingHelper.wrapperLeadsHousing> wrapResponse = new List<HousingHelper.wrapperLeadsHousing>();//wrapper for consuming response from the API
            wrapResponse = (List<HousingHelper.wrapperLeadsHousing>)System.JSON.deserialize(response.getBody(),List<HousingHelper.wrapperLeadsHousing>.class);//converting response into object in salesforce
            if(wrapResponse.size()>0){
                Id queueId = [Select id, Name from Group where type='Queue' AND Name='Unassigned Leads' limit 1].Id;
                Id freshSales= [select id from recordtype where name='Fresh Sales' AND sObjectType='Lead'].id;
                List<Lead> newLeads = new List<Lead>();
                /*========== To check if leads with same mobile or email are created today ===================================
for(HousingHelper.wrapperLeadsHousing tempResponse : wrapResponse){
if(tempResponse.lead_Email != null)    setOfEmails.add(tempResponse.lead_Email);
if(tempResponse.lead_phone != null)    setOfMobiles.add(tempResponse.lead_phone);
}
Date filterDate= system.today();
List<Lead> listOfLeads = new List<Lead>();
listOfLeads = [Select Id, Name, MobilePhone, Email, Project__c,createdDate from Lead where (Email in : setOfEmails Or MobilePhone in : setOfMobiles) AND DAY_ONLY(convertTimezone(CreatedDate))=:filterDate];
======= Ends here ========================================================================================== */
                //New lead creation
                for(HousingHelper.wrapperLeadsHousing tempResponse : wrapResponse){
                    Lead tempLead = new Lead();
                    //lead name mapping
                    /* if((!setOfEmails.contains(tempResponse.lead_phone)) && (!setOfMobiles.contains(tempResponse.lead_Email)))
{    */                     
                    if(tempResponse.lead_name!=null){
                        String[] splitName = tempResponse.lead_name.split(' ');
                        if(splitName.size()>0){
                            //split the name into first name and last name
                            if(splitName.size()==1){
                                //tempLead.FirstName = splitName[0];
                                tempLead.LastName = splitName[0];
                            }
                            else{
                                tempLead.FirstName = splitName[0];
                                integer sizeArr = 1;
                                String tempLastName = '';
                                while(sizeArr<splitName.size()){
                                    tempLastName+=splitName[sizeArr]+' ';
                                    sizeArr++;
                                }
                                tempLead.lastName = tempLastName;
                            }
                        }
                    }
                    else
                        tempLead.lastName = 'Not provided';
                    
                    tempLead.LeadSource = 'Online';
                    tempLead.Lead_Medium__c='Housing';
                    string mobile;
                    if(tempResponse.lead_phone != null)
                        mobile=tempResponse.lead_phone;
                    if(mobile != null) {                      
                        mobile= mobile.deleteWhitespace();
                        mobile= mobile.remove(',');
                        if(mobile.length()==10)
                            tempLead.MobilePhone = mobile;
                        else
                            tempLead.Alt_Mobile__c = mobile;
                    }
                    string email=tempResponse.lead_Email;
                    if(email != null){
                        email= email.deleteWhitespace();
                        email= email.remove(',');
                    }
                    tempLead.Email = email;
                    tempLead.Primary_Customer_Status__c = 'Unattended';
                    tempLead.Company = 'Company name not provided';
                    tempLead.RecordTypeId = freshSales;
                    if(tempResponse.project_name == 'Ashiana Town B')
                        tempLead.ProjectName__c = 'Ashiana Town';
                    else
                        tempLead.ProjectName__c = tempResponse.project_name;
                    tempLead.Country_Code__c = tempResponse.country_code ;
                    //tempLead.Address_line_1__c = tempResponse.locality_name ;
                    if(queueId!=null){
                        tempLead.OwnerId = queueId;    
                    }
                    newLeads.add(tempLead);
                    //}
                }//End of For loop Housing Loop
                try{
                    
                    Database.SaveResult[] srList = Database.insert(newLeads,False);
                    String errorMsg = '<table border="1" align="center" style="width:100%;border-collapse: collapse;"><caption>Housing Lead Error Table</caption><tr style="background-color:#87CEFA !important;"><th>Lead Name</th><th>Mobile</th><th>Email Id</th><th>Project</th><th>Field</th><th>Error message</th></tr>';
                    // Iterate through each returned result
                    for (Integer i=0;i<srList.size();i++) {
                        if (srList[i].isSuccess()) {
                            // Operation was successful, so get the ID of the record that was processed
                            System.debug('Successfully inserted lead. Lead ID: ' + srList[i].getId());
                        }
                        else {
                            
                            hasError = true;
                            String error = '';
                            String fields='';
                            // Get all errors                
                            for(Database.Error err : srList[i].getErrors()) {
                                System.debug('The following error has occurred.');                    
                                System.debug(err.getStatusCode() + ': ' + err.getMessage());
                                System.debug('Lead fields that affected this error: ' + err.getFields());
                                error+=err.getMessage();
                                fields+=err.getFields();
                            }
                            errorMsg+='<tr><td style="width:13%;"><center>'+newLeads[i].FirstName+' '+newLeads[i].LastName+'<center></td><td style="width:13%;"><center>'+newLeads[i].MobilePhone+'<center></td><td style="width:13%;"><center>'+newLeads[i].Email+'<center></td><td style="width:10%;"><center>'+newLeads[i].ProjectName__c+'<center></td><td style="width:10%;"><center>'+fields+'<center></td><td style="width:20%;"><center>'+error+'<center></td></tr>' ;
                        }
                    }
                    if(hasError){
                        errorMsg += '</table>';
                        errorBody = '<html><body>Dear Admin,<br/><br/>Error in following leads : <br/><br/>'+errorMsg;
                    }
                }
                catch(DMLException e){
                    //hasError = true;
                    //errorBody = '<html><body>Dear Admin,<br/><br/>Error due to '+e.getMessage();
                    System.debug('Error in inserting leads from housing due to '+e.getMessage());
                }
            }            
        }
        Catch(Exception e)
        { 
            //hasError = true;
            //errorBody = '<html><body>Dear Admin,<br/><br/>Error due to '+e.getMessage();
            system.debug('error'+e.getMessage());
        }
        if(hasError){
            list<Email_for_integration_error_mail__mdt> tempEmailIds = [Select Email__c from Email_for_integration_error_mail__mdt];
            
            system.debug('tempEmailIds:'+tempEmailIds);
            List<String> emailIds = new List<String>();
            for(Email_for_integration_error_mail__mdt email : tempEmailIds){
                emailIds.add(email.Email__c);
            }
            system.debug('emailIds:'+emailIds);
            errorBody +='<br/><br/><br/>Thanks & Regards</body></html>';
            Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
            message.toAddresses =  emailIds;
            message.subject = 'Error in Housing Lead Integrations || Date : '+(System.today()).format();
            message.setHtmlBody(errorBody);
            message.setsaveAsActivity(false);
            Messaging.SingleEmailMessage[] messages =   new List<Messaging.SingleEmailMessage> {message};
                Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
            if (results[0].success) {
                System.debug('The email was sent successfully.');
            } else {
                System.debug('The email failed to send: ' + results[0].errors[0].message);
            } 
        }
        
        
        
    }
    
    public class wrapperLeadsHousing { // Convert API response to object in salesforce to save leads
        public Integer lead_date;
        public String lead_name;
        public String lead_email;
        public String lead_phone;
        public String country_code;
        public Integer project_id;
        public String project_name;
        public String locality_name;
        
    }
}
  • July 12, 2019
  • Like
  • 0
public class QuoteHandler_PayTerms_GenerateDoc {
  Public void Documenttemplate(list<SBQQ__Quote__c> newlist){
    list<SBQQ__QuoteTemplate__c> qt1 = [select id,Name,SBQQ__Default__c  from SBQQ__QuoteTemplate__c WHERE name =:'Auto Renew' ];
        list<SBQQ__QuoteTemplate__c> qt2 = [select id,Name,SBQQ__Default__c  from SBQQ__QuoteTemplate__c WHERE name =:'Auto Renew with Auto pay' ];
        list<SBQQ__QuoteTemplate__c> qt3 = [select id,Name,SBQQ__Default__c  from SBQQ__QuoteTemplate__c WHERE name =:'Basic Template'];
        list<SBQQ__QuoteTemplate__c> qt4 = [select id,Name,SBQQ__Default__c  from SBQQ__QuoteTemplate__c WHERE name =:'Basic Template with Auto Pay'];                
        list<SBQQ__QuoteTemplate__c> qt5 = [select id,Name,SBQQ__Default__c  from SBQQ__QuoteTemplate__c WHERE name =:'Auto Renew with 3% Annual Increment with Autopay'];
        list<SBQQ__QuoteTemplate__c> qt6 = [select id,Name,SBQQ__Default__c  from SBQQ__QuoteTemplate__c WHERE name =:'Auto Renew with 3% Annual Increment'];
        list<SBQQ__QuoteTemplate__c> list1 = new list<SBQQ__QuoteTemplate__c>();
                for(SBQQ__Quote__c ss : newlist)
            {
                        if(ss.Document_Template__c=='Auto Renew' && ( ss.SBQQ__PaymentTerms__c=='Monthly' ||  ss.SBQQ__PaymentTerms__c=='Quarterly')   )
                {        
                    if(Test.isRunningTest()) {
                        qt2.add(new  SBQQ__QuoteTemplate__c());
                        qt1.add(new  SBQQ__QuoteTemplate__c());
                        qt3.add(new  SBQQ__QuoteTemplate__c());
                        qt4.add(new  SBQQ__QuoteTemplate__c());
                        qt5.add(new  SBQQ__QuoteTemplate__c());
                        qt6.add(new  SBQQ__QuoteTemplate__c());
                    }                    
                    if(qt2.size() >0) {
                        qt2[0].SBQQ__Default__c = true;
                        list1.add(qt2[0]);
                    }
                    if(qt1.size() >0) {
                        qt1[0].SBQQ__Default__c = false;
                        list1.add(qt1[0]);
                    }
                    if(qt3.size() >0) {
                        qt3[0].SBQQ__Default__c = false;
                        list1.add(qt3[0]);
                    }
                    if(qt4.size() >0) {
                        qt4[0].SBQQ__Default__c = false;
                        list1.add(qt4[0]);
                    }
                    if(qt5.size() >0) {
                        qt5[0].SBQQ__Default__c = false;
                        list1.add(qt5[0]);
                    }
                    if(qt6.size() >0) {
                        qt6[0].SBQQ__Default__c = false;
                        list1.add(qt6[0]);
                    }
                }
                if(ss.Document_Template__c=='Auto Renew' && ( ss.SBQQ__PaymentTerms__c=='Annual' ||  ss.SBQQ__PaymentTerms__c=='Semi-annual' || ss.SBQQ__PaymentTerms__c=='Upfront') )
                {  
                    if(Test.isRunningTest()) {
                        qt2.add(new  SBQQ__QuoteTemplate__c());
                        qt1.add(new  SBQQ__QuoteTemplate__c());
                        qt3.add(new  SBQQ__QuoteTemplate__c());
                        qt4.add(new  SBQQ__QuoteTemplate__c());
                        qt5.add(new  SBQQ__QuoteTemplate__c());
                        qt6.add(new  SBQQ__QuoteTemplate__c());
                    }
                   if(qt2.size() >0) {
                        qt2[0].SBQQ__Default__c = False;
                        list1.add(qt2[0]);
                    }
                    if(qt1.size() >0) {
                        qt1[0].SBQQ__Default__c = True;
                        list1.add(qt1[0]);
                    }
                    if(qt3.size() >0) {
                        qt3[0].SBQQ__Default__c = false;
                        list1.add(qt3[0]);
                    }
                    if(qt4.size() >0) {
                        qt4[0].SBQQ__Default__c = false;
                        list1.add(qt4[0]);
                    }
                    if(qt5.size() >0) {
                        qt5[0].SBQQ__Default__c = false;
                        list1.add(qt5[0]);
                    }
                    if(qt6.size() >0) {
                        qt6[0].SBQQ__Default__c = false;
                        list1.add(qt6[0]);
                    }
                }
                if(ss.Document_Template__c=='Auto Renew 3' && ( ss.SBQQ__PaymentTerms__c=='Quarterly' ||  ss.SBQQ__PaymentTerms__c=='Monthly') )
                {
                    if(Test.isRunningTest()) {
                        qt2.add(new  SBQQ__QuoteTemplate__c());
                        qt1.add(new  SBQQ__QuoteTemplate__c());
                        qt3.add(new  SBQQ__QuoteTemplate__c());
                        qt4.add(new  SBQQ__QuoteTemplate__c());
                        qt5.add(new  SBQQ__QuoteTemplate__c());
                        qt6.add(new  SBQQ__QuoteTemplate__c());
                    }
                     if(qt2.size() >0) {
                        qt2[0].SBQQ__Default__c = false;
                        list1.add(qt2[0]);
                    }
                    if(qt1.size() >0) {
                        qt1[0].SBQQ__Default__c = false;
                        list1.add(qt1[0]);
                    }
                    if(qt3.size() >0) {
                        qt3[0].SBQQ__Default__c = false;
                        list1.add(qt3[0]);
                    }
                    if(qt4.size() >0) {
                        qt4[0].SBQQ__Default__c = false;
                        list1.add(qt4[0]);
                    }
                    if(qt5.size() >0) {
                        qt5[0].SBQQ__Default__c = True;
                        list1.add(qt5[0]);
                    }
                    if(qt6.size() >0) {
                        qt6[0].SBQQ__Default__c = false;
                        list1.add(qt6[0]);
                    }
                }
                if(ss.Document_Template__c=='Auto Renew 3' && (  ss.SBQQ__PaymentTerms__c=='Annual' ||  ss.SBQQ__PaymentTerms__c=='Semi-annual' || ss.SBQQ__PaymentTerms__c=='Upfront')  )
                {
                    if(Test.isRunningTest()) {
                        qt2.add(new  SBQQ__QuoteTemplate__c());
                        qt1.add(new  SBQQ__QuoteTemplate__c());
                        qt3.add(new  SBQQ__QuoteTemplate__c());
                        qt4.add(new  SBQQ__QuoteTemplate__c());
                        qt5.add(new  SBQQ__QuoteTemplate__c());
                        qt6.add(new  SBQQ__QuoteTemplate__c());
                    }
                    if(qt2.size() >0) {
                        qt2[0].SBQQ__Default__c = false;
                        list1.add(qt2[0]);
                    }
                    if(qt1.size() >0) {
                        qt1[0].SBQQ__Default__c = false;
                        list1.add(qt1[0]);
                    }
                    if(qt3.size() >0) {
                        qt3[0].SBQQ__Default__c = false;
                        list1.add(qt3[0]);
                    }
                    if(qt4.size() >0) {
                        qt4[0].SBQQ__Default__c = false;
                        list1.add(qt4[0]);
                    }
                    if(qt5.size() >0) {
                        qt5[0].SBQQ__Default__c = false;
                        list1.add(qt5[0]);
                    }
                    if(qt6.size() >0) {
                        qt6[0].SBQQ__Default__c = True;
                        list1.add(qt6[0]);
                    }
                }
          
            try {
                update list1;            
            }
                catch(exception e) {
                    system.debug('error:'+e);
                }
    }
}
}

 
  • July 10, 2019
  • Like
  • 0
  • July 08, 2019
  • Like
  • 0
Test Class :-

@IsTest
public class OpportunityHandlerTest 
{
   //public static String VAR_EXP = '0 0 0 15 3 ? 2022'; 
   
   private static testmethod void MyUnitTest()
   {  
       Integer MAX_QUERY = Limits.getLimitQueries();
       Integer NUM_QUERY = MAX_QUERY - 1; 
      //Create accunt
      Account acc = new account();
      acc.name='test';
      try
      {
          insert acc;
          system.debug('this is acc' +acc); 
      }
      catch(DMLException de)
      {
           system.debug('a is failed' +de.getMessage());
      }
      
       //Create contact 1
       Contact c=new Contact();
       c.lastname='nunes';
       c.Accountid=acc.id;
       c.LeadSource='Inbound';
       c.Contact_Status__c='Open';
       c.New_Lead_Source__c='Inbound';
       c.Pre_Demo_Notes__c='from pre contact';
       c.Post_Demo_Notes__c='from post contact';
       c.Created_in_admin_panel__c=true;
       insert c;
       system.assert(c.id != null);
       
       //Create contact 2
       Contact c2=new Contact();
       c2.lastname='nunes';
       c2.Accountid=acc.id;
       c2.LeadSource='Inbound';
       c2.Contact_Status__c='Open';
       c2.New_Lead_Source__c='Inbound';
       c2.Pre_Demo_Notes__c='from pre contact';
       c2.Post_Demo_Notes__c='from post contact';
       c2.Created_in_admin_panel__c=true;
       insert c2;
       system.assert(c2.id != null);
       
       
        Opportunity opp1 = new Opportunity(AccountId=acc.id,Upsell_Potential__c='No', Name='o2',contact_name__c=c.id, CloseDate=System.today(), StageName='Prospecting',Product_Specialist__c='Nicolas Carreras');
        insert opp1;

        Opportunity opp=[Select id,Contact_Name__c from Opportunity where contact_name__c != null ];
        opp.name='Start';
        opp.Contact_Name__c=c2.id;
        update opp;

        Opportunity opp2 = new Opportunity(AccountId=acc.id,Upsell_Potential__c='No', Name='o2', CloseDate=System.today(), StageName='Prospecting',Product_Specialist__c='Nicolas Carreras');
        insert opp2;

        Opportunity opp3 = new Opportunity
        (AccountId=acc.id,
        Upsell_Potential__c='SDR Target', 
        Name='o3', 
        CloseDate=System.today(), 
        StageName='Closed Won',
        Product_Specialist__c='Nicolas Carreras',
        Catalyst__c='Greenfield'
        //RenewalDate__c=system.today()
        );
        insert opp3;
        
        opp3.StageName = 'Prospecting';
        update opp3;
        
        opp3.StageName = 'Closed Won';
        update opp3; 
        
         OpportunityContactRole opcr=new OpportunityContactRole();
         opcr.OpportunityId = opp3.id;
         opcr.ContactId = c2.id;
         opcr.IsPrimary = true;
         opcr.Role='End-User';
         insert opcr;
        system.assert(opcr.id != null); 
        
        Id stdpricebook = System.Test.getStandardPricebookId();
        system.debug('this is stdpricebook : ' +stdpricebook);
        system.assert(stdpricebook != null);
        
        List<SBQQ__Quote__c> qlist=new List<SBQQ__Quote__c>();
        SBQQ__Quote__c thisquote=new SBQQ__Quote__c();
        thisquote.SBQQ__SubscriptionTerm__c=12;
        thisquote.SBQQ__StartDate__c=system.today();
        thisquote.SBQQ__PriceBook__c=stdpricebook;
        thisquote.SBQQ__Primary__c=true;
        thisquote.SBQQ__Opportunity2__c=opp3.id;
        qlist.add(thisquote);
        //try{
        Test.startTest();
        insert qlist;
        Test.stopTest();
        //}
        ////catch(exception e)
        //{
        //system.debug(e);
        //}
        System.assert(thisquote.id != null);
        
        set<id> setid = new set<id>();
        
        for(SBQQ__Quote__c a : qlist){
        
        setid.add(a.id);
        }
        
       // list<SBQQ__Quote__c> insrtdQ = 
        list<SBQQ__QuoteLine__c> qq = [select id from SBQQ__QuoteLine__c where id=:setid];
        List<SBQQ__QuoteLine__c> newQlils = new List<SBQQ__QuoteLine__c>();   
          
       for(SBQQ__QuoteLine__c qq1 :qq ){
       
       if(qq1.id != null){
       SBQQ__QuoteLine__c QL = new SBQQ__QuoteLine__c();
     //  QL.SBQQ__Quote__c = setid;
       
       }
       }
       
     }  
                 
}

Apex Class:-

public class OpportunityHandler_cpq{

public integer enddate;

    Public void CpqQuoteInsert( list<opportunity> listopp){
        
        set<id> oppids = new set<id>();
      
        for(opportunity op :listopp ) {
      
            if(op.SBQQ__Renewal__c == True &&  op.SBQQ__RenewedContract__c != null ){

              oppids.add(op.id);
              system.debug('First op id'+op.id);
            }
        }
        system.debug('oppids::'+oppids);  
        List<Opportunity> oppls = [select id,Renewal_Contract_Term__c,SBQQ__RenewedContract__c, formulapreviousopp__c, SBQQ__RenewedContract__r.SBQQ__Opportunity__c from opportunity where id IN : oppids];
        system.debug('oppls::'+oppls);  
        Map<Id, Id> oldVSnewOpp = new Map<Id, Id>();
   
        for(Opportunity opp: oppls) {
            system.debug('opp.SBQQ__RenewedContract__c::'+opp.SBQQ__RenewedContract__c);
            system.debug('opp.SBQQ__RenewedContract__r.SBQQ__Opportunity__c::'+opp.SBQQ__RenewedContract__r.SBQQ__Opportunity__c);
            system.debug('opp.formulapreviousopp__::'+opp.formulapreviousopp__c);
            
            if(opp.SBQQ__RenewedContract__c != null && opp.SBQQ__RenewedContract__r.SBQQ__Opportunity__c != null)
                oldVSnewOpp.put(opp.SBQQ__RenewedContract__r.SBQQ__Opportunity__c, opp.Id);
     
        }
        system.debug('oldVSnewOpp:'+oldVSnewOpp);
        List<Opportunity> oldOppls = [select id, name,
                                                (Select ACV_Auto_Renew_Increment_Amount__c, ACV__c, Account_Name__c, Auto_Renew__c, Contract_End_Date__c, CreatedById, CreatedDate, Document_Template__c, 
Id, IsDeleted, LastActivityDate, LastModifiedById, LastModifiedDate, LastReferencedDate, LastViewedDate, Name, Number_of_Licences__c, 
Opp_Closed__c, Original_Quote_id__c, OwnerId, Payment__c, Primary_Contact_First_Name__c, Product_Family__c, SBQQ__Account__c, 
SBQQ__AdditionalDiscountAmount__c, SBQQ__AverageCustomerDiscount__c, SBQQ__AveragePartnerDiscount__c, SBQQ__BillingCity__c, SBQQ__BillingCountry__c, 
SBQQ__BillingFrequency__c, SBQQ__BillingName__c, SBQQ__BillingPostalCode__c, SBQQ__BillingState__c, SBQQ__BillingStreet__c, SBQQ__ContractingMethod__c,
 SBQQ__CustomerAmount__c, SBQQ__CustomerDiscount__c, SBQQ__DaysQuoteOpen__c, SBQQ__DefaultTemplate__c, SBQQ__DeliveryMethod__c, SBQQ__DistributorDiscount__c,
 SBQQ__Distributor__c, SBQQ__DocumentStatus__c, SBQQ__EmailTemplateId__c, SBQQ__EndDate__c, SBQQ__ExpirationDate__c, SBQQ__FirstSegmentTermEndDate__c,
 SBQQ__GenerateContractedPrice__c, SBQQ__Introduction__c, SBQQ__Key__c, SBQQ__LineItemCount__c, SBQQ__LineItemsGrouped__c, SBQQ__LineItemsPrinted__c, 
 SBQQ__ListAmount__c, SBQQ__MarkupRate__c, SBQQ__MasterContract__c, SBQQ__NetAmount__c, SBQQ__Notes__c, SBQQ__Opportunity2__c, SBQQ__Ordered__c, 
 SBQQ__OriginalQuote__c, SBQQ__PartnerDiscount__c, SBQQ__Partner__c, SBQQ__PaymentTerms__c, SBQQ__PriceBook__c, SBQQ__PricebookId__c,
 SBQQ__PrimaryContact__c, SBQQ__Primary__c, SBQQ__QuoteProcessId__c, SBQQ__QuoteTemplateId__c, SBQQ__RegularAmount__c, SBQQ__SalesRep__c, 
 SBQQ__ShippingCity__c, SBQQ__ShippingCountry__c, SBQQ__ShippingName__c, SBQQ__ShippingPostalCode__c, SBQQ__ShippingState__c, SBQQ__ShippingStreet__c, 
 SBQQ__Source__c, SBQQ__StartDate__c, SBQQ__Status__c, SBQQ__SubscriptionTerm__c, SBQQ__TargetCustomerAmount__c, SBQQ__TotalCustomerDiscountAmount__c,
 SBQQ__Type__c, SBQQ__WatermarkShown__c, SystemModstamp
                                                from SBQQ__Quotes2__r where SBQQ__Primary__c =  true) 
                                    from opportunity where id IN :oldVSnewOpp.keySet()];
         system.debug('oldOppls:'+oldOppls);
     
        List<SBQQ__Quote__c>  quotels = new  List<SBQQ__Quote__c>();
        for(Opportunity oldOpp :oldOppls) {
            if(oldOpp.SBQQ__Quotes2__r.size() >0 ) {
                system.debug('oldOpp.SBQQ__Quotes2__r::'+oldOpp.SBQQ__Quotes2__r);
                system.debug('oldVSnewOpp.containsKey(oldOpp.id)::'+oldVSnewOpp.containsKey(oldOpp.id));
                if(oldVSnewOpp.containsKey(oldOpp.id)) {
                    system.debug('here!!!!!!');
                    SBQQ__Quote__c  quote1 =  oldOpp.SBQQ__Quotes2__r[0].clone();
                    quote1.Original_Quote_id__c=oldOpp.SBQQ__Quotes2__r[0].id;
                    quote1.SBQQ__StartDate__c = system.today();
                    
                 //  Integer enddate= Integer.valueOf(String.valueOf(Math.roundToLong(oldOpp.SBQQ__Quotes2__r[0].SBQQ__SubscriptionTerm__c)));
                    
              //   quote1.SBQQ__EndDate__c =system.today().addmonths(enddate);

                    system.debug('quote1.Original_Quote_id__c::'+quote1.Original_Quote_id__c);
                    quote1.SBQQ__Opportunity2__c = oldVSnewOpp.get(oldOpp.id);
                    system.debug('quote1::'+quote1);
                    quotels.add(quote1);
                } 
         
            }
     
        }
        system.debug('quotels::'+quotels);
        
        if(quotels.size()>0) {
            insert quotels;
        }
        
       
        
         set<id> Quoteid = new set<id>();
         Map<id, id> oldQuoteVSNewQuoteIds = new Map<id, id>();
         for(SBQQ__Quote__c qt : quotels){
            if(qt.Original_Quote_id__c != null){
                oldQuoteVSNewQuoteIds.put(qt.Original_Quote_id__c, qt.id);
            }
        }
        system.debug('oldQuoteVSNewQuoteIds:::'+oldQuoteVSNewQuoteIds);
        
        list<SBQQ__Quote__c> oldquotelist = [Select ACV_Auto_Renew_Increment_Amount__c, ACV__c, Account_Name__c, Auto_Renew__c, Contract_End_Date__c, CreatedById, CreatedDate, Document_Template__c, 
Id, IsDeleted, LastActivityDate, LastModifiedById, LastModifiedDate, LastReferencedDate, LastViewedDate, Name, Number_of_Licences__c, 
Opp_Closed__c, Original_Quote_id__c, OwnerId, Payment__c, Primary_Contact_First_Name__c, Product_Family__c, SBQQ__Account__c, 
SBQQ__AdditionalDiscountAmount__c, SBQQ__AverageCustomerDiscount__c, SBQQ__AveragePartnerDiscount__c, SBQQ__BillingCity__c, SBQQ__BillingCountry__c, 
tartDate__c, SBQQ__Status__c, SBQQ__SubscriptionTerm__c, SBQQ__TargetCustomerAmount__c, SBQQ__TotalCustomerDiscountAmount__c,
 SBQQ__Type__c, SBQQ__WatermarkShown__c, SystemModstamp,
                                              (Select CreatedById, CreatedDate, Id, IsDeleted, LastModifiedById, LastModifiedDate, Name, Opportunity__c, Product_Description__c, Product_Family__c, 
SBQQ__AdditionalDiscountAmount__c, SBQQ__AdditionalDiscount__c, SBQQ__AdditionalQuantity__c, SBQQ__AllowAssetRefund__c, SBQQ__BatchQuantity__c, 
SBQQ__BillingFrequency__c, SBQQ__BillingType__c, SBQQ__BlockPrice__c, SBQQ__Bundle__c, SBQQ__BundledQuantity__c, SBQQ__Bundled__c, SBQQ__CarryoverLine__c,
 SBQQ__ChargeType__c, SBQQ__ComponentCost__c, SBQQ__ComponentDiscountedByPackage__c, SBQQ__ComponentListTotal__c, SBQQ__ComponentSubscriptionScope__c, 
 
 
 SBQQ__TotalDiscountRate__c, SBQQ__UnitCost__c, SBQQ__UnproratedNetPrice__c, SBQQ__UpgradedAsset__c, SBQQ__UpgradedQuantity__c, 
 SBQQ__UpgradedSubscription__c, SBQQ__UpliftAmount__c, SBQQ__Uplift__c, SBQQ__VolumeDiscount__c, SystemModstamp  FROM SBQQ__Lineitems__r) FROM SBQQ__Quote__c 
                                                   where id IN :oldQuoteVSNewQuoteIds.keySet()];
                                              
        List<SBQQ__QuoteLine__c> newQlils = new List<SBQQ__QuoteLine__c>();                                           
        for(SBQQ__Quote__c q1 :oldquotelist){
            for(SBQQ__QuoteLine__c qli : q1.SBQQ__Lineitems__r){
                SBQQ__QuoteLine__c newQli = qli.clone();
                newQli.SBQQ__Quote__c = oldQuoteVSNewQuoteIds.get(q1.id);
                newQli.SBQQ__Product__c= qli.SBQQ__Product__c;
                
                system.debug('qli:::'+qli.SBQQ__ProductFamily__c+ '::'+qli);
                system.debug('newQli:::'+newQli.SBQQ__ProductFamily__c+ '::'+newQli);

                newQlils.add(newQli);  
            } 
        }
        
        system.debug('newQlils::'+newQlils.size() + '::' +newQlils);
        if(newQlils.size() > 0) {
            insert newQlils;
        
        }
      /*  set<Id> newIds = new Set<Id>();
        for(SBQQ__QuoteLine__c qliNew1 :newQlils) {
            newIds.add(qliNew1.id);
        }
        
    
    List<SBQQ__QuoteLine__c>  updatedValue = [select id, name, SBQQ__CustomerPrice__c,SBQQ__ProductFamily__c  from SBQQ__QuoteLine__c where id IN :newIds];                                      
    system.debug('updatedValue::'+updatedValue);
    for(SBQQ__QuoteLine__c a1  :updatedValue) {
        system.debug('a1::'+a1);
    
    }
        */
        
        set<id> newQuoteid = new set<id>();
       
       for(SBQQ__Quote__c qt2 :quotels){
       newQuoteid.add(qt2.id);
       
       }
       
     //  list<string> updateTerm = new list<string>();
        
        list<SBQQ__Quote__c> newQuote =[select SBQQ__SubscriptionTerm__c, Renewal_Contract_Term_from_Renewal_opp__c, SBQQ__EndDate__c from  SBQQ__Quote__c where id=:newQuoteid];

        for(SBQQ__Quote__c updateEnddate: newQuote){
        
           Integer enddate= Integer.valueOf(String.valueOf(Math.roundToLong(updateEnddate.Renewal_Contract_Term_from_Renewal_opp__c)));

        
        updateEnddate.SBQQ__EndDate__c = system.today().addMonths(enddate);
        
        updateEnddate.SBQQ__SubscriptionTerm__c =updateEnddate.Renewal_Contract_Term_from_Renewal_opp__c;
        
        update updateEnddate;
        }

    } 
        
}
  • June 18, 2019
  • Like
  • 1
public class caseController {
    @AuraEnabled
    public static List<Organizational_Payment__c> getCaseList(Id recordId){
        
        Id orgId;
        List<Case> org = [select ContactId from Case WHERE Id=:recordId];
        for(Case c:org){
            orgId=c.ContactId;
        }
        
        List<Organizational_Payment__c> orgPaylst = [SELECT Id,Name,Receiving_organization__r.Name,Payment_Status__c,Payment_Date__c,Payable_Amount__c,  Bank_Account_Number__c,Concerning_Person_ID__c
                              FROM Organizational_Payment__c WHERE Concerning_Person_ID__c = :orgId and Payment_Date__c > LAST_N_MONTHS:6
                                                    ORDER BY Payment_date__c DESC];
        return orgPaylst;
    }
    
    @AuraEnabled
    public static void updateRecord(List<String> lstRecordId) {
        List<Organizational_Payment__c> lstOrgPayUpdate = new   List<Organizational_Payment__c>() ;
        for(Organizational_Payment__c orgPay :[SELECT Id,Payment_Status__c FROM  Organizational_Payment__c where id = : lstRecordId] ){
            orgPay.Payment_Status__c= 'Bounced payment';
            lstOrgPayUpdate.add(orgPay);
            System.debug('Success');
            
        }
       
        if(!lstOrgPayUpdate.isEmpty()){
            update lstOrgPayUpdate;
        }
       
    }
     @AuraEnabled
    public static List<Payment_Result__c> getPayResultList(Id recordId){
        
        Id perId;
        List<Case> per = [select ContactId from Case WHERE Id=:recordId];
        for(Case c:per){
            perId=c.ContactId;
        }
        
        List<Payment_Result__c> PayReslst = [SELECT Id,Name,Payment_Status__c,Payment_Date__c,Person_ID__c,Bank_Number__c,Total_Amount_Net__c
                              FROM Payment_Result__c WHERE Person_ID__c = :perId and Payment_Date__c > LAST_N_MONTHS:6
                                                    ORDER BY Payment_Date__c DESC];
        return PayReslst;
    }
     @AuraEnabled
    public static void updatePaymentRecord(List<String> lstPayId) {
        List<Payment_Result__c> lstPayResUpdate = new   List<Payment_Result__c>() ;
        for(Payment_Result__c Pay :[SELECT Id,Payment_Status__c FROM  Payment_Result__c where id = : lstPayId] ){
            Pay.Payment_Status__c= 'Bounced payment';
            lstPayResUpdate.add(Pay);
            System.debug('Success');
            
        }
       
        if(!lstPayResUpdate.isEmpty()){
            update lstPayResUpdate;
        }
       
    }
}

What i have implemented is this :-
@isTest
public class CaseAuraControllerTest {
    public static void setupData(){   
        Account acc = TestDataFactory.createAccount();
        Contact con = TestDataFactory.createContactWithBasicInfo(acc.Id);
        Case cas = TestDataFactory.createCase(con.Id);
  
    }

}

Can you help what to do after this?
                   
  • February 22, 2022
  • Like
  • 0
public without sharing class MaterialRequestManager {
public void validateOrderProducts(Map<Id, OrderItem> newItems, Map<Id,OrderItem> oldItems){
        List<OrderItem> orderItems = new List<OrderItem>();
        for(OrderItem oi : newItems.values()){
            if((oi.Quantity != oldItems.get(oi.Id).Quantity)
               || (oi.Product2Id != oldItems.get(oi.Id).Product2Id)){
                orderItems.add(oi);
            }
 public void validateOrderProducts(List<OrderItem> newLineItems){
        List<Id> orderIds = new List<Id>();
        Set<Id> productIds = new Set<Id>();
        for(OrderItem oi : newLineItems){
            orderIds.add(oi.OrderId);
            productIds.add(oi.Product2Id);
        }
        
        List<Id> serviceFormIds = new List<Id>();
        Map<Id, Id> orderIdVsServiceFormId = new Map<Id, Id>();
        for(Order od: [Select Id, Service_Form__c from Order Where Id IN: orderIds And Service_Form__c != null]){
            serviceFormIds.add(od.Service_Form__c);
            orderIdVsServiceFormId.put(od.Id, od.Service_Form__c);
        }
        
        
        Map<Id, Map<Id, SR_Products__c>> srFormIdVsSRProductsMap = new Map<Id, Map<Id,SR_Products__c>>();
        for(SR_Products__c srp : [Select Id, Service_Form__c, Product__c, Quantify__c From SR_Products__c Where Service_Form__c IN: serviceFormIds And Product__c IN: productIds]){
            if(srFormIdVsSRProductsMap.containsKey(srp.Service_Form__c)){
                srFormIdVsSRProductsMap.get(srp.Service_Form__c).put(srp.Product__c, srp);
            }else{
                srFormIdVsSRProductsMap.put(srp.Service_Form__c, new Map<Id, SR_Products__c>{srp.Product__c => srp});
            }
        }
        
        Boolean isProductPresent = false;
        if(!orderIdVsServiceFormId.isEmpty()){
            for(OrderItem oi : newLineItems){
                if(orderIdVsServiceFormId.containsKey(oi.OrderId)){
                    Id serviceFormId = orderIdVsServiceFormId.get(oi.OrderId);
                    if(srFormIdVsSRProductsMap.containsKey(serviceFormId)){
                        Map<Id, SR_Products__c> idVsSRProduct = srFormIdVsSRProductsMap.get(serviceFormId);
                        if(idVsSRProduct.containsKey(oi.Product2Id)){
                            isProductPresent = true;
                        }
                        if(idVsSRProduct.containsKey(oi.Product2Id)){
                            Double srQty = idVsSRProduct.get(oi.Product2Id).Quantify__c;
                            if(oi.Quantity > srQty){
                                oi.addError(System.Label.Validate_OrderItem_Quantity_From_SR_Products +' ' + srQty);
                            }
                        }
                    }
                    
                    if(isProductPresent == false){
                        oi.addError(System.Label.Validate_OrderItem_Product_From_SR_Products);
                    }
                }
            }
        }      
    }

        }
        if(orderItems.size() > 0)
            validateOrderProducts(orderItems);
    }
   } 
  • May 11, 2021
  • Like
  • 0
Hi everyone,

Actually we have one task,we need to Upload Document data which where in salesforce we need to get that data in other application using API"s.If any one know how to send that data please respond.

Thanks inadvance,
RajuBalaji.
Hi,
I cannot open a flow that works fine in production. I tried in 3 different sandboxes. 
Did it happen to one of you?
Could you solve it?
I try to copy the flow and deploy the copy in the sandbox but i got the same error message when I try to open it.
Thanks a lot
Error message
trigger mobileUpdate on APEX_TEST__c (before insert, after insert, after update, before update) {
    List<APEX_TEST__c> mobile = new List<APEX_TEST__c>();
    
    for(APEX_TEST__c m : mobile){
        m.mobile__c = '9413836278';
    }
    insert mobile;
}

I want to update mobile filed for all record. any help??
Hello Guys,

I want to check whether the records is already exist if yes then update it with new data if not insert new record into custom field.


currentRecord = [SELECT ID,Base_Yearly_Package__c FROM  Offers_Appraisals__c WHERE Id = :'a12M000000MMF6k'];

    List<Monthly_Salary__c> SalList = new List<Monthly_Salary__c>();
    SalList=[SELECT ID,Name,From_Date__c FROM Monthly_Salary__c WHERE Resource__c=:currentRecord.Resource__c];
    
                Monthly_Salary__c new_records2=new Monthly_Salary__c();
                                new_records2.Base_Yearly_Package__c=currentRecord.Base_Yearly_Package__c;
                                new_records2.Resource__c=currentRecord.Resource__c;

    for(Monthly_Salary__c s:SalList){
                                        if(s.Name!=new_records3.Name) {
                                            insert new_records3;
                                            break;
                                        } else {update new_records3;}
                           }


Above code working.Not even inserting nor updating the records.
Please help me.
where i am wrong?
Thank you
  • April 10, 2020
  • Like
  • 0
Write a trigger on Opportunity LineItem , when Line Item is deletes, delete an opportunity as well with Map.?
Iam getting this error :-


System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.
Stack Trace: External entry point

@isTest(seealldata = true)
public class QuoteTrigger_PayTerms_GenerateDoc_Test{
             
         Static testMethod Void testMethod2(){
           
             Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             Contact con = new contact();
             con.lastname='test contact';
             con.LeadSource = 'Inbound';
             con.Contact_Status__c='Open';
             con.accountid=acc.id;
             insert con;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             opp.Contact_Name__c=con.id;
             insert opp;  
             
             OpportunityContactRole ocr = new OpportunityContactRole();
                ocr.ContactId = con.Id;
                ocr.OpportunityId = opp.Id;
                ocr.IsPrimary = TRUE;
                ocr.Role = 'Decision Maker';
                insert ocr;
             
             SBQQ__Quote__c oldquote2 = new SBQQ__Quote__c();
             oldquote2.SBQQ__Primary__c = true;
             oldquote2.SBQQ__Opportunity2__c = opp.id;
             oldquote2.SBQQ__StartDate__c = system.today();
             oldquote2.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote2.SBQQ__SubscriptionTerm__c=1;
             oldquote2.Status_Of_Approval__c='Pending';
             oldquote2.Document_Template__c= 'Auto Renew 3';
             oldquote2.SBQQ__PaymentTerms__c= 'monthly';
             oldquote2.SBQQ__BillingCountry__c ='United States';
             oldquote2.Long_Form__c=false;
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'No';
             insert oldquote2;
   //--------------------------------------------------------------------------Annual Starts here----------------
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';      
             update oldquote2;   
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';      
             update oldquote2;   
         

         }
             
               
             Static testMethod Void testMethod3(){

//----------------------------------------------Standard saas------------------------------------------------
           

             Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             Contact con = new contact();
             con.lastname='test contact';
             con.LeadSource = 'Inbound';
             con.Contact_Status__c='Open';
             con.accountid=acc.id;
             insert con;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             opp.Contact_Name__c=con.id;

             insert opp;  
             
              OpportunityContactRole ocr = new OpportunityContactRole();
              ocr.ContactId = con.Id;
              ocr.OpportunityId = opp.Id;
              ocr.IsPrimary = TRUE;
              ocr.Role = 'Decision Maker';
              insert ocr;
             
             SBQQ__Quote__c oldquote2 = new SBQQ__Quote__c();
             oldquote2.SBQQ__Primary__c = true;
             oldquote2.SBQQ__Opportunity2__c = opp.id;
             oldquote2.SBQQ__StartDate__c = system.today();
             oldquote2.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote2.SBQQ__SubscriptionTerm__c=1;
             oldquote2.Status_Of_Approval__c='Pending';
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'monthly';
             oldquote2.SBQQ__BillingCountry__c ='United States';
             oldquote2.Long_Form__c=false;
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'No';
             insert oldquote2;

             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';      
             update oldquote2;   
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';      
             update oldquote2;   
         

         }
            
    
        
    }
  • March 31, 2020
  • Like
  • 0
Hey guys, I've got a very simple trigger:
 
trigger TF on Account (before update, before insert) {
    for (Account a: trigger.New) {
        a.TestField__c = 'test';
    }

}

I wrote a test class for it:
 
@isTest
public class TFTest {
    @isTest static void testName() {
       Account cat = new Account();
        cat.Name = 'cat';
        insert cat;
        System.assertEquals('test', cat.TestField__c);
       }

}
When I run the test, I get an error:
 
Error Message	System.AssertException: Assertion Failed: Expected: test, Actual: null
Stack Trace	Class.TFTest.testName: line 7, column 1

I have two questions:
1) What am I doing wrong?
2) How come my trigger does not need to be tested and works already? I added an Account record already and the field gets populated.

Have a nice day


 
Test class:-

@isTest
public class QuoteTrigger_PayTerms_GenerateDoc_Test{
         Static testMethod Void testMetho
d2(){
           Test.starttest();

             Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             insert opp;  
             
             //  Quote Templates-------------------------------------------------------
             
             SBQQ__QuoteTemplate__c qt10 = new SBQQ__QuoteTemplate__c();

               qt10.Name='Auto Renew without Discount';
               qt10.SBQQ__Default__c=false;
               qt10.SBQQ__PageWidth__c= 8.5;
               qt10.SBQQ__TopMargin__c =0.50;
               qt10.SBQQ__LeftMargin__c = 0.50;
               qt10.SBQQ__PageHeight__c  =11.00;
               qt10.SBQQ__BottomMargin__c = 0.50;   
               qt10.SBQQ__RightMargin__c = 0.50;
               qt10.SBQQ__FontFamily__c = 'Helvetica';
               qt10.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt10.SBQQ__BorderColor__c = '000000';
               qt10.SBQQ__FontSize__c = 9.0;
               insert qt10;
            
             SBQQ__QuoteTemplate__c qt9 = new SBQQ__QuoteTemplate__c();

               qt9.Name='Basic Template without Discount';
               qt9.SBQQ__Default__c=false;
               qt9.SBQQ__PageWidth__c= 8.5;
               qt9.SBQQ__TopMargin__c =0.50;
               qt9.SBQQ__LeftMargin__c = 0.50;
               qt9.SBQQ__PageHeight__c  =11.00;
               qt9.SBQQ__BottomMargin__c = 0.50;   
               qt9.SBQQ__RightMargin__c = 0.50;
               qt9.SBQQ__FontFamily__c = 'Helvetica';
               qt9.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt9.SBQQ__BorderColor__c = '000000';
               qt9.SBQQ__FontSize__c = 9.0;
               insert qt9;
            
             SBQQ__QuoteTemplate__c qt8 = new SBQQ__QuoteTemplate__c();

               qt8.Name='Auto Renew with 3% Annual Increment Without Discount';
               qt8.SBQQ__Default__c=false;
               qt8.SBQQ__PageWidth__c= 8.5;
               qt8.SBQQ__TopMargin__c =0.50;
               qt8.SBQQ__LeftMargin__c = 0.50;
               qt8.SBQQ__PageHeight__c  =11.00;
               qt8.SBQQ__BottomMargin__c = 0.50;   
               qt8.SBQQ__RightMargin__c = 0.50;
               qt8.SBQQ__FontFamily__c = 'Helvetica';
               qt8.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt8.SBQQ__BorderColor__c = '000000';
               qt8.SBQQ__FontSize__c = 9.0;
               insert qt8;
       
             SBQQ__QuoteTemplate__c qt7 = new SBQQ__QuoteTemplate__c();

               qt7.Name='Auto Renew with 3% Annual Increment with Autopay';
               qt7.SBQQ__Default__c=false;
               qt7.SBQQ__PageWidth__c= 8.5;
               qt7.SBQQ__TopMargin__c =0.50;
               qt7.SBQQ__LeftMargin__c = 0.50;
               qt7.SBQQ__PageHeight__c  =11.00;
               qt7.SBQQ__BottomMargin__c = 0.50;   
               qt7.SBQQ__RightMargin__c = 0.50;
               qt7.SBQQ__FontFamily__c = 'Helvetica';
               qt7.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt7.SBQQ__BorderColor__c = '000000';
               qt7.SBQQ__FontSize__c = 9.0;
               insert qt7;
            
            SBQQ__QuoteTemplate__c qt6 = new SBQQ__QuoteTemplate__c();

               qt6.Name='Auto Renew with 3% Annual Increment';
               qt6.SBQQ__Default__c=false;
               qt6.SBQQ__PageWidth__c= 8.5;
               qt6.SBQQ__TopMargin__c =0.50;
               qt6.SBQQ__LeftMargin__c = 0.50;
               qt6.SBQQ__PageHeight__c  =11.00;
               qt6.SBQQ__BottomMargin__c = 0.50;   
               qt6.SBQQ__RightMargin__c = 0.50;
               qt6.SBQQ__FontFamily__c = 'Helvetica';
               qt6.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt6.SBQQ__BorderColor__c = '000000';
               qt6.SBQQ__FontSize__c = 9.0;
               insert qt6;
            
             SBQQ__QuoteTemplate__c qt5 = new SBQQ__QuoteTemplate__c();

               qt5.Name='Auto Renew';
               qt5.SBQQ__Default__c=false;
               qt5.SBQQ__PageWidth__c= 8.5;
               qt5.SBQQ__TopMargin__c =0.50;
               qt5.SBQQ__LeftMargin__c = 0.50;
               qt5.SBQQ__PageHeight__c  =11.00;
               qt5.SBQQ__BottomMargin__c = 0.50;   
               qt5.SBQQ__RightMargin__c = 0.50;
               qt5.SBQQ__FontFamily__c = 'Helvetica';
               qt5.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt5.SBQQ__BorderColor__c = '000000';
               qt5.SBQQ__FontSize__c = 9.0;
               insert qt5;
               
             SBQQ__QuoteTemplate__c qt4 = new SBQQ__QuoteTemplate__c();

               qt4.Name='Basic Template with Auto Pay';
               qt4.SBQQ__Default__c=false;
               qt4.SBQQ__PageWidth__c= 8.5;
               qt4.SBQQ__TopMargin__c =0.50;
               qt4.SBQQ__LeftMargin__c = 0.50;
               qt4.SBQQ__PageHeight__c  =11.00;
               qt4.SBQQ__BottomMargin__c = 0.50;   
               qt4.SBQQ__RightMargin__c = 0.50;
               qt4.SBQQ__FontFamily__c = 'Helvetica';
               qt4.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt4.SBQQ__BorderColor__c = '000000';
               qt4.SBQQ__FontSize__c = 9.0;
               insert qt4;
               
             SBQQ__QuoteTemplate__c qt3 = new SBQQ__QuoteTemplate__c();

            qt3.Name='Basic Template';
               qt3.SBQQ__Default__c=false;
               qt3.SBQQ__PageWidth__c= 8.5;
               qt3.SBQQ__TopMargin__c =0.50;
               qt3.SBQQ__LeftMargin__c = 0.50;
               qt3.SBQQ__PageHeight__c  =11.00;
               qt3.SBQQ__BottomMargin__c = 0.50;   
               qt3.SBQQ__RightMargin__c = 0.50;
               qt3.SBQQ__FontFamily__c = 'Helvetica';
               qt3.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt3.SBQQ__BorderColor__c = '000000';
               qt3.SBQQ__FontSize__c = 9.0;
               insert qt3;
               
               qt3.SBQQ__Default__c=true;
               update qt3;
            
             SBQQ__Quote__c oldquote = new SBQQ__Quote__c();
             oldquote.SBQQ__Primary__c = true;
             oldquote.SBQQ__Opportunity2__c = opp.id;
             oldquote.SBQQ__StartDate__c = system.today();
             oldquote.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote.SBQQ__SubscriptionTerm__c=1;
             
             /*
             Document documentObj = new Document();
             documentObj.Body = Blob.valueOf('Some Document Text');
             documentObj.ContentType = 'application/pdf';
             documentObj.DeveloperName = 'my_document';
             documentObj.IsPublic = true;
             documentObj.Name = 'Recurring Payment Agreement Form';
             documentObj.FolderId = [select id from folder limit 1].id;
             insert documentObj; 
             */
             oldquote.Status_Of_Approval__c='Pending';
             oldquote.Document_Template__c= 'Auto Renew';

             oldquote.SBQQ__PaymentTerms__c= 'monthly';
             oldquote.SBQQ__BillingCountry__c ='United States';
             insert oldquote;
                
             oldquote.Document_Template__c= 'Auto Renew 3';
             oldquote.SBQQ__PaymentTerms__c= 'monthly';
             oldquote.SBQQ__BillingCountry__c ='Japan';

             update oldquote;
             
              SBQQ__QuoteTemplate__c qt11 = new SBQQ__QuoteTemplate__c();
               
             oldquote.Document_Template__c= 'Basic Template';
             oldquote.SBQQ__PaymentTerms__c= 'monthly';
             update oldquote;
                
            SBQQ__RelatedContent__c att = new SBQQ__RelatedContent__c();
            att.Name ='Recurring Payment Agreement Form_2.pdf';
          //att.Owner=Userinfo.getuserid();
          //att.SBQQ__TemplateSection__c
            att.SBQQ__Required__c=true;
          //att.SBQQ__QuoteTemplate__c
            att.SBQQ__Quote__c =oldquote.id;
           //att.SBQQ__Product__c
            att.SBQQ__Opportunity__c = opp.id;
            att.SBQQ__ExternalId__c='00P5400000254mHEAQ';
          //att.SBQQ__DocumentName__c='00P5400000254mHEAQ';
          //att.SBQQ__DisplayOrder__c
                
            insert att;

            SBQQ__Quote__c oldquote2 = new SBQQ__Quote__c();
            oldquote2.SBQQ__Primary__c = true;
            oldquote2.SBQQ__Opportunity2__c = opp.id;
            oldquote2.SBQQ__StartDate__c = system.today();
            oldquote2.SBQQ__EndDate__c= system.today().addmonths(3);
            oldquote2.SBQQ__SubscriptionTerm__c=1;
        
            oldquote2.Status_Of_Approval__c='Pending';
            oldquote2.Document_Template__c= 'Auto Renew';

            oldquote2.SBQQ__PaymentTerms__c= 'monthly';
            
            insert oldquote2;

         }
   
    }

 
  • August 28, 2019
  • Like
  • 0
  • July 08, 2019
  • Like
  • 0