• srkSF
  • NEWBIE
  • 40 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 10
    Replies
Hi All,
I am new to LWC and have a requirement.Based on the values entered by user in first LWC Component.display the list of records in second LWC Component.
I am trying to acheive this by making second one as Parent Component and first one as Child Component.
I need to make use of Event to pass the values entered by the user to run a SOQL query which will fetch the matching records available in the database.
How to write Event Code for this and also Apex class?
Please help me!!!
  • August 03, 2021
  • Like
  • 0
Hi All,
I am trying to pass values to parent component using event in LWC.
But I am not able to retrieve the fields and use in a SOQL query.
I am getting [Object,Object] as field value.
I am trying to to do JSON.stringify() also.It is showing this
{FieldApiName:{Guest_Hotel_City__c},ObjectApiName:{Guest_Master}}
I need value of that field Guest_Hotel_City__c to make use of it in SOQL query.
Please help!!
Thanks in Advance.
JS code:
import { LightningElement } from 'lwc';
export default class HotelListingComponent extends LightningElement {
    handlechildevent(event){
    const varcityofhotel=event.detail.cityofhotel;
    const varpreferredhoteltype=event.detail.preferredhoteltype;
    var myjson=JSON.stringify(varcityofhotel);
    console.log("value after stringifying:",myjson);
        
        alert('Event handled in Parent Comp');
        alert('Guest Hotel City is: '+varcityofhotel);
        alert('Guest Hotel Type is: '+varpreferredhoteltype);
    }
}
  • August 03, 2021
  • Like
  • 0
Hi All,
On click of "Generate PDF" button,I have to show VF Page in PDF format with renderAs attribute.
I am able to render VF Page in PDF format but field values are not added in pdf.How to achieve this?
Please help!!!!

VF Page:
<apex:page controller="VendorRegister" tabStyle="Vendor__c" renderAs="PDF" >
    <!-- Javascript -->
    <script type="text/javascript">

    function validate()
    {
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi1.vendorcompname}').value == '')
        {
            alert("Vendor name is mandatory");
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi2.amountperevent}').value == '')
        {
            document.getElementById('{!$Component.frm.pb.pbb.sendemail}').disabled = true;
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi3.city}').value == '' && 
           document.getElementById('{!$Component.frm.pb.pbs.pbsi4.country}').value == '')
        {
           document.getElementById('{!$Component.frm.pb.pbb.pdfbutton}').disabled = true;
        }
    }
   
    </script>
<!-- Javascript -->
    <apex:form title="Vendor Registration Form" id="frm">
        <apex:pageBlock id="pb">
            <apex:pageBlockSection id="pbs" >
                <apex:pageBlockSectionItem > 
                    <apex:outputLabel >Vendor Company Name</apex:outputLabel>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem id="pbsi1">
                    <apex:inputText value="{!vendorcompname}" id="vendorcompname" />
                </apex:pageBlockSectionItem>
                
                <apex:outputLabel >Vendor Contact Person</apex:outputLabel><br/>
                <apex:inputText value="{!vendorconperson}"/><br/>
                 <apex:pageBlockSectionItem >
                <apex:outputLabel >Amount per Event</apex:outputLabel><br/>
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem id="pbsi2">
                <apex:inputText value="{!amountperevent}" id="amountperevent"/><br/>
                    </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                <apex:outputLabel >City</apex:outputLabel><br/>
                </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem id="pbsi3">
                <apex:inputText value="{!city}" id="city"/><br/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                <apex:outputLabel >Country</apex:outputLabel><br/>
                 </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem id="pbsi4">
                <apex:inputText value="{!country}" id="country"/><br/>
                 </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockButtons id="pbb" location="bottom">
                
               
        <apex:commandButton id="sendemail" value="Send Email"
                            onclick="validate();"
                           />
        <apex:commandButton value="Reset" />                                        
        <apex:commandButton id="pdfbutton" value="Generate PDF"  />                                          
        </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    

</apex:page>
  • July 27, 2021
  • Like
  • 0
Hi All,
I have a requirement to generate SOQL 101 error  in a for loop.
Using for loop,generate 100+ SOQL in one transaction.
Generate 101 error.
Using future function,resolve this issue and perform 150 SOQL in one transaction.
Code below is not compiling.
Pls help!!!!

Apex Class:

public class SOQL101Error {
List<Student_Master__c> studentlist = new List<Student_Master__c>();
    studentlist = [SELECT id,Name,First_Name__c,Last_Name__c FROM Student_Master__c];
    for(Student_Master__c sm: studentlist){
       // string query =' select ID,Name from Account ';
    }

}

 
  • July 27, 2021
  • Like
  • 0
Hi All,
I need to write Test Method for the code which is iteration collection object allSubs(means allSubscriptions) in BOLD.
I am able to write Test code for getConForProduct method but stuck with the later part.
Please help me!!
Thanks in Advance.
Apex Class:
Global class getContactsMatrixOrders {
    public static List<Map<String, Id>> getConForProduct(Map<String, Id> allProducts){
        // This method will return contacts who are eligible for C031 & C041 Testing done
        List<Map<String, Id>> conAndPro = new List<Map<String, Id>>();
        List<OrderApi__Subscription__c> allSubs = [SELECT id , OrderApi__Contact__r.id , OrderAPi__Contact__r.AccountId,OrderApi__Contact__r.apfy_products_received__c 
                                                   , OrderApi__Subscription_Plan__r.Name,OrderApi__Item__r.Name
                                                   FROM OrderApi__Subscription__c 
                                                   WHERE OrderApi__Status__c = 'Active'
                                                   AND OrderApi__Contact__r.CUSTOMER_CLASS__c = 'Member' 
                                                   AND OrderApi__Contact__r.Customer_Status__c = 'Active' 
                                                   AND OrderApi__Contact__r.DonorApi__Spouse__r.CUSTOMER_CLASS__c = 'Member' 
                                                   AND OrderApi__Contact__r.DonorApi__Spouse__r.Customer_Status__c = 'DECEASED'
                                                   AND OrderApi__Sales_Order_Line__r.OrderApi__Sales_Order__r.OrderApi__Source_Code__r.Name = 'WIDOW'];
        System.debug('allSubs'+allSubs);
        
        for(OrderApi__Subscription__c sub : allSubs){
            String itemName = sub.OrderApi__Item__r.Name;
            Id conId = sub.OrderApi__Contact__r.id;
            Id accId = sub.OrderAPi__Contact__r.AccountId;
            String proReceived = sub.OrderApi__Contact__r.apfy_products_received__c;
            List<String> productsReceived = new List<String>();
            if(proReceived!=null){
                productsReceived = proReceived.split(',');
            }
            Map<String,Id> singleCon = new Map<String, Id>();
            if((itemName == 'BASIC Membership for Surviving Spouse' || itemName == 'PREMIUM Membership for Surviving Spouse') && !productsReceived.contains('C031')){
                singleCon.put('conId',conId);
                singleCon.put('accId',accId);
                singleCon.put('proId',allProducts.get('C031'));
                conAndPro.add(singleCon);
            }else if(itemName == 'LIFE Membership for Surviving Spouse' && !productsReceived.contains('C041')){
                singleCon.put('conId',conId);
                singleCon.put('accId',accId);
                singleCon.put('proId',allProducts.get('C041'));
                conAndPro.add(singleCon);

            }
            
        }
        return conAndPro;
    }
    
  
  • July 21, 2021
  • Like
  • 0
Hi All,
I am getting Null Pointer Exception: Attempting to de-reference a null object at this line only-----> DealsMap.put(deal.id,deal)

Screenshot of the Null Pointer Exception

User-added image

It's not displaying any values in tabular format from Map Collection in my VF Page also.
How do I fix this issue?Please help me!

Apex Class:

public with sharing class searchname1 {

    public PageReference edit() {
       
        return null;
    }

   public String name { get; set; }
    public list<Training_Deal__c> lstdeal { get; set; }
    public list<Course_Master__c> lstcourse { get; set; }
    public Map<id, Training_Deal__c> DealsMap { get; set; }
   
    
    public boolean searched{get;set;}
    
    //default constructor
    public searchname1(){
    searched=false;
    string namestr=apexpages.currentpage().getparameters().get('name');
    if(null!=namestr){
    name=namestr;
    }
               
    }
    public PageReference search() {
    searched=true;
     string searchstr1=('%'+name+'%');
         
           
        System.debug('-----------before for loop');
        try{
        for ( Course_Master__c crs : [select ID,Name,Course_Name__c,
                                      (select ID,Name,Course__c,Fees_Finalized__c from Training_Deals__r) from Course_Master__c 
            where Course_Name__c LIKE :searchstr1] ) {
                            for ( Training_Deal__c deal : crs.Training_Deals__r ) {
                                  System.debug(deal.Course__c + ' - ' + deal.Name + ' - ' + deal.Fees_Finalized__c );
                                 DealsMap.put(deal.id,deal);
                                 System.debug('Map of Deals-----'+DealsMap);  
                                }
                 
                            }
             System.debug('----------After for loop');   
        }catch(Exception e){
            System.debug('Exception occured'+e);
        }                    
          
              return null;
    }


    
}
VF Page:
<apex:page controller="searchname1" >
  <apex:form >
   <apex:pageblock id="one" >
    <apex:pageblockSection >
    <apex:pageblocksectionitem >
       <apex:outputlabel >Course to Search</apex:outputlabel>
         <apex:inputtext value="{!name}"/>
         </apex:pageblocksectionitem>
         <apex:commandButton value="Search" action="{!search}"/>
          </apex:pageblockSection>
      </apex:pageblock>       
           <apex:pageBlock id="SearchResults" rendered="{!searched}" >
               
           <!-- <apex:pageblocktable value="{!lstcourse}" var="c">
            <apex:column value="{!c.Name}"/>
                
             <apex:column value="{!c.Course_Name__c}"/>
            
               </apex:pageblocktable>
<apex:pageblocktable value="{!DealsMap}" var="d">
           
             <apex:column value="{!d.Name}"/>  
             <apex:column value="{!d.Course__c}"/>
             <apex:column value="{!d.Fees_Finalized__c}"/>     
            </apex:pageblocktable>
--> 
               

    <apex:pageBlock >
        <apex:repeat value="{!DealsMap}" var="d">
       {!d}<br/><br/>
         <apex:repeat value="{!DealsMap[d]}" var="d1">
        {!d1.name} <br/><br/>
         </apex:repeat>

    </apex:repeat>

               </apex:pageBlock>
        
   
     <apex:pageblockbuttons >
             <apex:commandButton value="edit" action="{!edit}"/>
            </apex:pageblockbuttons>
      </apex:pageBlock>
  </apex:form>
</apex:page>

 
  • July 13, 2021
  • Like
  • 1
Hi All,
I have a requirement to search Course Name in Visual force page.
I have to return all Training Deal Object values based on the course name entered in the search field value.
Course Master: Master Table
Training Deal:Detail Table

Training Deal has a master-detail datatype Course__c field
when I query the Training Deal table I get RecordID of the Course__c field instead of the Course Code value.
How to pass this RecordID in the query to Course Master and get the search results.
I have tried many combinations in below apex class....sorry for the messy looking queries..
VF Page
<apex:page controller="searchname1">
  <apex:form >
   <apex:pageblock id="one" >
    <apex:pageblockSection >
    <apex:pageblocksectionitem >
       <apex:outputlabel >Course to Search</apex:outputlabel>
         <apex:inputtext value="{!name}"/>
         </apex:pageblocksectionitem>
         <apex:commandButton value="go" action="{!search}"/>
          </apex:pageblockSection>
           </apex:pageBlock> 
           <apex:pageBlock rendered="{!searched}" >
            <apex:pageblocktable value="{!lstcourse}" var="c">
            <apex:column value="{!c.Name}"/>
             <apex:column value="{!c.Course_Name__c}"/>
            </apex:pageblocktable>
            <apex:pageblockbuttons >
             <apex:commandButton value="edit" action="{!edit}"/>
            </apex:pageblockbuttons>
               </apex:pageblock>
  </apex:form>
</apex:page>

Apex Class:

public with sharing class searchname1 {

    public PageReference edit() {
       
        return null;
    }


   
   public String name { get; set; }
    public list<Training_Deal__c> lstdeal { get; set; }
    public list<Course_Master__c> lstcourse { get; set; }
    
    public boolean searched{get;set;}
    
    //default constructor
    public searchname1(){
    searched=false;
    string namestr=apexpages.currentpage().getparameters().get('name');
    if(null!=namestr){
    name=namestr;
    }
    }
    public PageReference search() {
    searched=true;
     string searchstr1=('%'+name+'%');
      lstdeal=[select Name,Course__c from Training_Deal__c ];
      //lstcourse=[select Name,Course_Name__c from Course_Master__c where ID=:Training_Deal__c.Course__c];
    /* lstcourse= [select Name,Course_Name__c from Course_Master__c 
                 where Course_Name__c like :searchstr1 limit 10 ];
     for(Course_Master__c crs:lstcourse )
     {
         //coursecode=crs.Id
         lstdeal=[select Name,Course__c from Training_Deal__c where Course__c LIKE :crs.Course_Name__c ];
     }
     */
    //lstdeal=[select Name,Course__c from Training_Deal__c where Course__c like searchstr1 limit 10 ];
        return null;
    }


    
}
  • July 11, 2021
  • Like
  • 0
Hi All,
I have a requirement to search Course Name in Visual force page.
I have to return all Training Deal Object values based on the course name entered in the search field value.
Course Master: Master Table
Training Deal:Detail Table

Training Deal has a master-detail datatype Course__c field
when I query the Training Deal table I get RecordID of the Course__c field instead of the Course Code value.
How to pass this RecordID in the query to Course Master and get the search results.
I have tried many combinations in below apex class....sorry for the messy looking queries..
VF Page
<apex:page controller="searchname1">
  <apex:form >
   <apex:pageblock id="one" >
    <apex:pageblockSection >
    <apex:pageblocksectionitem >
       <apex:outputlabel >Course to Search</apex:outputlabel>
         <apex:inputtext value="{!name}"/>
         </apex:pageblocksectionitem>
         <apex:commandButton value="go" action="{!search}"/>
          </apex:pageblockSection>
           </apex:pageBlock> 
           <apex:pageBlock rendered="{!searched}" >
            <apex:pageblocktable value="{!lstcourse}" var="c">
            <apex:column value="{!c.Name}"/>
             <apex:column value="{!c.Course_Name__c}"/>
            </apex:pageblocktable>
            <apex:pageblockbuttons >
             <apex:commandButton value="edit" action="{!edit}"/>
            </apex:pageblockbuttons>
               </apex:pageblock>
  </apex:form>
</apex:page>

Apex Class:

public with sharing class searchname1 {

    public PageReference edit() {
       
        return null;
    }


   
   public String name { get; set; }
    public list<Training_Deal__c> lstdeal { get; set; }
    public list<Course_Master__c> lstcourse { get; set; }
    
    public boolean searched{get;set;}
    
    //default constructor
    public searchname1(){
    searched=false;
    string namestr=apexpages.currentpage().getparameters().get('name');
    if(null!=namestr){
    name=namestr;
    }
    }
    public PageReference search() {
    searched=true;
     string searchstr1=('%'+name+'%');
      lstdeal=[select Name,Course__c from Training_Deal__c ];
      //lstcourse=[select Name,Course_Name__c from Course_Master__c where ID=:Training_Deal__c.Course__c];
    /* lstcourse= [select Name,Course_Name__c from Course_Master__c 
                 where Course_Name__c like :searchstr1 limit 10 ];
     for(Course_Master__c crs:lstcourse )
     {
         //coursecode=crs.Id
         lstdeal=[select Name,Course__c from Training_Deal__c where Course__c LIKE :crs.Course_Name__c ];
     }
     */
    //lstdeal=[select Name,Course__c from Training_Deal__c where Course__c like searchstr1 limit 10 ];
        return null;
    }


    
}



 
  • July 11, 2021
  • Like
  • 0
Hi All,
I am getting Null Pointer Exception: Attempting to de-reference a null object at this line only-----> DealsMap.put(deal.id,deal)

Screenshot of the Null Pointer Exception

User-added image

It's not displaying any values in tabular format from Map Collection in my VF Page also.
How do I fix this issue?Please help me!

Apex Class:

public with sharing class searchname1 {

    public PageReference edit() {
       
        return null;
    }

   public String name { get; set; }
    public list<Training_Deal__c> lstdeal { get; set; }
    public list<Course_Master__c> lstcourse { get; set; }
    public Map<id, Training_Deal__c> DealsMap { get; set; }
   
    
    public boolean searched{get;set;}
    
    //default constructor
    public searchname1(){
    searched=false;
    string namestr=apexpages.currentpage().getparameters().get('name');
    if(null!=namestr){
    name=namestr;
    }
               
    }
    public PageReference search() {
    searched=true;
     string searchstr1=('%'+name+'%');
         
           
        System.debug('-----------before for loop');
        try{
        for ( Course_Master__c crs : [select ID,Name,Course_Name__c,
                                      (select ID,Name,Course__c,Fees_Finalized__c from Training_Deals__r) from Course_Master__c 
            where Course_Name__c LIKE :searchstr1] ) {
                            for ( Training_Deal__c deal : crs.Training_Deals__r ) {
                                  System.debug(deal.Course__c + ' - ' + deal.Name + ' - ' + deal.Fees_Finalized__c );
                                 DealsMap.put(deal.id,deal);
                                 System.debug('Map of Deals-----'+DealsMap);  
                                }
                 
                            }
             System.debug('----------After for loop');   
        }catch(Exception e){
            System.debug('Exception occured'+e);
        }                    
          
              return null;
    }


    
}
VF Page:
<apex:page controller="searchname1" >
  <apex:form >
   <apex:pageblock id="one" >
    <apex:pageblockSection >
    <apex:pageblocksectionitem >
       <apex:outputlabel >Course to Search</apex:outputlabel>
         <apex:inputtext value="{!name}"/>
         </apex:pageblocksectionitem>
         <apex:commandButton value="Search" action="{!search}"/>
          </apex:pageblockSection>
      </apex:pageblock>       
           <apex:pageBlock id="SearchResults" rendered="{!searched}" >
               
           <!-- <apex:pageblocktable value="{!lstcourse}" var="c">
            <apex:column value="{!c.Name}"/>
                
             <apex:column value="{!c.Course_Name__c}"/>
            
               </apex:pageblocktable>
<apex:pageblocktable value="{!DealsMap}" var="d">
           
             <apex:column value="{!d.Name}"/>  
             <apex:column value="{!d.Course__c}"/>
             <apex:column value="{!d.Fees_Finalized__c}"/>     
            </apex:pageblocktable>
--> 
               

    <apex:pageBlock >
        <apex:repeat value="{!DealsMap}" var="d">
       {!d}<br/><br/>
         <apex:repeat value="{!DealsMap[d]}" var="d1">
        {!d1.name} <br/><br/>
         </apex:repeat>

    </apex:repeat>

               </apex:pageBlock>
        
   
     <apex:pageblockbuttons >
             <apex:commandButton value="edit" action="{!edit}"/>
            </apex:pageblockbuttons>
      </apex:pageBlock>
  </apex:form>
</apex:page>

 
  • July 13, 2021
  • Like
  • 1
Hi All,
I am new to LWC and have a requirement.Based on the values entered by user in first LWC Component.display the list of records in second LWC Component.
I am trying to acheive this by making second one as Parent Component and first one as Child Component.
I need to make use of Event to pass the values entered by the user to run a SOQL query which will fetch the matching records available in the database.
How to write Event Code for this and also Apex class?
Please help me!!!
  • August 03, 2021
  • Like
  • 0
Hi All,
I am trying to pass values to parent component using event in LWC.
But I am not able to retrieve the fields and use in a SOQL query.
I am getting [Object,Object] as field value.
I am trying to to do JSON.stringify() also.It is showing this
{FieldApiName:{Guest_Hotel_City__c},ObjectApiName:{Guest_Master}}
I need value of that field Guest_Hotel_City__c to make use of it in SOQL query.
Please help!!
Thanks in Advance.
JS code:
import { LightningElement } from 'lwc';
export default class HotelListingComponent extends LightningElement {
    handlechildevent(event){
    const varcityofhotel=event.detail.cityofhotel;
    const varpreferredhoteltype=event.detail.preferredhoteltype;
    var myjson=JSON.stringify(varcityofhotel);
    console.log("value after stringifying:",myjson);
        
        alert('Event handled in Parent Comp');
        alert('Guest Hotel City is: '+varcityofhotel);
        alert('Guest Hotel Type is: '+varpreferredhoteltype);
    }
}
  • August 03, 2021
  • Like
  • 0
Hi All,
On click of "Generate PDF" button,I have to show VF Page in PDF format with renderAs attribute.
I am able to render VF Page in PDF format but field values are not added in pdf.How to achieve this?
Please help!!!!

VF Page:
<apex:page controller="VendorRegister" tabStyle="Vendor__c" renderAs="PDF" >
    <!-- Javascript -->
    <script type="text/javascript">

    function validate()
    {
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi1.vendorcompname}').value == '')
        {
            alert("Vendor name is mandatory");
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi2.amountperevent}').value == '')
        {
            document.getElementById('{!$Component.frm.pb.pbb.sendemail}').disabled = true;
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi3.city}').value == '' && 
           document.getElementById('{!$Component.frm.pb.pbs.pbsi4.country}').value == '')
        {
           document.getElementById('{!$Component.frm.pb.pbb.pdfbutton}').disabled = true;
        }
    }
   
    </script>
<!-- Javascript -->
    <apex:form title="Vendor Registration Form" id="frm">
        <apex:pageBlock id="pb">
            <apex:pageBlockSection id="pbs" >
                <apex:pageBlockSectionItem > 
                    <apex:outputLabel >Vendor Company Name</apex:outputLabel>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem id="pbsi1">
                    <apex:inputText value="{!vendorcompname}" id="vendorcompname" />
                </apex:pageBlockSectionItem>
                
                <apex:outputLabel >Vendor Contact Person</apex:outputLabel><br/>
                <apex:inputText value="{!vendorconperson}"/><br/>
                 <apex:pageBlockSectionItem >
                <apex:outputLabel >Amount per Event</apex:outputLabel><br/>
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem id="pbsi2">
                <apex:inputText value="{!amountperevent}" id="amountperevent"/><br/>
                    </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                <apex:outputLabel >City</apex:outputLabel><br/>
                </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem id="pbsi3">
                <apex:inputText value="{!city}" id="city"/><br/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                <apex:outputLabel >Country</apex:outputLabel><br/>
                 </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem id="pbsi4">
                <apex:inputText value="{!country}" id="country"/><br/>
                 </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockButtons id="pbb" location="bottom">
                
               
        <apex:commandButton id="sendemail" value="Send Email"
                            onclick="validate();"
                           />
        <apex:commandButton value="Reset" />                                        
        <apex:commandButton id="pdfbutton" value="Generate PDF"  />                                          
        </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    

</apex:page>
  • July 27, 2021
  • Like
  • 0
Hi All,
I need to write Test Method for the code which is iteration collection object allSubs(means allSubscriptions) in BOLD.
I am able to write Test code for getConForProduct method but stuck with the later part.
Please help me!!
Thanks in Advance.
Apex Class:
Global class getContactsMatrixOrders {
    public static List<Map<String, Id>> getConForProduct(Map<String, Id> allProducts){
        // This method will return contacts who are eligible for C031 & C041 Testing done
        List<Map<String, Id>> conAndPro = new List<Map<String, Id>>();
        List<OrderApi__Subscription__c> allSubs = [SELECT id , OrderApi__Contact__r.id , OrderAPi__Contact__r.AccountId,OrderApi__Contact__r.apfy_products_received__c 
                                                   , OrderApi__Subscription_Plan__r.Name,OrderApi__Item__r.Name
                                                   FROM OrderApi__Subscription__c 
                                                   WHERE OrderApi__Status__c = 'Active'
                                                   AND OrderApi__Contact__r.CUSTOMER_CLASS__c = 'Member' 
                                                   AND OrderApi__Contact__r.Customer_Status__c = 'Active' 
                                                   AND OrderApi__Contact__r.DonorApi__Spouse__r.CUSTOMER_CLASS__c = 'Member' 
                                                   AND OrderApi__Contact__r.DonorApi__Spouse__r.Customer_Status__c = 'DECEASED'
                                                   AND OrderApi__Sales_Order_Line__r.OrderApi__Sales_Order__r.OrderApi__Source_Code__r.Name = 'WIDOW'];
        System.debug('allSubs'+allSubs);
        
        for(OrderApi__Subscription__c sub : allSubs){
            String itemName = sub.OrderApi__Item__r.Name;
            Id conId = sub.OrderApi__Contact__r.id;
            Id accId = sub.OrderAPi__Contact__r.AccountId;
            String proReceived = sub.OrderApi__Contact__r.apfy_products_received__c;
            List<String> productsReceived = new List<String>();
            if(proReceived!=null){
                productsReceived = proReceived.split(',');
            }
            Map<String,Id> singleCon = new Map<String, Id>();
            if((itemName == 'BASIC Membership for Surviving Spouse' || itemName == 'PREMIUM Membership for Surviving Spouse') && !productsReceived.contains('C031')){
                singleCon.put('conId',conId);
                singleCon.put('accId',accId);
                singleCon.put('proId',allProducts.get('C031'));
                conAndPro.add(singleCon);
            }else if(itemName == 'LIFE Membership for Surviving Spouse' && !productsReceived.contains('C041')){
                singleCon.put('conId',conId);
                singleCon.put('accId',accId);
                singleCon.put('proId',allProducts.get('C041'));
                conAndPro.add(singleCon);

            }
            
        }
        return conAndPro;
    }
    
  
  • July 21, 2021
  • Like
  • 0
Hi All,
I am getting Null Pointer Exception: Attempting to de-reference a null object at this line only-----> DealsMap.put(deal.id,deal)

Screenshot of the Null Pointer Exception

User-added image

It's not displaying any values in tabular format from Map Collection in my VF Page also.
How do I fix this issue?Please help me!

Apex Class:

public with sharing class searchname1 {

    public PageReference edit() {
       
        return null;
    }

   public String name { get; set; }
    public list<Training_Deal__c> lstdeal { get; set; }
    public list<Course_Master__c> lstcourse { get; set; }
    public Map<id, Training_Deal__c> DealsMap { get; set; }
   
    
    public boolean searched{get;set;}
    
    //default constructor
    public searchname1(){
    searched=false;
    string namestr=apexpages.currentpage().getparameters().get('name');
    if(null!=namestr){
    name=namestr;
    }
               
    }
    public PageReference search() {
    searched=true;
     string searchstr1=('%'+name+'%');
         
           
        System.debug('-----------before for loop');
        try{
        for ( Course_Master__c crs : [select ID,Name,Course_Name__c,
                                      (select ID,Name,Course__c,Fees_Finalized__c from Training_Deals__r) from Course_Master__c 
            where Course_Name__c LIKE :searchstr1] ) {
                            for ( Training_Deal__c deal : crs.Training_Deals__r ) {
                                  System.debug(deal.Course__c + ' - ' + deal.Name + ' - ' + deal.Fees_Finalized__c );
                                 DealsMap.put(deal.id,deal);
                                 System.debug('Map of Deals-----'+DealsMap);  
                                }
                 
                            }
             System.debug('----------After for loop');   
        }catch(Exception e){
            System.debug('Exception occured'+e);
        }                    
          
              return null;
    }


    
}
VF Page:
<apex:page controller="searchname1" >
  <apex:form >
   <apex:pageblock id="one" >
    <apex:pageblockSection >
    <apex:pageblocksectionitem >
       <apex:outputlabel >Course to Search</apex:outputlabel>
         <apex:inputtext value="{!name}"/>
         </apex:pageblocksectionitem>
         <apex:commandButton value="Search" action="{!search}"/>
          </apex:pageblockSection>
      </apex:pageblock>       
           <apex:pageBlock id="SearchResults" rendered="{!searched}" >
               
           <!-- <apex:pageblocktable value="{!lstcourse}" var="c">
            <apex:column value="{!c.Name}"/>
                
             <apex:column value="{!c.Course_Name__c}"/>
            
               </apex:pageblocktable>
<apex:pageblocktable value="{!DealsMap}" var="d">
           
             <apex:column value="{!d.Name}"/>  
             <apex:column value="{!d.Course__c}"/>
             <apex:column value="{!d.Fees_Finalized__c}"/>     
            </apex:pageblocktable>
--> 
               

    <apex:pageBlock >
        <apex:repeat value="{!DealsMap}" var="d">
       {!d}<br/><br/>
         <apex:repeat value="{!DealsMap[d]}" var="d1">
        {!d1.name} <br/><br/>
         </apex:repeat>

    </apex:repeat>

               </apex:pageBlock>
        
   
     <apex:pageblockbuttons >
             <apex:commandButton value="edit" action="{!edit}"/>
            </apex:pageblockbuttons>
      </apex:pageBlock>
  </apex:form>
</apex:page>

 
  • July 13, 2021
  • Like
  • 1
Hi All,
I have a requirement to search Course Name in Visual force page.
I have to return all Training Deal Object values based on the course name entered in the search field value.
Course Master: Master Table
Training Deal:Detail Table

Training Deal has a master-detail datatype Course__c field
when I query the Training Deal table I get RecordID of the Course__c field instead of the Course Code value.
How to pass this RecordID in the query to Course Master and get the search results.
I have tried many combinations in below apex class....sorry for the messy looking queries..
VF Page
<apex:page controller="searchname1">
  <apex:form >
   <apex:pageblock id="one" >
    <apex:pageblockSection >
    <apex:pageblocksectionitem >
       <apex:outputlabel >Course to Search</apex:outputlabel>
         <apex:inputtext value="{!name}"/>
         </apex:pageblocksectionitem>
         <apex:commandButton value="go" action="{!search}"/>
          </apex:pageblockSection>
           </apex:pageBlock> 
           <apex:pageBlock rendered="{!searched}" >
            <apex:pageblocktable value="{!lstcourse}" var="c">
            <apex:column value="{!c.Name}"/>
             <apex:column value="{!c.Course_Name__c}"/>
            </apex:pageblocktable>
            <apex:pageblockbuttons >
             <apex:commandButton value="edit" action="{!edit}"/>
            </apex:pageblockbuttons>
               </apex:pageblock>
  </apex:form>
</apex:page>

Apex Class:

public with sharing class searchname1 {

    public PageReference edit() {
       
        return null;
    }


   
   public String name { get; set; }
    public list<Training_Deal__c> lstdeal { get; set; }
    public list<Course_Master__c> lstcourse { get; set; }
    
    public boolean searched{get;set;}
    
    //default constructor
    public searchname1(){
    searched=false;
    string namestr=apexpages.currentpage().getparameters().get('name');
    if(null!=namestr){
    name=namestr;
    }
    }
    public PageReference search() {
    searched=true;
     string searchstr1=('%'+name+'%');
      lstdeal=[select Name,Course__c from Training_Deal__c ];
      //lstcourse=[select Name,Course_Name__c from Course_Master__c where ID=:Training_Deal__c.Course__c];
    /* lstcourse= [select Name,Course_Name__c from Course_Master__c 
                 where Course_Name__c like :searchstr1 limit 10 ];
     for(Course_Master__c crs:lstcourse )
     {
         //coursecode=crs.Id
         lstdeal=[select Name,Course__c from Training_Deal__c where Course__c LIKE :crs.Course_Name__c ];
     }
     */
    //lstdeal=[select Name,Course__c from Training_Deal__c where Course__c like searchstr1 limit 10 ];
        return null;
    }


    
}



 
  • July 11, 2021
  • Like
  • 0