• Shruthi Narsi
  • NEWBIE
  • 57 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 103
    Questions
  • 82
    Replies
Hi 

I am unable to complete the superbadge

please find the below link

https://trailhead.salesforce.com/en/content/learn/superbadges/superbadge_business_specialist

I am not able to complete the 3rd step. Can anyone help me

Couldn't find a component with the title 'Top Accounts'.

User-added imageUser-added imageUser-added image
Hi I am not getting the option of view as dasboard user. I need  to make changes in settings so that the user who login in should be able to view the dashboard in his name. I am not able to get that option in PE edition. Can anyone help

User-added image
I have created an assignment rule but all leads are getting assigned to default owner.

I want it to get assigned to owner of lead. I have selected default check box as checked for assigned.

User-added image
But still its not getting assigned to the lead owner

User-added image
 
1)I have a requirement to intgrate whatsapp with salesforce. I able to send and rec messgae using aura componenet. But the replies cannot be stored in salesforce. Can this be done using batch class.Running the batch at the specific time .
2)Can we automate the process of sending messages from whatsapp to Salesforce by making auto reply or auto message ?
 
I have written a test class to add list of leads and display on account page the lead should be of record type Partner Lead Registration.The test class code coverage is 90% in sandbox. While deploying its showing code coverage is 0% can anyone rewrite the test class to deploy the code successfully in prod

Below is the code I have writtena and the test class code covergae is 90%. Can anyone make the changes in the code so that ot gets deployed in prod. Error says test class code covergae is 0

Apex class

public  class PartnerLeadController {
    public Account acc{get;set;}
    public List<Lead> LeadList{get;set;}  
    Set<String> UserContactId = new Set<String>(); 
    public PartnerLeadController(ApexPages.StandardController stdController) {
        LeadList = new List<Lead>();
        this.acc = (Account)stdController.getRecord();
        list<contact> conlist=[Select Id From Contact WHERE AccountId =:acc.Id]; 
        for(User u: [Select Id, Name, ContactId FROM USER WHERE isactive=TRUE AND ContactId In:conlist]){
            UserContactId.add(u.Id);
        }
        LeadList = [select id,Name,CreatedDate,Company,OwnerId,Owner.Name,LeadSource,MAU__c,Estimated_Opportunity_Deal__c,recordType.Name,CRM_User__r.Name,CRM_User__r.Id,CRM_User__c, Status, Account__c,LastName, Account__r.id,Account__r.OwnerId
                    from Lead 
                    where    CRM_User__c !=null And Account__c=: acc.Id AND LeadSource='Partner' AND recordType.Name = 'Partner Lead Registration' ];
    }
}

Vf page

<apex:page standardController="Account" extensions="PartnerLeadController" lightningStylesheets="true" sidebar="false"  >

    <apex:form >
       

        <apex:pageBlock rendered="true" >
            <apex:outputPanel layout="block" styleClass="container">
            <apex:pageBlockTable value="{!LeadList}" var="ld" width="100" >
               
                          
            <apex:column >
                <apex:outputLink value="/{!ld.Owner}" target="_top">{!ld.Owner.Name}</apex:outputLink>
                <apex:facet name="header">Owner Name</apex:facet>
            </apex:column>/> 
                
                 <apex:column ><apex:outputField value="{!ld.Name}" />
                <apex:facet name="header">Lead Name</apex:facet>
            </apex:column>
            <apex:column ><apex:outputField value="{!ld.Status}" />
                <apex:facet name="header">Status</apex:facet>
            </apex:column> 
                <apex:column ><apex:outputField value="{!ld.Company}" />
                <apex:facet name="header">Company</apex:facet>
            </apex:column> 
                 <apex:column ><apex:outputField value="{!ld.MAU__c}" />
                <apex:facet name="header">MAU</apex:facet>
            </apex:column> 
                <apex:column ><apex:outputField value="{!ld.Estimated_Opportunity_Deal__c}" />
                <apex:facet name="header">Estimated Opportunity Deal</apex:facet>
            </apex:column> 
                
            <apex:column ><apex:outputField value="{!ld.CreatedDate}" />
                <apex:facet name="header">CreatedDate</apex:facet>
         
            </apex:column> 
            </apex:pageBlockTable>
                </apex:outputPanel>
        </apex:pageBlock>  
      
    </apex:form>
</apex:page>

Test class

@isTest
public class PartnerLeadControllerTestClass {
    
    static testMethod void leadscontroller()
    {        
        Account myaccount = new Account (name='Test');
        insert myaccount;
        
        PageReference pageRef = Page.PartnerleadList;
        pageRef.getparameters().put('recordId', myaccount.Id);  
     
        Test.setCurrentPage(pageRef);
        
        
        Apexpages.StandardController sc = new Apexpages.StandardController(myaccount);
        PartnerLeadController partlead = new PartnerLeadController(sc);   
          
        
            }
   
}





 
Below is the code I have written and the test class code covergae is 90%. Can anyone make the changes in the code so that ot gets deployed in prod. Error says test class code covergae is 0. I have written the code to add list of leads to be displayed on account. 

Apex class

public  class PartnerLeadController {
    public Account acc{get;set;}
    public List<Lead> LeadList{get;set;}  
    Set<String> UserContactId = new Set<String>(); 
    public PartnerLeadController(ApexPages.StandardController stdController) {
        LeadList = new List<Lead>();
        this.acc = (Account)stdController.getRecord();
        list<contact> conlist=[Select Id From Contact WHERE AccountId =:acc.Id]; 
        for(User u: [Select Id, Name, ContactId FROM USER WHERE isactive=TRUE AND ContactId In:conlist]){
            UserContactId.add(u.Id);
        }
        LeadList = [select id,Name,CreatedDate,Company,OwnerId,Owner.Name,LeadSource,MAU__c,Estimated_Opportunity_Deal__c,recordType.Name,CRM_User__r.Name,CRM_User__r.Id,CRM_User__c, Status, Account__c,LastName, Account__r.id,Account__r.OwnerId
                    from Lead 
                    where    CRM_User__c !=null And Account__c=: acc.Id AND LeadSource='Partner' AND recordType.Name = 'Partner Lead Registration' ];
    }
}

Vf page

<apex:page standardController="Account" extensions="PartnerLeadController" lightningStylesheets="true" sidebar="false"  >

    <apex:form >
       

        <apex:pageBlock rendered="true" >
            <apex:outputPanel layout="block" styleClass="container">
            <apex:pageBlockTable value="{!LeadList}" var="ld" width="100" >
               
                          
            <apex:column >
                <apex:outputLink value="/{!ld.Owner}" target="_top">{!ld.Owner.Name}</apex:outputLink>
                <apex:facet name="header">Owner Name</apex:facet>
            </apex:column>/> 
                
                 <apex:column ><apex:outputField value="{!ld.Name}" />
                <apex:facet name="header">Lead Name</apex:facet>
            </apex:column>
            <apex:column ><apex:outputField value="{!ld.Status}" />
                <apex:facet name="header">Status</apex:facet>
            </apex:column> 
                <apex:column ><apex:outputField value="{!ld.Company}" />
                <apex:facet name="header">Company</apex:facet>
            </apex:column> 
                 <apex:column ><apex:outputField value="{!ld.MAU__c}" />
                <apex:facet name="header">MAU</apex:facet>
            </apex:column> 
                <apex:column ><apex:outputField value="{!ld.Estimated_Opportunity_Deal__c}" />
                <apex:facet name="header">Estimated Opportunity Deal</apex:facet>
            </apex:column> 
                
            <apex:column ><apex:outputField value="{!ld.CreatedDate}" />
                <apex:facet name="header">CreatedDate</apex:facet>
         
            </apex:column> 
            </apex:pageBlockTable>
                </apex:outputPanel>
        </apex:pageBlock>  
      
    </apex:form>
</apex:page>

Test class

@isTest
public class PartnerLeadControllerTestClass {
    
    static testMethod void leadscontroller()
    {        
        Account myaccount = new Account (name='Test');
        insert myaccount;
        
        PageReference pageRef = Page.PartnerleadList;
        pageRef.getparameters().put('recordId', myaccount.Id);  
     
        Test.setCurrentPage(pageRef);
        
        
        Apexpages.StandardController sc = new Apexpages.StandardController(myaccount);
        PartnerLeadController partlead = new PartnerLeadController(sc);   
          
        
            }
   
}
I have written the below test class to add list of partner leads with record type as Partner Lead registartion on account page. Can you help me with the code
@isTest
public class PartnerLeadControllerTestClass {
    
    static testMethod void leadscontroller()
    {        
        Account myaccount = new Account (name='Test');
        insert myaccount;
        
        PageReference pageRef = Page.PartnerleadList;
        pageRef.getparameters().put('recordId', myaccount.Id);  
        Test.setCurrentPage(pageRef);
        
        Apexpages.StandardController sc = new Apexpages.StandardController(myaccount);
        PartnerLeadController partlead = new PartnerLeadController(sc);   
        partlead.getlead();
        partlead.initlead();
    }
   
}

Apex class

public  class PartnerLeadController {
    public Account acc{get;set;}
    public List<Lead> LeadList{get;set;}  
    Set<String> UserContactId = new Set<String>(); 
    public PartnerLeadController(ApexPages.StandardController stdController) {
        LeadList = new List<Lead>();
        this.acc = (Account)stdController.getRecord();
        list<contact> conlist=[Select Id From Contact WHERE AccountId =:acc.Id]; 
        for(User u: [Select Id, Name, ContactId FROM USER WHERE isactive=TRUE AND ContactId In:conlist]){
            UserContactId.add(u.Id);
        }
        LeadList = [select id,Name,CreatedDate,Company,OwnerId,Owner.Name,LeadSource,MAU__c,Estimated_Opportunity_Deal__c,recordType.Name,CRM_User__r.Name,CRM_User__r.Id,CRM_User__c, Status, Account__c,LastName, Account__r.id,Account__r.OwnerId
                    from Lead 
                    where    CRM_User__c !=null And Account__c=: acc.Id AND LeadSource='Partner' AND recordType.Name = 'Partner Lead Registration' ];
    }
}

VF Page

<apex:page standardController="Account" extensions="PartnerLeadController" lightningStylesheets="true" sidebar="false"  >

    <apex:form >
       

        <apex:pageBlock rendered="true" >
            <apex:outputPanel layout="block" styleClass="container">
            <apex:pageBlockTable value="{!LeadList}" var="ld" width="100" >
               
                          
            <apex:column >
                <apex:outputLink value="/{!ld.Owner}" target="_top">{!ld.Owner.Name}</apex:outputLink>
                <apex:facet name="header">Owner Name</apex:facet>
            </apex:column>/> 
                
                 <apex:column ><apex:outputField value="{!ld.Name}" />
                <apex:facet name="header">Lead Name</apex:facet>
            </apex:column>
            <apex:column ><apex:outputField value="{!ld.Status}" />
                <apex:facet name="header">Status</apex:facet>
            </apex:column> 
                <apex:column ><apex:outputField value="{!ld.Company}" />
                <apex:facet name="header">Company</apex:facet>
            </apex:column> 
                 <apex:column ><apex:outputField value="{!ld.MAU__c}" />
                <apex:facet name="header">MAU</apex:facet>
            </apex:column> 
                <apex:column ><apex:outputField value="{!ld.Estimated_Opportunity_Deal__c}" />
                <apex:facet name="header">Estimated Opportunity Deal</apex:facet>
            </apex:column> 
                
            <apex:column ><apex:outputField value="{!ld.CreatedDate}" />
                <apex:facet name="header">CreatedDate</apex:facet>
         
            </apex:column> 
            </apex:pageBlockTable>
                </apex:outputPanel>
        </apex:pageBlock>  
      
    </apex:form>
</apex:page>

User-added image
I have written a test class to add list of leads

@isTest
private class UpdateUnitPriceTest {

    static testMethod void myUnitTest() {

        Test.startTest();

       Account myaccount = new Account (name='Test');
        insert myaccount;
        
LeadList = [select id,Name,CreatedDate,Company,OwnerId,Owner.Name,LeadSource,recordType.Name,CRM_User__r.Name,CRM_User__r.Id,CRM_User__c, Status, Account__c,LastName, Account__r.id,Account__r.OwnerId
                    from Lead 
                    where    CRM_User__c !=null And Account__c=: acc.Id AND LeadSource='Partner' AND recordType.Name = 'Partner Lead Registration' ];
    }

        // Verify the expressions are the same
        System.assertEquals('Lead list',+LeadList);

        

        Test.stopTest();

    }
}

Apex class
@isTest
public class PartnerLeadControllerTestClass {
    
    static testMethod void leadscontroller()
    {        
        Account myaccount = new Account (name='Test');
        insert myaccount;
        
        PageReference pageRef = Page.PartnerleadList;
        pageRef.getparameters().put('recordId', myaccount.Id);  
        Test.setCurrentPage(pageRef);
        
        Apexpages.StandardController sc = new Apexpages.StandardController(myaccount);
        PartnerLeadController partlead = new PartnerLeadController(sc);   
        partlead.getlead();
        partlead.initlead();
    }
   
}
Can anyone help me with the test class to add parten lead list on account page

Below is my apex class

public class PartnerLeadController {
    public Account acc{get;set;}
    public List<Lead> LeadList{get;set;}  
    Set<String> UserContactId = new Set<String>(); 
    public PartnerLeadController(ApexPages.StandardController stdController) {
        LeadList = new List<Lead>();
        this.acc = (Account)stdController.getRecord();
        list<contact> conlist=[Select Id From Contact WHERE AccountId =:acc.Id]; 
        for(User u: [Select Id, Name, ContactId FROM USER WHERE isactive=TRUE AND ContactId In:conlist]){
            UserContactId.add(u.Id);
        }
        LeadList = [select id,Name, OwnerId, Owner.Name,LeadSource,CRM_User__r.Name,CRM_User__r.Id, Status, Account__c,LastName, Account__r.id,Account__r.OwnerId
                    from Lead 
                    where  CRM_User__c !=null And Account__c=: acc.Id AND LeadSource='Partner'];
    }
}

Test class

@isTest
public class PartnerLeadControllerTestClass {
    
    static testMethod void leadscontroller()
    {        
        Account myaccount = new Account (name='Test');
        insert myaccount;
        
        PageReference pageRef = Page.PartnerleadList;
        pageRef.getparameters().put('recordId', myaccount.Id);  
        Test.setCurrentPage(pageRef);
        
        Apexpages.StandardController sc = new Apexpages.StandardController(myaccount);
        PartnerLeadController partlead = new PartnerLeadController(sc);   
        partlead.getlead();
        partlead.initlead();
    }
   
}

Vf page

<apex:page standardController="Account" extensions="PartnerLeadController" lightningStylesheets="true" sidebar="false" >
    <apex:form >
        <apex:pageBlock rendered="true">
            <apex:pageBlockTable value="{!LeadList}" var="ld">
                <apex:column >
                    {!ld.Name}
                    <apex:facet name="header">Lead Name</apex:facet>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>  
    </apex:form>
</apex:page>
I have written the below apex class to display the lead who are parter

For example if I select the partner lead which is a look up feild as xyz then on account page I shoud be able to see his details I am getting ebelow error

Apex class
public class PartnerLeadController {
    
   public final Account acc;
   
    public PartnerLeadController(ApexPages.StandardController stdController) {
        this.acc = (Account)stdController.getRecord();
        initlead();
    }
    List<Lead> lead;
    
    public void initlead() {
        lead = [select id,OwnerId,Owner.Name,Status,LastName,Name from Lead where Partner_Name__c = : acc.id AND  LeadSource=: 'Partner' ORDER BY Name DESC];
    }
    
    public List<Lead> getlead () {
        return lead;
    }   
    
}
Vf Page

<apex:page standardController="Account" extensions="PartnerLeadController" lightningStylesheets="true" sidebar="false" >
   
    <style>
        body {
       
        }
    </style>
    <apex:pageBlock rendered="true">
        <apex:pageBlockTable value="{!lead}" var="l">
            <apex:column >
                <apex:outputLink value="/Lead/{!l.Id}/view" target="_top">{!l.Name}</apex:outputLink>
                <apex:facet name="header">Lead Name</apex:facet>
            </apex:column>
            <apex:column >
                <apex:outputLink value="/lead/{!l.AccountId}/view" target="_top">{!l.Account.Name}</apex:outputLink>
                <apex:facet name="header">Lead Name</apex:facet>
            </apex:column>
            <apex:column >
                <apex:outputLink value="/{!l.OwnerId}" target="_top">{!l.Owner.Name}</apex:outputLink>
                <apex:facet name="header">Owner Name</apex:facet>
            </apex:column>/>
            <apex:column ><apex:outputField value="{!l.Name}" />
                <apex:facet name="header">Name</apex:facet>
            </apex:column>
            <apex:column ><apex:outputField value="{!l.Status}" />
                <apex:facet name="header">Status</apex:facet>
            </apex:column>

        </apex:pageBlockTable>
    </apex:pageBlock>      
</apex:page>

User-added image
 
I have written the eblow code to display partner leads. Can u fix the error for me and help  me in writing test class for the same

Apex class
public class PartnerLeadController {
    public class PartnerLeadsController {
    
    private final Lead l;
    
    public PartnerLeadsController(ApexPages.StandardController stdController) {
        this.l = (Lead)stdController.getRecord();
        initlead();
    }
    
    List<Lead> lead;
    
    public void initlead() {
        lead = [select id,OwnerId,Owner.Name,Status,LastName from Lead where Partner_Name__c = :l.id AND  LeadSource=: 'Partner' ORDER BY Name DESC];
    }
    
    public List<Lead> getlead () {
        return lead;
    }   
    
}

           

}

Vf page

public class PartnerLeadController {
    public class PartnerLeadsController {
    
    private final Lead l;
    
    public PartnerLeadsController(ApexPages.StandardController stdController) {
        this.l = (Lead)stdController.getRecord();
        initlead();
    }
    
    List<Lead> lead;
    
    public void initlead() {
        lead = [select id,OwnerId,Owner.Name,Status,LastName from Lead where Partner_Name__c = :l.id AND  LeadSource=: 'Partner' ORDER BY Name DESC];
    }
    
    public List<Lead> getlead () {
        return lead;
    }   
    
}

           

}

User-added image
I need to post to chatter if the opportunity and lead has 3 tasks pending.Can anyone modiy the below code accordingly

public class MyBellNotification { public static void notifyCurrentUser(String message) { Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint(Url.getOrgDomainUrl().toExternalForm() + '/services/data/v46.0/actions/standard/customNotificationAction'); req.setMethod('POST'); req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId()); req.setHeader('Content-Type', 'application/json'); CustomNotificationActionInput input = new CustomNotificationActionInput(); input.customNotifTypeId = '0ML0b000000KyjGGAS'; input.recipientIds = new List<String>{UserInfo.getUserId()}; input.title = 'Test Data Operation Completed'; input.body = message; input.targetId = '0ML0b000000KyjGGAS'; CustomNotificationAction action = new CustomNotificationAction(); action.inputs = new List<CustomNotificationActionInput>{input}; req.setBody(JSON.serialize(action)); HttpResponse res = h.send(req); System.debug(res.getBody()); } public class CustomNotificationAction { public List<CustomNotificationActionInput> inputs { get; set; } } public class CustomNotificationActionInput { public String customNotifTypeId { get; set; } public List<String> recipientIds { get; set; } public String title { get; set; } public String body { get; set; } public String targetId { get; set; } } }
I have written a test class to create PDF on quote. Can anyone help me with the test class and make the code covergae as 90% atleast. Since the logic of ny test class is wrong

Apex class
public class QuotePDF {
    public boolean show{get;set;}
    public id pdtId{get;set;}
    public Quote op{get;set;}
    public QuoteLineItem oli{get;set;}
    public string pb{get;set;}
    public Id opid{get;set;}
    public id prodid{get;set;}
    public list<QuoteLineItem> OliList{get;set;}
    public list<Quotelineitem> OliCreate;
    public integer deleteIndex{get;set;}
    
    public QuotePDF()
    {
        show=false;
        oli=new QuoteLineItem();
        op=new Quote();
        OliList=new list<QuoteLineItem>();
        OliCreate=new list<Quotelineitem>();
    }
    
    public void save(){
        pricebook2 spbid=[select id from pricebook2 where isStandard=true limit 1];
        
        opportunity o1=[select id from opportunity limit 1];
        op.OpportunityId=o1.id;
        op.Pricebook2Id=spbid.id;
        upsert op;
        map<id,id>pdtTopbemap=new map<id,id>();
        
        for(pricebookentry pb:[select product2id,id from pricebookentry where pricebook2id =:spbid.id ])
        {
            pdtTopbemap.put(pb.product2id,pb.id);
        }
        for(QuoteLineItem o:OliList)
        {
            o.QuoteId=op.id;
            o.unitprice=o.unitprice; 
            o.quantity=o.quantity;
            o.pricebookentryid=pdtTopbemap.get(o.product2id);
            o.Product2Id=o.product2id;
            OliCreate.add(o);
        }
        insert OliCreate;
    }
    public void AddOli()
    {
        show=true;
        QuoteLineItem olitemp = new QuoteLineItem();
        OliList.add(olitemp);
    }
    
    public void deleteOpp()
    {
        OliList.remove(deleteIndex);
    }
}

VF

<apex:page standardController="Quotes__c" renderAs="{!renderAs}" extensions="QuoteApexClass" sidebar="false">
    <apex:form id="form1" rendered="{!showPrintLink}" style="width:700px; margin:auto; float:center;font-family:Times New Roman;font-size: 18px;"> 
        <Right>
            <apex:commandButton action="{!print}" value="Save to PDF" style="float:center;color: #0A3FF3; font-size: 17px;right:0px;position:relative;border-radius:1px;"/>
            <apex:commandButton action="{!saveQuoteAsPDFandEmail}" value="Save and Email" style="float:center;color: #0A3FF3; font-size: 17px;right:-20px;position:relative; border-radius:1px;"/>
            <apex:commandButton action="{!cancel}" value="Cancel" style="float:center;color: #0A3FF3; font-size: 17px;right:-40px;position:relative; border-radius:1px;"/>
        </Right>
        <br/><br/><br/>
        <apex:outputPanel rendered="{!If(selectedList=='Standard' , true, false)}">
            <html>
                <head>
                    <div style="background-color: #ffe4c4;margin-top: -32px;">
                        <apex:image url="{!URLFOR($Resource.Proseralogo)}" width="200" height="60" alt="plogo"/><br/><br/>
                        <b style="font-size: 20px;">{!$Organization.Name}</b>
                    </div>
                </head>
                <body>
                    <br/> 
                    <table width="100%"> 
                        <tr><td style="background-color:#add8e6;" colspan="6">General Information</td></tr>
                        <tr>
                            <td width="66%">Company Address: {!$Organization.Country}</td>
                            <td></td>
                            <td>Quote Number:{!Quotes__c.Quote_Number__c}</td>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                            <td>Expiration Date:<apex:outputField value="{!Quotes__c.Expiration_Date__c}"/></td>
                        </tr>
                    </table><br/>
                    <div style="background-color:#add8e6;">Contact Information </div>
                    <table>
                        <tr>
                            <td>Prepared By:</td>
                        </tr>
                        <tr>
                            <td>Email:{!Quotes__c.Email__c}</td>
                        </tr>
                    </table><br/>
                    <div style="background-color:#add8e6;">Address Information</div>
                    <table>
                        <tr>
                            <td>
                                Bil To:<p style="margin-left: 49px;margin-top: -20px;margin-right: 311px;font-size: 15px;">
                                {!Quotes__c.Bill_To__c}
                                </p>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 15px;">Ship To:{!Quotes__c.Quote_Number__c}</td>
                        </tr>
                    </table><br/>
                    <div style="background-color:#add8e6;">Product Details</div>
                    <table style=" width:100%;">
                        <tr border="1" style="background-color: #deb887;"> 
                            <th style="text-align:center">Product Name</th>
                            <th style="text-align:center">List Price</th>
                            <th style="text-align:center">Sales Price</th>
                            <th style="text-align:center">Quantity</th>
                            <th style="text-align:center">Total Price</th>  
                        </tr>
                        <apex:repeat value="{!Quotes__c.Quote_Line_Items__r}" var="QuoteLine">
                            <tr style="border: 1px solid #ddd; background-color: #f2f2f2;background-color: #ddd;">
                                <td style="text-align:center">{!QuoteLine.Product2Id__r.Name}</td>
                                <td style="text-align:center">{!QuoteLine.ListPrice__c}</td>
                                <td style="text-align:center">{!QuoteLine.UnitPrice__c}</td>
                                <td style="text-align:center">{!QuoteLine.Quantity__c}</td>
                                <td style="text-align:center">{!QuoteLine.Total_Price__c}</td>
                            </tr>
                        </apex:repeat>
                    </table><br/>
                    <div style="background-color:#add8e6;">Totals</div>
                    <table>
                        <tr>
                            <td>Sub Total:₹<apex:outputLabel escape="false" value="{!Quotes__c.SubTotal__c}"/></td>
                        </tr>
                        <tr>
                            <td>Discount:₹<apex:outputLabel escape="false" value="{!Quotes__c.Discount__c}"/></td>
                        </tr>
                        <tr>
                            <td>Total Price:₹<apex:outputLabel escape="false" value="{!Quotes__c.Total_Price__c}"/></td>
                        </tr>
                        <tr>
                            <td>Tax:₹<apex:outputLabel escape="false" value="{!Quotes__c.Tax__c}"/></td>
                        </tr>
                        <tr>
                            <td>Shipping and Handling:₹<apex:outputLabel escape="false" value="{!Quotes__c.ShippingHandling__c}"/></td>
                        </tr>
                        <tr>
                            <td>Grand Total:₹<apex:outputLabel escape="false" value="{!Quotes__c.Grand_Total__c}"/></td>
                        </tr>
                    </table><br/>
                    <div style="background-color:#add8e6;margin-bottom: 6px;">Quote Acceptance Information</div>
                    <table>
                        <tr>
                            <td style="margin-bottom: 6px;">Signature:........................</td>
                        </tr>
                        <tr>
                            <td style="margin-bottom: 6px;">Name:..............................</td>
                        </tr>
                        <tr>
                            <td style="margin-bottom: 6px;">Title:..............................</td>
                        </tr>
                        <tr>
                            <td style="margin-bottom: 6px;">Date:...............................</td>
                        </tr>
                    </table>
                </body>
            </html>

Test Class

@isTest
Public class QuoteApexClassTest {
    @isTest public static void QuoteApextestMethod() {
 Opportunities__c opp = new Opportunities__c();
        opp.Name = 'TestOpp';
        opp.Close_Date__c = System.today() + 5;
        opp.Stage__c = 'Prospecting';
        Insert opp;
        
        Quotes__c q = new Quotes__c();
        q.Name = 'test';
        q.OpportunityId__c = opp.Id;
        Insert q;
        
        ApexPages.StandardController sc = new ApexPages.StandardController(q);
        PageReference pageRef = Page.QuoteTemplate;
        pageRef.getParameters().put('id', String.valueOf(q.Id));
        Test.setCurrentPage(pageRef);

    
    PageReference pref = Page.QuoteTemplate;
      
    pref.getParameters().put('id',opp.id);
    Test.setCurrentPage(pref);

   


  }
}
I have written a test class to create PDF but logic is not working can anyone help me with the test class

Apex Class

public class QuotePDF {
    public boolean show{get;set;}
    public id pdtId{get;set;}
    public Quote op{get;set;}
    public QuoteLineItem oli{get;set;}
    public string pb{get;set;}
    public Id opid{get;set;}
    public id prodid{get;set;}
    public list<QuoteLineItem> OliList{get;set;}
    public list<Quotelineitem> OliCreate;
    public integer deleteIndex{get;set;}
    
    public QuotePDF()
    {
        show=false;
        oli=new QuoteLineItem();
        op=new Quote();
        OliList=new list<QuoteLineItem>();
        OliCreate=new list<Quotelineitem>();
    }
    
    public void save(){
        pricebook2 spbid=[select id from pricebook2 where isStandard=true limit 1];
        
        opportunity o1=[select id from opportunity limit 1];
        op.OpportunityId=o1.id;
        op.Pricebook2Id=spbid.id;
        upsert op;
        map<id,id>pdtTopbemap=new map<id,id>();
        
        for(pricebookentry pb:[select product2id,id from pricebookentry where pricebook2id =:spbid.id ])
        {
            pdtTopbemap.put(pb.product2id,pb.id);
        }
        for(QuoteLineItem o:OliList)
        {
            o.QuoteId=op.id;
            o.unitprice=o.unitprice; 
            o.quantity=o.quantity;
            o.pricebookentryid=pdtTopbemap.get(o.product2id);
            o.Product2Id=o.product2id;
            OliCreate.add(o);
        }
        insert OliCreate;
    }
    public void AddOli()
    {
        show=true;
        QuoteLineItem olitemp = new QuoteLineItem();
        OliList.add(olitemp);
    }
    
    public void deleteOpp()
    {
        OliList.remove(deleteIndex);
    }
}

Test Class

@isTest
Public class QuoteApexClassTest {
    @isTest public static void QuoteApextestMethod() {
        Opportunities__c opp = new Opportunities__c();
        opp.Name = 'TestOpp';
        opp.Close_Date__c = System.today() + 5;
        opp.Stage__c = 'Prospecting';
        Insert opp;
        
        Quotes__c q = new Quotes__c();
        q.Name = 'test';
        q.OpportunityId__c = opp.Id;
        Insert q;
        
        ApexPages.StandardController sc = new ApexPages.StandardController(q);
        PageReference pageRef = Page.QuoteTemplate;
        pageRef.getParameters().put('id', String.valueOf(q.Id));
        Test.setCurrentPage(pageRef);
        
        QuoteApexClass qac = new QuoteApexClass(sc);        
        qac.saveQuoteAsPDFandEmail();
         
        qac.print();
    } 
}
Can Anyone help me with the test class and make the code coverage to 100%

Apex class

public class QuotePDF {
    public boolean show{get;set;}
    public id pdtId{get;set;}
    public Quote op{get;set;}
    public QuoteLineItem oli{get;set;}
    public string pb{get;set;}
    public Id opid{get;set;}
    public id prodid{get;set;}
    public list<QuoteLineItem> OliList{get;set;}
    public list<Quotelineitem> OliCreate;
    public integer deleteIndex{get;set;}
    
    public QuotePDF()
    {
        show=false;
        oli=new QuoteLineItem();
        op=new Quote();
        OliList=new list<QuoteLineItem>();
        OliCreate=new list<Quotelineitem>();
    }
    
    public void save(){
        pricebook2 spbid=[select id from pricebook2 where isStandard=true limit 1];
        
        opportunity o1=[select id from opportunity limit 1];
        op.OpportunityId=o1.id;
        op.Pricebook2Id=spbid.id;
        upsert op;
        map<id,id>pdtTopbemap=new map<id,id>();
        
        for(pricebookentry pb:[select product2id,id from pricebookentry where pricebook2id =:spbid.id ])
        {
            pdtTopbemap.put(pb.product2id,pb.id);
        }
        for(QuoteLineItem o:OliList)
        {
            o.QuoteId=op.id;
            o.unitprice=o.unitprice; 
            o.quantity=o.quantity;
            o.pricebookentryid=pdtTopbemap.get(o.product2id);
            o.Product2Id=o.product2id;
            OliCreate.add(o);
        }
        insert OliCreate;
    }
    public void AddOli()
    {
        show=true;
        QuoteLineItem olitemp = new QuoteLineItem();
        OliList.add(olitemp);
    }
    
    public void deleteOpp()
    {
        OliList.remove(deleteIndex);
    }
}

Test Class

@isTest
Public class QuoteApexClassTest {
    @isTest public static void QuoteApextestMethod() {
        Opportunity opp = new Opportunity();
        opp.Name = 'TestOpp';
        opp.CloseDate = System.today() + 5;
        opp.StageName = 'Prospecting';
        Insert opp;
        
        Quote q = new Quote();
        q.Name = 'test';
        q.OpportunityId = opp.Id;
        Insert q;
        

       ApexPages.StandardController sc = new ApexPages.StandardController(q);
        PageReference pageRef = Page.QuoteTemplate;
        pageRef.getParameters().put('id', String.valueOf(q.Id));
        Test.setCurrentPage(pageRef);
    
        QuoteApexClass qac = new QuoteApexClass(sc);        
        qac.saveQuoteAsPDFandEmail();
        qac.attachPDF();
        qac.getShowPrintLink();
        qac.print();
    }
}

User-added image
I have written a apex class to generate PDF On Quote. I have wirtten a test class but I am getting below error

User-added image

Apex Class

public class QuotePDF {
    public boolean show{get;set;}
    public id pdtId{get;set;}
    public Quote op{get;set;}
    public QuoteLineItem oli{get;set;}
    public string pb{get;set;}
    public Id opid{get;set;}
    public id prodid{get;set;}
    public list<QuoteLineItem> OliList{get;set;}
    public list<Quotelineitem> OliCreate;
    public integer deleteIndex{get;set;}
    
    public QuotePDF()
    {
        show=false;
        oli=new QuoteLineItem();
        op=new Quote();
        OliList=new list<QuoteLineItem>();
        OliCreate=new list<Quotelineitem>();
    }
    
    public void save(){
        pricebook2 spbid=[select id from pricebook2 where isStandard=true limit 1];
        
        opportunity o1=[select id from opportunity limit 1];
        op.OpportunityId=o1.id;
        op.Pricebook2Id=spbid.id;
        upsert op;
        map<id,id>pdtTopbemap=new map<id,id>();
        
        for(pricebookentry pb:[select product2id,id from pricebookentry where pricebook2id =:spbid.id ])
        {
            pdtTopbemap.put(pb.product2id,pb.id);
        }
        for(QuoteLineItem o:OliList)
        {
            o.QuoteId=op.id;
            o.unitprice=o.unitprice; 
            o.quantity=o.quantity;
            o.pricebookentryid=pdtTopbemap.get(o.product2id);
            o.Product2Id=o.product2id;
            OliCreate.add(o);
        }
        insert OliCreate;
    }
    public void AddOli()
    {
        show=true;
        QuoteLineItem olitemp = new QuoteLineItem();
        OliList.add(olitemp);
    }
    
    public void deleteOpp()
    {
        OliList.remove(deleteIndex);
    }
}

Test Class

@isTest
Public class QuoteApexClassTest {
    @isTest public static void QuoteApextestMethod() {
        Opportunities__c opp = new Opportunities__c();
        opp.Name = 'TestOpp';
        opp.Close_Date__c = System.today() + 5;
        opp.Stage__c = 'Prospecting';
        Insert opp;
        
        Quotes__c q = new Quotes__c();
        q.Name = 'test';
        q.OpportunityId__c = opp.Id;
        Insert q;
        
        ApexPages.StandardController sc = new ApexPages.StandardController(q);
        PageReference pageRef = Page.QuoteTemplate;
        pageRef.getParameters().put('id', String.valueOf(q.Id));
        Test.setCurrentPage(pageRef);
        
        QuoteApexClass qac = new QuoteApexClass(sc);        
        qac.saveQuoteAsPDFandEmail();
        qac.attachPDF();
        qac.getShowPrintLink(); 
        qac.print();
    } 
}

 
I have written the below code to add orderlineitems once quote is synced.
Once quote is synced the order gets created and the order procducts will get created. Can u help me with the code covergae as 100% its 0% now

trigger Createorderproduct on Order__c (after insert) {
    Set<Id> orderIdset= new Set<Id>();
    List<Order__c> orderList = new List<Order__c>();
    Map<Id,Id> opMap = new Map<Id,Id>();
    List<OrderItem__c> orderItemsForInsert = new List<OrderItem__c>();
    for(Order__c o : Trigger.new){
        if(o.Opportunity__c!= null){
            opMap.put(o.Opportunity__c ,o.Id);
        }
    }
    
    if(!opMap.isEmpty()){
        for(OpportunityLineItem__c oli: [Select id, name, OpportunityId__r.Stage__c, Product2Id__r.name, ListPrice__c, 
                                         OpportunityId__c, Sales_Price__c, Quantity__c 
                                         FROM OpportunityLineItem__c 
                                         WHERE OpportunityId__c IN: opMap.Keyset() 
                                         AND OpportunityId__r.Stage__c='Closed Won'])
        {
            OrderItem__c OrderItem = new OrderItem__c();
            OrderItem.OrderId__c = opMap.get(oli.OpportunityId__c);
            OrderItem.Name = oli.Product2Id__r.name;
            OrderItem.ListPrice__c = oli.ListPrice__c;
            OrderItem.Sales_Price__c = oli.Sales_Price__c;
            OrderItem.Quantity__c = oli.Quantity__c;
            orderItemsForInsert.add(OrderItem);                
        }
        if(orderItemsForInsert.size()>0)
        {
            insert orderItemsForInsert;
        } 
    }
}

Test Class

@isTest
public class orderproductTestClass {
    
    public static testMethod void testorderproduct(){
       Map<Id,Id> mapof = new Map<Id,Id>();
       OpportunityLineItem__c pd = new OpportunityLineItem__c();
       pd.OpportunityId__r.Stage__c='Closed Won' ;
        OrderItem__c orderItemsForInsert = new OrderItem__c();
        
        OrderItem__c oi = new OrderItem__c();
        oi.OrderId__c = mapof.get(pd.OpportunityId__c);
        oi.Name = pd.Product2Id__r.name;
        oi.ListPrice__c = pd.ListPrice__c;
        oi.Sales_Price__c = pd.Sales_Price__c;
        oi.Quantity__c = pd.Quantity__c;
        insert orderItemsForInsert;
        
    } 
}
 
I have written A test calss to add quoteLineitems

Test class covergae is only 70% Can anyone help me reach atleast 90%

User-added imageUser-added imageUser-added imageUser-added imageUser-added imageApex class

global class ProductSearchPopupController {
    
    public String query {get; set;}
    public List<PricebookEntry__c> products {get; set;}
    public List<wrapProduct> wrapProductList {get; set;}
    public List<QuoteLineitem__c> selectedProduct{get;set;}
    public List<QuoteLineitem__c> quoteLineList{get;set;}
    public List<wrapProduct> selectedWrapperList{get;set;}
    public Boolean normalList{get;set;}
    public Boolean selectedList{get;set;}
    public Boolean block{get;set;}
    public Boolean block1{get;set;}
    public Boolean block2{get;set;}
    public Boolean Error{get;set;}
    public String SalesPrice {get; set;}
    public integer Discount {get; set;}
    public String Quantity {get; set;}
    public String ServiceDate {get; set;}
    public list<PricebookEntry__c> PricebookEntryList{get;set;}
    public string selectePriceBook{get;set;}
    public list<selectOption> listofpricebook{get;set;}
    
    Id recordId;
    
    public ProductSearchPopupController(ApexPages.StandardController controller){
        recordId = controller.getId();
        SalesPrice='';
        Quantity='';
        ServiceDate='';
        system.debug('recordId '+recordId);
        wrapProductList = new List<wrapProduct>();
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = true;
        block = true;
        block1 = true;
        block2 = false;
        selectePriceBook='None';
        Error=False;
        listofpricebook=new list<selectOption>();
        PricebookEntryList= new List<PricebookEntry__c>();
        
        list<pricebook2__c> przblist=new list<pricebook2__c>([select id, name, Is_Standard_Price_Book__c, IsActive__c from pricebook2__c Where IsActive__c =True Limit 999]);
        listofpricebook.clear();
        listofpricebook.add(new SelectOption('None','--None--'));
        for(pricebook2__c pb: przblist)
        {
            listofpricebook.add(new selectOption(pb.id,pb.name));
        }
        
    }
    public PageReference runQuery1(){
        
        List<PricebookEntry__c> searchResults=[select id, PricebookEntry__c.Name, Pricebook2Id__r.Id, Pricebook2Id__r.Name, Product2Id__r.Product_Code__c, Product2Id__r.Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c from PricebookEntry__c where IsActive__c = true And Pricebook2Id__c=:selectePriceBook AND Product2Id__r.Name!=null];
        if(searchResults.size() >= 0){
            
            for(PricebookEntry__c a: searchResults) {
                // As each product is processed we create a new wrapproduct object and add it to the wrapProductList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;
                block2 = false;
            }
        }
        return null;
    }
    public PageReference runQuery(){
        wrapProductList = new List<wrapProduct>();
        
        if(Test.isRunningTest()){
            query='Test';
        }
        if(query == null || query == '' || query.length() ==1){
            runQuery1();
        }else if(query.length() >1){
            query = '%'+query+'%'; 
            List<PricebookEntry__c> searchResults=[Select id, Name,Product_Name__c,Product2Id__c, Pricebook2Id__r.Id, Pricebook2Id__r.Name, Product2Id__r.Name, Product2Id__r.Product_Code__c,Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c 
                                                   from PricebookEntry__c where (Product2Id__r.Name like:query OR Product2Id__r.Product_Code__c like:query) And Pricebook2Id__c=:selectePriceBook Limit 1];
            
            if(searchResults.size()>0){ 
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(searchResults[0]));
                block = true;
                block1 = true;  
                block2 = false;  
                
            }
            query = query.replaceAll('%','');
        }
        return null;
    }
    public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = true;
        for(wrapProduct selectedWrapObj: wrapProductList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
                selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
    public void processSelected() {
        selectedProduct = new List<QuoteLineitem__c>();
        for(wrapProduct wrapProductObj : wrapProductList) {
            if(wrapProductObj.selected == true) {
                QuoteLineitem__c qli = new QuoteLineitem__c(); 
                qli.QuotesId__c = recordId;
                qli.ListPrice__c = wrapProductObj.acc.UnitPrice__c;
                qli.UnitPrice__c = wrapProductObj.acc.UnitPrice__c;
                qli.Product2Id__c = wrapProductObj.acc.Product2Id__c; 
                qli.Quantity__c = 1;
                selectedProduct.add(qli);
                block = true;
                block1 = false;
                block2 = true;
            }else{
                Error=True;
            }
        }
        if(Error==True && selectedProduct.isEmpty()){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select at least one product to continue'));
        }
        
    }
    public void callOnPageLoad() {
        runQuery1();
        processSelected();
    }
    
    public void GoBack() {
        block = true;
        block1 = true;
        block2 = false;
    }
    
    global class wrapProduct{
        public PricebookEntry__c acc {get;set;}
        public Boolean selected {get;set;}
        public wrapProduct(PricebookEntry__c p) {
            this.acc = p;
            this.selected = false;
        } 
    }
    
    public pagereference saveproduct(){
        
        if(Test.isRunningTest()){
            insertTestData();
        }
        if(!selectedProduct.isEmpty()){
            System.debug('selectedProduct' + selectedProduct.size());
            for(QuoteLineitem__c sp:selectedProduct){
                if(sp.Quantity__c == null || sp.Quantity__c==0){
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Quantity should not be blank or Zero'));   
                    return null;
                } 
            }
            
            if(selectedProduct.size() > 0){
                insert selectedProduct;
                System.debug('selectedProduct' + selectedProduct);
                PageReference pageRef = new PageReference('/'+recordId);
                pageRef.setRedirect(true);
                return pageRef;
            }
        }
        return null;
    }
    public void insertTestData(){
        Product2__c testProduct = new Product2__c();
        testProduct.Name='Test product';
        insert testProduct;
        PricebookEntry__c testpbe = new PricebookEntry__c();
        testpbe.Name='Test PriceBookEntry';
        testpbe.UnitPrice__c =123;
        testpbe.Product2Id__c=testProduct.Id;
        insert testpbe;
        //selectedProduct.add(testpbe);
    }
}

Test Class

@isTest
Private class TestProductSearchpopupController {
     static testMethod void method()        {
        Account acc = new Account ();
        acc.Name = 'Test1';
        insert acc;
        
        Opportunities__c opp= new Opportunities__c ();
        opp.Name= 'Testopp1';
        opp.Account_Name__c = acc.id;
        opp.Close_Date__c = date.today();            
        opp.Stage__c = 'Prospecting';
        insert opp;
        
        Quotes__c testque = new Quotes__c();
        testque.Name = 'Test PriceBookEntry';
        testque.OpportunityId__c = opp.id;
        testque.AccountId__c = acc.id;
        insert testque;
        
        List <Product2__c> lstproduct = new List<Product2__c>();
        Product2__c testProduct = new Product2__c();
        testProduct.Name='Test product';
        lstproduct.add(testProduct);
        insert lstproduct;
        
         List <PricebookEntry__c> lstpbe = new List<PricebookEntry__c>();
         PricebookEntry__c testpbe = new PricebookEntry__c();
         testpbe.Name='Test';
         lstpbe.add(testpbe);
         insert lstpbe;
         product2 pr = new product2();
         pr.name = 'Test product';
         insert pr;
         
         List<Pricebook2> pricebook2List = new List<pricebook2>();
         PriceBook2 pb2=new PriceBook2();
         pb2.Name = 'test';
         pb2.IsActive = true;
          pricebook2List.add(pb2); 
         
         insert pricebook2List;
         PricebookEntry two = new PricebookEntry();
         two.pricebook2Id =  Test.getStandardPricebookId();
         two.product2id = pr.id;
         two.unitprice = 1249.0;
         two.isactive = true;
         insert two;
         PricebookEntry one = new PricebookEntry();
         one.pricebook2Id = pb2.id;
         one.product2id = pr.id;
         one.unitprice = 1249.0;
         one.isactive = true;
         insert one;
        
        List <QuoteLineitem__c> lstqli = new List<QuoteLineitem__c>();
        QuoteLineitem__c testqli = new QuoteLineitem__c();
        testqli.QuotesId__c = testque.id;
        testqli.Quantity__c = 12;    
        lstqli.add(testqli);
        insert lstqli;
        
        PageReference pageRef = Page.ProductSearchPopupController;
        pageRef.getparameters().put('recordId',testque.id);
        Test.setCurrentPage(pageRef);
        
        
        ProductSearchPopupController.wrapProduct test=new 
        ProductSearchPopupController.wrapProduct(testpbe);
        ApexPages.StandardController sc = new ApexPages.StandardController(testque);
        ProductSearchPopupController psp = new ProductSearchPopupController(sc);
        
      
         psp.wrapProductList.add(Test);
        psp.selectedWrapperList.add(test);
        psp.runQuery();
        psp.runQuery1();
        psp.ProceedWithSelectedToNextPage();
        psp.processSelected();
        psp.GoBack();
        psp.saveproduct();
        psp.callOnPageLoad(); 
    }
     
}
I have written a test class to create orderline product once the order is created.



User-added image


@isTest
public class orderproductTestClass {
    
    public static testMethod void testorderproduct(){
       Map<Id,Id> mapof = new Map<Id,Id>();
       OpportunityLineItem__c pd = new OpportunityLineItem__c();
       OrderItem__c orderItemsForInsert = new OrderItem__c();
        
        OrderItem__c oi = new OrderItem__c();
        oi.OrderId__c = mapof.get(pd.OpportunityId__c);
        oi.Name = pd.Product2Id__r.name;
        oi.ListPrice__c = pd.ListPrice__c;
        oi.Sales_Price__c = pd.Sales_Price__c;
        oi.Quantity__c = pd.Quantity__c;
        insert orderItemsForInsert;
        Test.StopTest();
    } 
}

Apex class

trigger Createorderproduct on Order__c (after insert) {
    Set<Id> orderIdset= new Set<Id>();
    List<Order__c> orderList = new List<Order__c>();
    Map<Id,Id> opMap = new Map<Id,Id>();
    List<OrderItem__c> orderItemsForInsert = new List<OrderItem__c>();
    for(Order__c o : Trigger.new){
        if(o.Opportunity__c!= null){
            opMap.put(o.Opportunity__c ,o.Id);
        }
    }
    
    if(!opMap.isEmpty()){
        for(OpportunityLineItem__c oli: [Select id, name, OpportunityId__r.Stage__c, Product2Id__r.name, ListPrice__c, 
                                         OpportunityId__c, Sales_Price__c, Quantity__c 
                                         FROM OpportunityLineItem__c 
                                         WHERE OpportunityId__c IN: opMap.Keyset() 
                                         AND OpportunityId__r.Stage__c='Closed Won'])
        {
            OrderItem__c OrderItem = new OrderItem__c();
            OrderItem.OrderId__c = opMap.get(oli.OpportunityId__c);
            OrderItem.Name = oli.Product2Id__r.name;
            OrderItem.ListPrice__c = oli.ListPrice__c;
            OrderItem.Sales_Price__c = oli.Sales_Price__c;
            OrderItem.Quantity__c = oli.Quantity__c;
            orderItemsForInsert.add(OrderItem);                
        }
        if(orderItemsForInsert.size()>0)
        {
            insert orderItemsForInsert;
        } 
    }
}

User-added image
I have wrotten the below code to add quoteline items . The code covergae is only 70%. Can you help me with the code coverage tp be 90%
Test Class

@isTest
Private class TestProductSearchpopupController {
     static testMethod void method()        {
        Account acc = new Account ();
        acc.Name = 'Test1';
        insert acc;
        
        Opportunities__c opp= new Opportunities__c ();
        opp.Name= 'Testopp1';
        opp.Account_Name__c = acc.id;
        opp.Close_Date__c = date.today();            
        opp.Stage__c = 'Prospecting';
        insert opp;
        
        Quotes__c testque = new Quotes__c();
        testque.Name = 'Test PriceBookEntry';
        testque.OpportunityId__c = opp.id;
        testque.AccountId__c = acc.id;
        insert testque;
        
        List <Product2__c> lstproduct = new List<Product2__c>();
        Product2__c testProduct = new Product2__c();
        testProduct.Name='Test product';
        lstproduct.add(testProduct);
        insert lstproduct;
        
         List <PricebookEntry__c> lstpbe = new List<PricebookEntry__c>();
         PricebookEntry__c testpbe = new PricebookEntry__c();
         testpbe.Name='Test';
         lstpbe.add(testpbe);
         insert lstpbe;
         product2 pr = new product2();
         pr.name = 'Test product';
         insert pr;
         
         List<Pricebook2> pricebook2List = new List<pricebook2>();
         PriceBook2 pb2=new PriceBook2();
         pb2.Name = 'test';
         pb2.IsActive = true;
          pricebook2List.add(pb2); 
         
         insert pricebook2List;
         PricebookEntry two = new PricebookEntry();
         two.pricebook2Id =  Test.getStandardPricebookId();
         two.product2id = pr.id;
         two.unitprice = 1249.0;
         two.isactive = true;
         insert two;
         PricebookEntry one = new PricebookEntry();
         one.pricebook2Id = pb2.id;
         one.product2id = pr.id;
         one.unitprice = 1249.0;
         one.isactive = true;
         insert one;
        
        List <QuoteLineitem__c> lstqli = new List<QuoteLineitem__c>();
        QuoteLineitem__c testqli = new QuoteLineitem__c();
        testqli.QuotesId__c = testque.id;
        testqli.Quantity__c = 12;    
        lstqli.add(testqli);
        insert lstqli;
        
        PageReference pageRef = Page.ProductSearchPopupController;
        pageRef.getparameters().put('recordId',testque.id);
        Test.setCurrentPage(pageRef);
        
        
        ProductSearchPopupController.wrapProduct test=new 
        ProductSearchPopupController.wrapProduct(testpbe);
        ApexPages.StandardController sc = new ApexPages.StandardController(testque);
        ProductSearchPopupController psp = new ProductSearchPopupController(sc);
        
      
         psp.wrapProductList.add(Test);
        psp.selectedWrapperList.add(test);
        psp.runQuery();
        psp.runQuery1();
        psp.ProceedWithSelectedToNextPage();
        psp.processSelected();
        psp.GoBack();
        psp.saveproduct();
        psp.callOnPageLoad(); 
    }
     
}

ClAass

global class ProductSearchPopupController {
    
    public String query {get; set;}
    public List<PricebookEntry__c> products {get; set;}
    public List<wrapProduct> wrapProductList {get; set;}
    public List<QuoteLineitem__c> selectedProduct{get;set;}
    public List<QuoteLineitem__c> quoteLineList{get;set;}
    public List<wrapProduct> selectedWrapperList{get;set;}
    public Boolean normalList{get;set;}
    public Boolean selectedList{get;set;}
    public Boolean block{get;set;}
    public Boolean block1{get;set;}
    public Boolean block2{get;set;}
    public Boolean Error{get;set;}
    public String SalesPrice {get; set;}
    public integer Discount {get; set;}
    public String Quantity {get; set;}
    public String ServiceDate {get; set;}
    public list<PricebookEntry__c> PricebookEntryList{get;set;}
    public string selectePriceBook{get;set;}
    public list<selectOption> listofpricebook{get;set;}
    
    Id recordId;
    
    public ProductSearchPopupController(ApexPages.StandardController controller){
        recordId = controller.getId();
        SalesPrice='';
        Quantity='';
        ServiceDate='';
        system.debug('recordId '+recordId);
        wrapProductList = new List<wrapProduct>();
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = true;
        block = true;
        block1 = true;
        block2 = false;
        selectePriceBook='None';
        Error=False;
        listofpricebook=new list<selectOption>();
        PricebookEntryList= new List<PricebookEntry__c>();
        
        list<pricebook2__c> przblist=new list<pricebook2__c>([select id, name, Is_Standard_Price_Book__c, IsActive__c from pricebook2__c Where IsActive__c =True Limit 999]);
        listofpricebook.clear();
        listofpricebook.add(new SelectOption('None','--None--'));
        for(pricebook2__c pb: przblist)
        {
            listofpricebook.add(new selectOption(pb.id,pb.name));
        }
        
    }
    public PageReference runQuery1(){
        
        List<PricebookEntry__c> searchResults=[select id, PricebookEntry__c.Name, Pricebook2Id__r.Id, Pricebook2Id__r.Name, Product2Id__r.Product_Code__c, Product2Id__r.Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c from PricebookEntry__c where IsActive__c = true And Pricebook2Id__c=:selectePriceBook AND Product2Id__r.Name!=null];
        if(searchResults.size() >= 0){
            
            for(PricebookEntry__c a: searchResults) {
                // As each product is processed we create a new wrapproduct object and add it to the wrapProductList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;
                block2 = false;
            }
        }
        return null;
    }
    public PageReference runQuery(){
        wrapProductList = new List<wrapProduct>();
        
        if(Test.isRunningTest()){
            query='Test';
        }
        if(query == null || query == '' || query.length() ==1){
            runQuery1();
        }else if(query.length() >1){
            query = '%'+query+'%'; 
            List<PricebookEntry__c> searchResults=[Select id, Name,Product_Name__c,Product2Id__c, Pricebook2Id__r.Id, Pricebook2Id__r.Name, Product2Id__r.Name, Product2Id__r.Product_Code__c,Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c 
                                                   from PricebookEntry__c where (Product2Id__r.Name like:query OR Product2Id__r.Product_Code__c like:query) And Pricebook2Id__c=:selectePriceBook Limit 1];
            
            if(searchResults.size()>0){ 
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(searchResults[0]));
                block = true;
                block1 = true;  
                block2 = false;  
                
            }
            query = query.replaceAll('%','');
        }
        return null;
    }
    public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = true;
        for(wrapProduct selectedWrapObj: wrapProductList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
                selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
    public void processSelected() {
        selectedProduct = new List<QuoteLineitem__c>();
        for(wrapProduct wrapProductObj : wrapProductList) {
            if(wrapProductObj.selected == true) {
                QuoteLineitem__c qli = new QuoteLineitem__c(); 
                qli.QuotesId__c = recordId;
                qli.ListPrice__c = wrapProductObj.acc.UnitPrice__c;
                qli.UnitPrice__c = wrapProductObj.acc.UnitPrice__c;
                qli.Product2Id__c = wrapProductObj.acc.Product2Id__c; 
                qli.Quantity__c = 1;
                selectedProduct.add(qli);
                block = true;
                block1 = false;
                block2 = true;
            }else{
                Error=True;
            }
        }
        if(Error==True && selectedProduct.isEmpty()){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select at least one product to continue'));
        }
        
    }
    public void callOnPageLoad() {
        runQuery1();
        processSelected();
    }
    
    public void GoBack() {
        block = true;
        block1 = true;
        block2 = false;
    }
    
    global class wrapProduct{
        public PricebookEntry__c acc {get;set;}
        public Boolean selected {get;set;}
        public wrapProduct(PricebookEntry__c p) {
            this.acc = p;
            this.selected = false;
        } 
    }
    
    public pagereference saveproduct(){
        
        if(Test.isRunningTest()){
            insertTestData();
        }
        if(!selectedProduct.isEmpty()){
            System.debug('selectedProduct' + selectedProduct.size());
            for(QuoteLineitem__c sp:selectedProduct){
                if(sp.Quantity__c == null || sp.Quantity__c==0){
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Quantity should not be blank or Zero'));   
                    return null;
                } 
            }
            
            if(selectedProduct.size() > 0){
                insert selectedProduct;
                System.debug('selectedProduct' + selectedProduct);
                PageReference pageRef = new PageReference('/'+recordId);
                pageRef.setRedirect(true);
                return pageRef;
            }
        }
        return null;
    }
    public void insertTestData(){
        Product2__c testProduct = new Product2__c();
        testProduct.Name='Test product';
        insert testProduct;
        PricebookEntry__c testpbe = new PricebookEntry__c();
        testpbe.Name='Test PriceBookEntry';
        testpbe.UnitPrice__c =123;
        testpbe.Product2Id__c=testProduct.Id;
        insert testpbe;
        //selectedProduct.add(testpbe);
    }
}
Add all amount on opportunity on quota actual amount 

User-added image
public with sharing class listopponquota {
    
    public list<Opportunity> oppList{get;set;}
    
    public listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        oppList();
    }
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c,Actual_Amount__c,OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,Amount,OwnerId From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                system.debug('Name-->'+q.Name);
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId && q.RecordTypeId == '0122v000002KFRAAA4'){
                        oppList.add(opp);
                    } 
                    if( q.RecordTypeId == '0122v000002KFRAAA4') {
                    q.Actual_Amount__c = 0;
                } else {
                    q.Actual_Amount__c = q.Actual_Amount__c + Decimal.ValueOf(String.ValueOf(q.get('Actual_Amount__c')));                    
                    quotaList1.add(q);
                }
            }
        }
        if(quotaList1.size()>0) {            
            update quotaList1;
             
        
        }
    }
        system.debug('oppList-->'+oppList);
            return null;
}
}
    
Hi 

I am unable to complete the superbadge

please find the below link

https://trailhead.salesforce.com/en/content/learn/superbadges/superbadge_business_specialist

I am not able to complete the 3rd step. Can anyone help me

Couldn't find a component with the title 'Top Accounts'.

User-added imageUser-added imageUser-added image
I have created an assignment rule but all leads are getting assigned to default owner.

I want it to get assigned to owner of lead. I have selected default check box as checked for assigned.

User-added image
But still its not getting assigned to the lead owner

User-added image
 
1)I have a requirement to intgrate whatsapp with salesforce. I able to send and rec messgae using aura componenet. But the replies cannot be stored in salesforce. Can this be done using batch class.Running the batch at the specific time .
2)Can we automate the process of sending messages from whatsapp to Salesforce by making auto reply or auto message ?
 
I have written the below test class to add list of partner leads with record type as Partner Lead registartion on account page. Can you help me with the code
@isTest
public class PartnerLeadControllerTestClass {
    
    static testMethod void leadscontroller()
    {        
        Account myaccount = new Account (name='Test');
        insert myaccount;
        
        PageReference pageRef = Page.PartnerleadList;
        pageRef.getparameters().put('recordId', myaccount.Id);  
        Test.setCurrentPage(pageRef);
        
        Apexpages.StandardController sc = new Apexpages.StandardController(myaccount);
        PartnerLeadController partlead = new PartnerLeadController(sc);   
        partlead.getlead();
        partlead.initlead();
    }
   
}

Apex class

public  class PartnerLeadController {
    public Account acc{get;set;}
    public List<Lead> LeadList{get;set;}  
    Set<String> UserContactId = new Set<String>(); 
    public PartnerLeadController(ApexPages.StandardController stdController) {
        LeadList = new List<Lead>();
        this.acc = (Account)stdController.getRecord();
        list<contact> conlist=[Select Id From Contact WHERE AccountId =:acc.Id]; 
        for(User u: [Select Id, Name, ContactId FROM USER WHERE isactive=TRUE AND ContactId In:conlist]){
            UserContactId.add(u.Id);
        }
        LeadList = [select id,Name,CreatedDate,Company,OwnerId,Owner.Name,LeadSource,MAU__c,Estimated_Opportunity_Deal__c,recordType.Name,CRM_User__r.Name,CRM_User__r.Id,CRM_User__c, Status, Account__c,LastName, Account__r.id,Account__r.OwnerId
                    from Lead 
                    where    CRM_User__c !=null And Account__c=: acc.Id AND LeadSource='Partner' AND recordType.Name = 'Partner Lead Registration' ];
    }
}

VF Page

<apex:page standardController="Account" extensions="PartnerLeadController" lightningStylesheets="true" sidebar="false"  >

    <apex:form >
       

        <apex:pageBlock rendered="true" >
            <apex:outputPanel layout="block" styleClass="container">
            <apex:pageBlockTable value="{!LeadList}" var="ld" width="100" >
               
                          
            <apex:column >
                <apex:outputLink value="/{!ld.Owner}" target="_top">{!ld.Owner.Name}</apex:outputLink>
                <apex:facet name="header">Owner Name</apex:facet>
            </apex:column>/> 
                
                 <apex:column ><apex:outputField value="{!ld.Name}" />
                <apex:facet name="header">Lead Name</apex:facet>
            </apex:column>
            <apex:column ><apex:outputField value="{!ld.Status}" />
                <apex:facet name="header">Status</apex:facet>
            </apex:column> 
                <apex:column ><apex:outputField value="{!ld.Company}" />
                <apex:facet name="header">Company</apex:facet>
            </apex:column> 
                 <apex:column ><apex:outputField value="{!ld.MAU__c}" />
                <apex:facet name="header">MAU</apex:facet>
            </apex:column> 
                <apex:column ><apex:outputField value="{!ld.Estimated_Opportunity_Deal__c}" />
                <apex:facet name="header">Estimated Opportunity Deal</apex:facet>
            </apex:column> 
                
            <apex:column ><apex:outputField value="{!ld.CreatedDate}" />
                <apex:facet name="header">CreatedDate</apex:facet>
         
            </apex:column> 
            </apex:pageBlockTable>
                </apex:outputPanel>
        </apex:pageBlock>  
      
    </apex:form>
</apex:page>

User-added image
I have written a test class to add list of leads

@isTest
private class UpdateUnitPriceTest {

    static testMethod void myUnitTest() {

        Test.startTest();

       Account myaccount = new Account (name='Test');
        insert myaccount;
        
LeadList = [select id,Name,CreatedDate,Company,OwnerId,Owner.Name,LeadSource,recordType.Name,CRM_User__r.Name,CRM_User__r.Id,CRM_User__c, Status, Account__c,LastName, Account__r.id,Account__r.OwnerId
                    from Lead 
                    where    CRM_User__c !=null And Account__c=: acc.Id AND LeadSource='Partner' AND recordType.Name = 'Partner Lead Registration' ];
    }

        // Verify the expressions are the same
        System.assertEquals('Lead list',+LeadList);

        

        Test.stopTest();

    }
}

Apex class
@isTest
public class PartnerLeadControllerTestClass {
    
    static testMethod void leadscontroller()
    {        
        Account myaccount = new Account (name='Test');
        insert myaccount;
        
        PageReference pageRef = Page.PartnerleadList;
        pageRef.getparameters().put('recordId', myaccount.Id);  
        Test.setCurrentPage(pageRef);
        
        Apexpages.StandardController sc = new Apexpages.StandardController(myaccount);
        PartnerLeadController partlead = new PartnerLeadController(sc);   
        partlead.getlead();
        partlead.initlead();
    }
   
}
I have written the eblow code to display partner leads. Can u fix the error for me and help  me in writing test class for the same

Apex class
public class PartnerLeadController {
    public class PartnerLeadsController {
    
    private final Lead l;
    
    public PartnerLeadsController(ApexPages.StandardController stdController) {
        this.l = (Lead)stdController.getRecord();
        initlead();
    }
    
    List<Lead> lead;
    
    public void initlead() {
        lead = [select id,OwnerId,Owner.Name,Status,LastName from Lead where Partner_Name__c = :l.id AND  LeadSource=: 'Partner' ORDER BY Name DESC];
    }
    
    public List<Lead> getlead () {
        return lead;
    }   
    
}

           

}

Vf page

public class PartnerLeadController {
    public class PartnerLeadsController {
    
    private final Lead l;
    
    public PartnerLeadsController(ApexPages.StandardController stdController) {
        this.l = (Lead)stdController.getRecord();
        initlead();
    }
    
    List<Lead> lead;
    
    public void initlead() {
        lead = [select id,OwnerId,Owner.Name,Status,LastName from Lead where Partner_Name__c = :l.id AND  LeadSource=: 'Partner' ORDER BY Name DESC];
    }
    
    public List<Lead> getlead () {
        return lead;
    }   
    
}

           

}

User-added image
I have written a test class to create PDF but logic is not working can anyone help me with the test class

Apex Class

public class QuotePDF {
    public boolean show{get;set;}
    public id pdtId{get;set;}
    public Quote op{get;set;}
    public QuoteLineItem oli{get;set;}
    public string pb{get;set;}
    public Id opid{get;set;}
    public id prodid{get;set;}
    public list<QuoteLineItem> OliList{get;set;}
    public list<Quotelineitem> OliCreate;
    public integer deleteIndex{get;set;}
    
    public QuotePDF()
    {
        show=false;
        oli=new QuoteLineItem();
        op=new Quote();
        OliList=new list<QuoteLineItem>();
        OliCreate=new list<Quotelineitem>();
    }
    
    public void save(){
        pricebook2 spbid=[select id from pricebook2 where isStandard=true limit 1];
        
        opportunity o1=[select id from opportunity limit 1];
        op.OpportunityId=o1.id;
        op.Pricebook2Id=spbid.id;
        upsert op;
        map<id,id>pdtTopbemap=new map<id,id>();
        
        for(pricebookentry pb:[select product2id,id from pricebookentry where pricebook2id =:spbid.id ])
        {
            pdtTopbemap.put(pb.product2id,pb.id);
        }
        for(QuoteLineItem o:OliList)
        {
            o.QuoteId=op.id;
            o.unitprice=o.unitprice; 
            o.quantity=o.quantity;
            o.pricebookentryid=pdtTopbemap.get(o.product2id);
            o.Product2Id=o.product2id;
            OliCreate.add(o);
        }
        insert OliCreate;
    }
    public void AddOli()
    {
        show=true;
        QuoteLineItem olitemp = new QuoteLineItem();
        OliList.add(olitemp);
    }
    
    public void deleteOpp()
    {
        OliList.remove(deleteIndex);
    }
}

Test Class

@isTest
Public class QuoteApexClassTest {
    @isTest public static void QuoteApextestMethod() {
        Opportunities__c opp = new Opportunities__c();
        opp.Name = 'TestOpp';
        opp.Close_Date__c = System.today() + 5;
        opp.Stage__c = 'Prospecting';
        Insert opp;
        
        Quotes__c q = new Quotes__c();
        q.Name = 'test';
        q.OpportunityId__c = opp.Id;
        Insert q;
        
        ApexPages.StandardController sc = new ApexPages.StandardController(q);
        PageReference pageRef = Page.QuoteTemplate;
        pageRef.getParameters().put('id', String.valueOf(q.Id));
        Test.setCurrentPage(pageRef);
        
        QuoteApexClass qac = new QuoteApexClass(sc);        
        qac.saveQuoteAsPDFandEmail();
         
        qac.print();
    } 
}
Can Anyone help me with the test class and make the code coverage to 100%

Apex class

public class QuotePDF {
    public boolean show{get;set;}
    public id pdtId{get;set;}
    public Quote op{get;set;}
    public QuoteLineItem oli{get;set;}
    public string pb{get;set;}
    public Id opid{get;set;}
    public id prodid{get;set;}
    public list<QuoteLineItem> OliList{get;set;}
    public list<Quotelineitem> OliCreate;
    public integer deleteIndex{get;set;}
    
    public QuotePDF()
    {
        show=false;
        oli=new QuoteLineItem();
        op=new Quote();
        OliList=new list<QuoteLineItem>();
        OliCreate=new list<Quotelineitem>();
    }
    
    public void save(){
        pricebook2 spbid=[select id from pricebook2 where isStandard=true limit 1];
        
        opportunity o1=[select id from opportunity limit 1];
        op.OpportunityId=o1.id;
        op.Pricebook2Id=spbid.id;
        upsert op;
        map<id,id>pdtTopbemap=new map<id,id>();
        
        for(pricebookentry pb:[select product2id,id from pricebookentry where pricebook2id =:spbid.id ])
        {
            pdtTopbemap.put(pb.product2id,pb.id);
        }
        for(QuoteLineItem o:OliList)
        {
            o.QuoteId=op.id;
            o.unitprice=o.unitprice; 
            o.quantity=o.quantity;
            o.pricebookentryid=pdtTopbemap.get(o.product2id);
            o.Product2Id=o.product2id;
            OliCreate.add(o);
        }
        insert OliCreate;
    }
    public void AddOli()
    {
        show=true;
        QuoteLineItem olitemp = new QuoteLineItem();
        OliList.add(olitemp);
    }
    
    public void deleteOpp()
    {
        OliList.remove(deleteIndex);
    }
}

Test Class

@isTest
Public class QuoteApexClassTest {
    @isTest public static void QuoteApextestMethod() {
        Opportunity opp = new Opportunity();
        opp.Name = 'TestOpp';
        opp.CloseDate = System.today() + 5;
        opp.StageName = 'Prospecting';
        Insert opp;
        
        Quote q = new Quote();
        q.Name = 'test';
        q.OpportunityId = opp.Id;
        Insert q;
        

       ApexPages.StandardController sc = new ApexPages.StandardController(q);
        PageReference pageRef = Page.QuoteTemplate;
        pageRef.getParameters().put('id', String.valueOf(q.Id));
        Test.setCurrentPage(pageRef);
    
        QuoteApexClass qac = new QuoteApexClass(sc);        
        qac.saveQuoteAsPDFandEmail();
        qac.attachPDF();
        qac.getShowPrintLink();
        qac.print();
    }
}

User-added image