• Rahul
  • NEWBIE
  • 305 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 77
    Questions
  • 77
    Replies
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?
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
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 Form'];
        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')   )
                {
                    for(SBQQ__QuoteTemplate__c qq2 : qt2)
                    {
                        for(SBQQ__QuoteTemplate__c qq1 :qt1)
                        {
                            for(SBQQ__QuoteTemplate__c qq3 :qt3)
                            {
                                for(SBQQ__QuoteTemplate__c qq4 :qt4)
                                {
                                    for(SBQQ__QuoteTemplate__c qq5 :qt5)
                                    {
                                        for(SBQQ__QuoteTemplate__c qq6 :qt6)
                                        {
                                    qq2.SBQQ__Default__c = true;
                                    qq1.SBQQ__Default__c = false;
                                    qq3.SBQQ__Default__c = false;
                                    qq4.SBQQ__Default__c = false;
                                    qq5.SBQQ__Default__c = false;
                                    qq6.SBQQ__Default__c = false;
                                    list1.add(qq1);
                                    list1.add(qq2);
                                    list1.add(qq3);
                                    list1.add(qq4);
                                    list1.add(qq5);
                                    list1.add(qq6);
                                    }
                                    }
                               }
                            }
                        }
                    }
                }
                if(ss.Document_Template__c=='Auto Renew' && ( ss.SBQQ__PaymentTerms__c=='Annual' ||  ss.SBQQ__PaymentTerms__c=='Semi-annual' || ss.SBQQ__PaymentTerms__c=='Upfront') )
                {
                    for(SBQQ__QuoteTemplate__c qq2 : qt2)
                    {
                        for(SBQQ__QuoteTemplate__c qq1 :qt1)
                        {
                            for(SBQQ__QuoteTemplate__c qq3 :qt3)
                            {
                                for(SBQQ__QuoteTemplate__c qq4 :qt4)
                                {
                                    for(SBQQ__QuoteTemplate__c qq5 :qt5)
                                    {
                                        for(SBQQ__QuoteTemplate__c qq6 :qt6)
                                        {
                                    qq2.SBQQ__Default__c = False;
                                    qq1.SBQQ__Default__c = True;
                                    qq3.SBQQ__Default__c = False;
                                    qq4.SBQQ__Default__c = False;
                                    qq5.SBQQ__Default__c = false;
                                    qq6.SBQQ__Default__c = false;
                                    list1.add(qq1);
                                    list1.add(qq2);
                                    list1.add(qq3);
                                    list1.add(qq4);
                                    list1.add(qq5);
                                    list1.add(qq6);
                                    }
                                    }
                               }
                            }
                        }
                    }
                }
                if(ss.Document_Template__c=='Auto Renew 3' && ( ss.SBQQ__PaymentTerms__c=='Quarterly' ||  ss.SBQQ__PaymentTerms__c=='Monthly') )
                {
                    for(SBQQ__QuoteTemplate__c qq2 : qt2)
                    {
                        for(SBQQ__QuoteTemplate__c qq1 :qt1)
                        {
                            for(SBQQ__QuoteTemplate__c qq3 :qt3)
                            {
                                for(SBQQ__QuoteTemplate__c qq4 :qt4)
                                {
                                    for(SBQQ__QuoteTemplate__c qq5 :qt5)
                                    {
                                        for(SBQQ__QuoteTemplate__c qq6 :qt6)
                                        {
                                    qq2.SBQQ__Default__c = False;
                                    qq1.SBQQ__Default__c = False;
                                    qq3.SBQQ__Default__c = False;
                                    qq4.SBQQ__Default__c = False;
                                    qq5.SBQQ__Default__c = True;
                                    qq6.SBQQ__Default__c = false;
                                    list1.add(qq1);
                                    list1.add(qq2);
                                    list1.add(qq3);
                                    list1.add(qq4);
                                    list1.add(qq5);
                                    list1.add(qq6);
                                    }
                                    }
                               }
                            }
                        }
                    update list1;
                    }
                }

 
  • July 07, 2019
  • Like
  • 0
public class OpportunityHandler_cpq{

public integer enddate=0;

public integer startdate=0;


    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;
                    
                    integer startdate = Integer.valueOf(String.valueOf(Math.roundToLong(oldOpp.SBQQ__Quotes2__r[0].SBQQ__SubscriptionTerm__c)));
                    
                    quote1.SBQQ__StartDate__c = oldOpp.SBQQ__Quotes2__r[0].SBQQ__StartDate__c.addmonths(startdate);
                    quote1.SBQQ__EndDate__c = (quote1.SBQQ__StartDate__c).addmonths(startdate);
                    
                 //  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, 
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,
                                              (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__ComponentTotal__c, SBQQ__ComponentUpliftedByPackage__c, SBQQ__ComponentVisibility__c, SBQQ__CompoundDiscountRate__c, SBQQ__ConfigurationRequired__c,
 SBQQ__ContractedPrice__c, SBQQ__CostEditable__c, SBQQ__Cost__c, SBQQ__CustomerPrice__c, SBQQ__CustomerTotal__c, SBQQ__DefaultSubscriptionTerm__c,
 SBQQ__Description__c, SBQQ__Dimension__c, SBQQ__DiscountScheduleType__c, SBQQ__DiscountSchedule__c, SBQQ__DiscountTier__c, SBQQ__Discount__c, 
 SBQQ__DistributorDiscount__c, SBQQ__DynamicOptionId__c, SBQQ__EffectiveEndDate__c, SBQQ__EffectiveQuantity__c, SBQQ__EffectiveStartDate__c,
 SBQQ__EndDate__c, SBQQ__Existing__c, SBQQ__Favorite__c, SBQQ__GenerateContractedPrice__c, SBQQ__GrossProfit__c, SBQQ__Group__c, SBQQ__Hidden__c,
 SBQQ__Incomplete__c, SBQQ__ListPrice__c, SBQQ__ListTotal__c, SBQQ__MarkupAmount__c, SBQQ__MarkupRate__c, SBQQ__Markup__c, SBQQ__MaximumPrice__c,
 SBQQ__MinimumPrice__c, SBQQ__NetPrice__c, SBQQ__NetTotal__c, SBQQ__NonDiscountable__c, SBQQ__NonPartnerDiscountable__c, SBQQ__Number__c,
 SBQQ__OptionDiscountAmount__c, SBQQ__OptionDiscount__c, SBQQ__OptionLevel__c, SBQQ__OptionType__c, SBQQ__Optional__c, SBQQ__OriginalPrice__c,
 SBQQ__OriginalUnitCost__c, SBQQ__PackageCost__c, SBQQ__PackageListTotal__c, SBQQ__PackageProductCode__c, SBQQ__PackageProductDescription__c, 
 SBQQ__PackageTotal__c, SBQQ__PartnerDiscount__c, SBQQ__PartnerPrice__c, SBQQ__PartnerTotal__c, SBQQ__PreviousSegmentPrice__c, 
 SBQQ__PreviousSegmentUplift__c, SBQQ__PriceEditable__c, SBQQ__PricingMethodEditable__c, SBQQ__PricingMethod__c, 
 SBQQ__PriorQuantity__c, SBQQ__ProductCode__c, SBQQ__ProductFamily__c, SBQQ__ProductName__c, SBQQ__ProductOption__c, SBQQ__Product__c, 
 SBQQ__ProrateMultiplier__c, SBQQ__ProratedListPrice__c, SBQQ__ProratedPrice__c, SBQQ__Quantity__c, SBQQ__Quote__c, SBQQ__RegularPrice__c, 
 SBQQ__RegularTotal__c, SBQQ__Renewal__c, SBQQ__RenewedAsset__c, SBQQ__RenewedSubscription__c, SBQQ__RequiredBy__c, SBQQ__SegmentIndex__c, 
 SBQQ__SegmentKey__c, SBQQ__SegmentLabel__c, SBQQ__Source__c, SBQQ__SpecialPriceDescription__c, SBQQ__SpecialPriceType__c, SBQQ__SpecialPrice__c,
 SBQQ__StartDate__c, SBQQ__SubscribedAssetIds__c, SBQQ__SubscriptionBase__c, SBQQ__SubscriptionCategory__c, SBQQ__SubscriptionPercent__c, 
 SBQQ__SubscriptionPricing__c, SBQQ__SubscriptionScope__c, SBQQ__SubscriptionTargetPrice__c, SBQQ__SubscriptionTerm__c,
 SBQQ__TaxCode__c, SBQQ__Taxable__c, SBQQ__TermDiscountSchedule__c, SBQQ__TermDiscountTier__c, SBQQ__TermDiscount__c, SBQQ__TotalDiscountAmount__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__Primary__c   from  SBQQ__Quote__c where id=:newQuoteid];
       
        for(SBQQ__Quote__c  newprimary: newQuote){
        
        newprimary.SBQQ__Primary__c  = true;
        
        update newprimary;
       
       }

    } 
        
}
  • June 19, 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
List<Opportunity> oldOppls = [select id, name,
                                                (select id,Product_Family__c,SBQQ__SubscriptionTerm__c, 
                                                SBQQ__Primary__c
                                                from SBQQ__Quotes2__r where SBQQ__Primary__c =  true) 
                                    from opportunity where id IN :oldVSnewOpp.keySet()];
  • June 14, 2019
  • Like
  • 0

trigger AccountTrigger on Account (after insert, after update) {

set<string> setstring = new set<string>();

list<Account> listAccount = new list<Account>();

Pincode__mdt[]   pin= [select city__C, state__C from Pincode__mdt ];


for(Account a : trigger.new){
if(Trigger.IsInsert && Trigger.isAfter ){
if(a.Pincode__C != null){
setstring.add(a.Pincode__C);

system.debug('value in pin' + Pin);
system.debug('This is insert Trigger');

}
}
}

Pincode__mdt[]   pin2= [select city__C, state__C,pincode__C from Pincode__mdt where pincode__C =:setstring ];

system.debug('this is pin2'+ pin2);

for(Pincode__mdt pt : pin2){

for(Account ac : trigger.new){
if(ac.pincode__C == pt.pincode__C){

ac.Billing_City__c   = pt.city__C;

ac.Billing_State__c    = pt.state__C;

listAccount.add(ac);

system.debug('Values in ListAccount'+listAccount);
}


}
}
insert listAccount;

if(Trigger.isUpdate){

system.debug('This is Update');

}

}
 
  • June 03, 2019
  • Like
  • 0
VF Page :-

<apex:page standardController="Account" extensions="acccontroller">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection id="theform" columns="1">
 <apex:actionRegion >
 <apex:outputLabel >hvb :</apex:outputLabel>
       <apex:inputField value="{!acc.Rating}">
       <apex:actionSupport event="onchange" action="{!null}" rerender="myform"/>  
       </apex:inputField>
   </apex:actionRegion>
  <apex:outputPanel id="myform" > 
       <apex:outputPanel rendered="{!If(acc.Rating == 'Warm',true,false)}">
       <apex:outputLabel >hvb :</apex:outputLabel>
     <apex:inputField value="{!acc.phone}"/>
       </apex:outputPanel> 
   </apex:outputPanel> 
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>  
</apex:page>

Apex Class :-

public class acccontroller {
public account acc{get;set;}
    public acccontroller(ApexPages.StandardController controller) {

    }
}
  • May 30, 2019
  • Like
  • 0
Value(text(Total_tenure__C)/ value(text(Advance_Emi__C)) 

Result should be 12/4  displayed on Scheme field but its display as 3 after calculation. I dont want it to be calculated.
  • May 30, 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
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
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

trigger AccountTrigger on Account (after insert, after update) {

set<string> setstring = new set<string>();

list<Account> listAccount = new list<Account>();

Pincode__mdt[]   pin= [select city__C, state__C from Pincode__mdt ];


for(Account a : trigger.new){
if(Trigger.IsInsert && Trigger.isAfter ){
if(a.Pincode__C != null){
setstring.add(a.Pincode__C);

system.debug('value in pin' + Pin);
system.debug('This is insert Trigger');

}
}
}

Pincode__mdt[]   pin2= [select city__C, state__C,pincode__C from Pincode__mdt where pincode__C =:setstring ];

system.debug('this is pin2'+ pin2);

for(Pincode__mdt pt : pin2){

for(Account ac : trigger.new){
if(ac.pincode__C == pt.pincode__C){

ac.Billing_City__c   = pt.city__C;

ac.Billing_State__c    = pt.state__C;

listAccount.add(ac);

system.debug('Values in ListAccount'+listAccount);
}


}
}
insert listAccount;

if(Trigger.isUpdate){

system.debug('This is Update');

}

}
 
  • June 03, 2019
  • Like
  • 0
VF Page :-

<apex:page standardController="Account" extensions="acccontroller">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection id="theform" columns="1">
 <apex:actionRegion >
 <apex:outputLabel >hvb :</apex:outputLabel>
       <apex:inputField value="{!acc.Rating}">
       <apex:actionSupport event="onchange" action="{!null}" rerender="myform"/>  
       </apex:inputField>
   </apex:actionRegion>
  <apex:outputPanel id="myform" > 
       <apex:outputPanel rendered="{!If(acc.Rating == 'Warm',true,false)}">
       <apex:outputLabel >hvb :</apex:outputLabel>
     <apex:inputField value="{!acc.phone}"/>
       </apex:outputPanel> 
   </apex:outputPanel> 
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>  
</apex:page>

Apex Class :-

public class acccontroller {
public account acc{get;set;}
    public acccontroller(ApexPages.StandardController controller) {

    }
}
  • May 30, 2019
  • Like
  • 0
Value(text(Total_tenure__C)/ value(text(Advance_Emi__C)) 

Result should be 12/4  displayed on Scheme field but its display as 3 after calculation. I dont want it to be calculated.
  • May 30, 2019
  • Like
  • 0
Test CLass :-

@istest
public class bucket1controllertest{

public static testmethod void metd1(){
Bucket1__c b = new Bucket1__c();
b.Aadhar_Number__c ='jcshusd66';
b.CBIL__c ='77567';
b.PAN_Number__c='hshshbhj678';
//b.Start_Date_and_TimeStamp__c =Now();
b.Accomodation_Type__c='own' ;
b.Already_have_a_Loan__c ='No';
b.Borrower_Name__c='jkcndjd';
b.Company_Name__c = 'abc';
b.Company_Type__c = 'jsdnjd';
b.Credit_card_holder__c ='Yes';
//b.Date_of_birth__c  = '1/08/1995';
b.Eligibility_Check__c = true;
b.Email__c='testr@gmail.com';
b.Full_Residential_Address__c = 'hdyh khskfh khsd kuhsukds hkdsdb';
b.Hoapital_clinic__c ='hbdc';
b.Last_Month_Salary__c = 67557;
b.Loan_Amount_Eligible__c = 600000;
b.Loan_Amount__c = 900000;
b.Obligation_Amount__c = 1000000;
b.Phone_number__c = '678767876';
b.Scheme__c ='hjgjdgsjdh';
b.Treatment__c ='jdnd';
insert b;
}
}

Class:-

public class Bucket1controller {

public Bucket1__c buck1 = new Bucket1__c();

public Bucket1__c getbuck1(){


return buck1;
}

    public Bucket1controller(ApexPages.StandardController controller) {

    }

public pageReference Bucket1form2(){


return Page.Bucket1form2page;
}

public PageReference Saveall(){
Bucket1__c b = new Bucket1__c();
b.Aadhar_Number__c =buck1.Aadhar_Number__c;
b.CBIL__c =buck1.CBIL__c;

b.PAN_Number__c=buck1.PAN_Number__c;
b.Start_Date_and_TimeStamp__c = buck1.Start_Date_and_TimeStamp__c;
b.Accomodation_Type__c= buck1.Accomodation_Type__c;
b.Already_have_a_Loan__c =buck1.Already_have_a_Loan__c;
b.Borrower_Name__c=buck1.Borrower_Name__c;
b.Company_Name__c = buck1.Company_Name__c;
b.Company_Type__c = buck1.Company_Type__c;
b.Credit_card_holder__c = buck1.Credit_card_holder__c;
b.Date_of_birth__c  = buck1.Date_of_birth__c;

b.Eligibility_Check__c = buck1.Eligibility_Check__c;
b.Email__c=buck1.Email__c;
b.Full_Residential_Address__c = buck1.Full_Residential_Address__c;

b.Hoapital_clinic__c = buck1.Hoapital_clinic__c;

b.Last_Month_Salary__c = buck1.Last_Month_Salary__c;

b.Loan_Amount_Eligible__c = buck1.Loan_Amount_Eligible__c;
b.Loan_Amount__c = buck1.Loan_Amount__c;

b.Obligation_Amount__c = buck1.Obligation_Amount__c;
b.Phone_number__c = buck1.Phone_number__c;
b.Scheme__c =buck1.Scheme__c;
b.Treatment__c =buck1.Treatment__c;

insert b;

return Page.savedsuccessfully;
}

}
  • May 30, 2019
  • Like
  • 0
<apex:page standardController="Account">
<apex:form id="myform">
<apex:pageBlock >
<apex:pageBlockSection id="theform" columns="1">


<apex:inputField value="{!Account.Rating}">
    <apex:actionSupport event="onchange" reRender="myform" />

</apex:inputfield>

<apex:inputField id="myform" value="{!Account.phone}" rendered="{!Account.Rating == 'warm'}"  ></apex:inputField>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>
  
</apex:page>
  • May 29, 2019
  • Like
  • 0
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, bucket1associatetobucket2: execution of AfterInsert caused by: System.TypeException: Invalid id value for this SObject type: a14p000000275tEAAQ Trigger.bucket1associatetobucket2: line 35, column 1: []

Bucket1__c is parent and Bucket_2__c is child.Iam trying to create buckel1 record and when borower_name__c is null , then create bucket_2__C record and associate it with parent which is bucket1__c.
​​​​​​​Please help to solve this error.

Please find my code below :-

trigger bucket1associatetobucket2 on Bucket1__c (after insert) {
  map<string,id> conEmailVsId = new map<string,id>();
List<Bucket_2__c> newbuck2 = new list<Bucket_2__c>();
    if(Trigger.isAfter && Trigger.isInsert) {
            for(Bucket1__c a1:trigger.new){
if(a1.Borrower_Name__c == null){

Bucket_2__c bb = new Bucket_2__c();
bb.id=a1.id;
bb.Addhar_Number__c = a1.Aadhar_Number__c;
bb.Name=a1.Name;
newbuck2.add(bb);
system.debug('values in newbuck2'+newbuck2);
}
    
    }
    if(newbuck2.size()>0){
    insert newbuck2;
    
    }
}
}
  • May 26, 2019
  • Like
  • 0
trigger updateborrowerinbucket1 on Account (after insert, after update) {

set<id> setid = new set<id>();
list<bucket1__C> bucketlist = new list<bucket1__C>();

for(Account a : trigger.new){
setid.add(a.Bucket_1__c);

}

for(bucket1__c bb : [select id,name,Borrower_Name__c,(select id, name, Mobile_Number__c from Accounts__r)from bucket1__C where id=:setid]){

bucket1__C bb2 = new bucket1__C();
bb2.id=bb.id;
bb2.count_of_patients__c=bb.Accounts__r.size();
bb2.Borrower_Name__c=bb.Accounts__r[0].Name;

bucketlist.add(bb2);

}

update bucketlist;
}
  • May 25, 2019
  • Like
  • 0
trigger updateborrowerinbucket1 on Account (after insert, after update) {

set<id> setid = new set<id>();
list<bucket1__C> bucketlist = new list<bucket1__C>();

for(Account a : trigger.new){
setid.add(a.Bucket_1__c);

}

for(bucket1__c bb : [select id,name,Borrower_Name__c,(select id, name, Mobile_Number__c from Accounts__r)from bucket1__C]){

bucket1__C bb2 = new bucket1__C();
bb2.id=bb.id;
bb2.count_of_patients__c=bb.Accounts__r.size();
bb2.Borrower_Name__c=bb.Accounts__r.Name;

bucketlist.add(bb2);

}

update bucketlist;
}
  • May 25, 2019
  • Like
  • 0