• srkSF
  • NEWBIE
  • 40 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 12
    Replies
Hi All,
I am new to Platform event based flows.So I am not able to understand how the platform event flow will run once we click "Debug" button to test the flow.As per my business requirement,there are 2 flows involved one is Scheduled flow and other one is Platform event flow.
Scheduled flow will just create a record to create a platform event.
Platform event has to execute the loop and if the loop limit is reached,update the records,create a platform event again,otherwise just update the records and exit.

I am getting the following error:
The flow failed to start because the provided values were not valid: You can't launch a platform event–triggered flow from within Flow Builder. To launch this flow, activate it and then publish an event message for the platform event that's configured in the Start element.


Any help is really appreciated.

Thanks
srk
  • May 07, 2022
  • Like
  • 0
Hi All,
I am getting 0% coverage in 3 classes,OrderExtension,OrderTrigger,OrderHelper.
My Tests are all passing but getting NullPointer Exception
in below code line highlighted.I dont know where I am doing mistake.
How do I correct this Error?
Please help!!!!
Thanks in Advance.

Product2Tests 
-----------------------------------------------------------
@isTest (seeAllData=false)
private class Product2Tests {
    
    /**
* @name product2Extension_UnitTest
* @description UnitTest for product2Extension
**/
    static TestMethod void Product2Extension_UnitTest(){
        
        PageReference pageRef = page.Product2New;
        Product2 prod = new Product2(Name='test', isActive= true);
        ApexPages.StandardController controller = new ApexPages.StandardController(prod);
        Test.startTest();
        Product2Extension ext = new Product2Extension(controller);
        System.assertEquals(Constants.DEFAULT_ROWS, ext.productsToInsert.size());
        ext.addRows();
        System.assertEquals(2*Constants.DEFAULT_ROWS, ext.productsToInsert.size());
        
        for(Integer i=0; i< Constants.DEFAULT_ROWS; i++) {
            
            Product2 newProduct = new Product2(Name='Product'+i, Initial_Inventory__c = 10, isActive=true, family= Constants.PRODUCT_FAMILY.get(math.mod(i,4)).getValue());
            ext.productsToInsert.get(i).productRecord = newProduct;
            
            PriceBookEntry entry = new PriceBookEntry(UnitPrice = 100, isActive=true);
            ext.productsToInsert.get(i).pricebookEntryRecord = entry;
            
        }
        ext.save();
        ext.GetFamilyOptions();
        ext.GetInventory();
        List<Product2> selectedProd = [Select id from Product2];
        System.assertEquals(Constants.DEFAULT_ROWS, selectedProd.size());
        Test.stopTest();
    }
    
    static TestMethod void Product2Trigger_UnitTest() {
        try{
        Test.startTest();
        Product2 newProduct = new Product2();
        newProduct.Name = 'Test';
        newProduct.Family = 'Dessert';
        newProduct.IsActive = true;
        newProduct.Quantity_Ordered__c = 5;
        newProduct.Initial_Inventory__c = 10;
        insert newProduct;
        
        CollaborationGroup c = new CollaborationGroup();
        c.Name = 'TEST' + Constants.INVENTORY_ANNOUNCEMENTS;
        c.Description = 'Description';
        c.CollaborationType = 'Public';
        insert c;
        
        newProduct.Quantity_Ordered__c=96;
        update newProduct;
        Test.stopTest();
        }catch(Exception e){
            System.debug('Exception has occurred '+e);
        }
    } 
    
}
  • February 11, 2022
  • Like
  • 0
Hi All,
UpcomingEvents query is fetching records  properly using Developer Console.But I am seeing just blank white card(LWC) only when I am clicking Home page.
Please help me!!!!!
User-added imageUser-added image
Apex Class:
--------------------------------------------------------------
public without sharing class EventListLWCService {
    @AuraEnabled(cacheable=true)
    public static List<Event__c> fetchUpcomingEvents(){
        List<Event__c> eventList=new List<Event__c>();
        try {
            eventList= [SELECT Id,Name,Name__c,CreatedDate,Event_Detail__c,Location__c,Location__r.Name,Event_Organizer__c,
                        Start_DateTime__c,End_Date_Time__c,Event_Organizer__r.Name,Event_Organizer__r.Email__c,Recurring__c,
                        Max_Seats__c,Status__c,Remaining_Seats__c,PeopleAttending__c
                        FROM Event__c
                        WHERE Start_DateTime__c >= Today AND Live__c = true
                        WITH SECURITY_ENFORCED
                        ];
           
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return eventList;
    }
    @AuraEnabled(cacheable=true)
    public static List<Event__c> fetchPastEvents(){
        List<Event__c> eventList=new List<Event__c>();
        try {
            eventList= [SELECT Id,Name,Name__c,CreatedDate,Event_Detail__c,Location__c,Location__r.Name,Event_Organizer__c,
            Start_DateTime__c,End_Date_Time__c,Event_Organizer__r.Name,Event_Organizer__r.Email__c,Recurring__c,
            Max_Seats__c,Status__c,Remaining_Seats__c,PeopleAttending__c
            FROM Event__c
            WHERE Start_DateTime__c <= Today AND Live__c = true
            WITH SECURITY_ENFORCED
         ];
           
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return eventList;
    }
   
}

HTML:
-----------------------------------------------
<template>
    <lightning-card variant="Narrow">
        <!--Upcoming Events-->
        <div class="slds-text-heading_large">Upcoming Events</div>
        <hr/>
        <lightning-layout multiple-rows>
            <lightning-layout-item size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">1
                </div>
            </lightning-layout-item>
            <lightning-layout-item  size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">2
                </div>
            </lightning-layout-item>
            <lightning-layout-item  size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">3
                </div>
            </lightning-layout-item>
            <template if:true={upComingEvents} for:each={upComingEvents} for:item="event" for:index="index">
            <lightning-layout-item key={event.Id} size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">
                <p>{event.Name__c}</p>
                <p>{event.Start_DateTime__c}</p>
                <p><lightning-formatted-rich-text value={event.Event_Detail__c}></lightning-formatted-rich-text></p>
                </div>
            </lightning-layout-item>
            </template>
        </lightning-layout>
        <!--Past Events-->
        <div class="slds-text-heading_large">Past Events</div>
        <hr/>
        <lightning-layout multiple-rows>
            <template if:true={pastEvents} for:each={pastEvents} for:item="event" for:index="index">
            <lightning-layout-item key={event.Id} size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">
                    <p>{event.Name__c}</p>
                    <p>{event.Start_DateTime__c}</p>
                    <p><lightning-formatted-rich-text value={event.Event_Detail__c}></lightning-formatted-rich-text></p>
            </div>
            </lightning-layout-item>
            </template>
        </lightning-layout>
    </lightning-card>
</template>
JavaScript file:
-----------------------------------------------------------------------
import { LightningElement, wire } from 'lwc';
import fetchUpcomingEvents from '@salesforce/apex/EventListLWCService.fetchUpcomingEvents';
import fetchPastEvents from '@salesforce/apex/EventListLWCService.fetchPastEvents';
export default class EventListComponent extends LightningElement {
    upcomingEvents;
    pastEvents;
    __errors;
    isSpinner=false;
    @wire(fetchUpcomingEvents)
    wiredUpcomingEventsData({ error, data }) {
      if (data) {
        console.log('Data', data);
        this.upcomingEvents=data;
      } else if (error) {
        console.error('Error:', error);
        this.upcomingEvents=undefined;
        this.__errors=error;
      }
    }
    @wire(fetchPastEvents)
    wiredPastEventsData({ error, data }) {
      if (data) {
        console.log('Data', data);
        this.fetchPastEvents=data;
      } else if (error) {
        console.error('Error:', error);
        this.fetchPastEvents=undefined;
        this.__errors=error;
      }
    }
}
Please let me know where i am doing wrong?

Thanks
 
  • February 02, 2022
  • Like
  • 0
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 getting 0% coverage in 3 classes,OrderExtension,OrderTrigger,OrderHelper.
My Tests are all passing but getting NullPointer Exception
in below code line highlighted.I dont know where I am doing mistake.
How do I correct this Error?
Please help!!!!
Thanks in Advance.

Product2Tests 
-----------------------------------------------------------
@isTest (seeAllData=false)
private class Product2Tests {
    
    /**
* @name product2Extension_UnitTest
* @description UnitTest for product2Extension
**/
    static TestMethod void Product2Extension_UnitTest(){
        
        PageReference pageRef = page.Product2New;
        Product2 prod = new Product2(Name='test', isActive= true);
        ApexPages.StandardController controller = new ApexPages.StandardController(prod);
        Test.startTest();
        Product2Extension ext = new Product2Extension(controller);
        System.assertEquals(Constants.DEFAULT_ROWS, ext.productsToInsert.size());
        ext.addRows();
        System.assertEquals(2*Constants.DEFAULT_ROWS, ext.productsToInsert.size());
        
        for(Integer i=0; i< Constants.DEFAULT_ROWS; i++) {
            
            Product2 newProduct = new Product2(Name='Product'+i, Initial_Inventory__c = 10, isActive=true, family= Constants.PRODUCT_FAMILY.get(math.mod(i,4)).getValue());
            ext.productsToInsert.get(i).productRecord = newProduct;
            
            PriceBookEntry entry = new PriceBookEntry(UnitPrice = 100, isActive=true);
            ext.productsToInsert.get(i).pricebookEntryRecord = entry;
            
        }
        ext.save();
        ext.GetFamilyOptions();
        ext.GetInventory();
        List<Product2> selectedProd = [Select id from Product2];
        System.assertEquals(Constants.DEFAULT_ROWS, selectedProd.size());
        Test.stopTest();
    }
    
    static TestMethod void Product2Trigger_UnitTest() {
        try{
        Test.startTest();
        Product2 newProduct = new Product2();
        newProduct.Name = 'Test';
        newProduct.Family = 'Dessert';
        newProduct.IsActive = true;
        newProduct.Quantity_Ordered__c = 5;
        newProduct.Initial_Inventory__c = 10;
        insert newProduct;
        
        CollaborationGroup c = new CollaborationGroup();
        c.Name = 'TEST' + Constants.INVENTORY_ANNOUNCEMENTS;
        c.Description = 'Description';
        c.CollaborationType = 'Public';
        insert c;
        
        newProduct.Quantity_Ordered__c=96;
        update newProduct;
        Test.stopTest();
        }catch(Exception e){
            System.debug('Exception has occurred '+e);
        }
    } 
    
}
  • February 11, 2022
  • Like
  • 0
Hi All,
UpcomingEvents query is fetching records  properly using Developer Console.But I am seeing just blank white card(LWC) only when I am clicking Home page.
Please help me!!!!!
User-added imageUser-added image
Apex Class:
--------------------------------------------------------------
public without sharing class EventListLWCService {
    @AuraEnabled(cacheable=true)
    public static List<Event__c> fetchUpcomingEvents(){
        List<Event__c> eventList=new List<Event__c>();
        try {
            eventList= [SELECT Id,Name,Name__c,CreatedDate,Event_Detail__c,Location__c,Location__r.Name,Event_Organizer__c,
                        Start_DateTime__c,End_Date_Time__c,Event_Organizer__r.Name,Event_Organizer__r.Email__c,Recurring__c,
                        Max_Seats__c,Status__c,Remaining_Seats__c,PeopleAttending__c
                        FROM Event__c
                        WHERE Start_DateTime__c >= Today AND Live__c = true
                        WITH SECURITY_ENFORCED
                        ];
           
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return eventList;
    }
    @AuraEnabled(cacheable=true)
    public static List<Event__c> fetchPastEvents(){
        List<Event__c> eventList=new List<Event__c>();
        try {
            eventList= [SELECT Id,Name,Name__c,CreatedDate,Event_Detail__c,Location__c,Location__r.Name,Event_Organizer__c,
            Start_DateTime__c,End_Date_Time__c,Event_Organizer__r.Name,Event_Organizer__r.Email__c,Recurring__c,
            Max_Seats__c,Status__c,Remaining_Seats__c,PeopleAttending__c
            FROM Event__c
            WHERE Start_DateTime__c <= Today AND Live__c = true
            WITH SECURITY_ENFORCED
         ];
           
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return eventList;
    }
   
}

HTML:
-----------------------------------------------
<template>
    <lightning-card variant="Narrow">
        <!--Upcoming Events-->
        <div class="slds-text-heading_large">Upcoming Events</div>
        <hr/>
        <lightning-layout multiple-rows>
            <lightning-layout-item size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">1
                </div>
            </lightning-layout-item>
            <lightning-layout-item  size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">2
                </div>
            </lightning-layout-item>
            <lightning-layout-item  size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">3
                </div>
            </lightning-layout-item>
            <template if:true={upComingEvents} for:each={upComingEvents} for:item="event" for:index="index">
            <lightning-layout-item key={event.Id} size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">
                <p>{event.Name__c}</p>
                <p>{event.Start_DateTime__c}</p>
                <p><lightning-formatted-rich-text value={event.Event_Detail__c}></lightning-formatted-rich-text></p>
                </div>
            </lightning-layout-item>
            </template>
        </lightning-layout>
        <!--Past Events-->
        <div class="slds-text-heading_large">Past Events</div>
        <hr/>
        <lightning-layout multiple-rows>
            <template if:true={pastEvents} for:each={pastEvents} for:item="event" for:index="index">
            <lightning-layout-item key={event.Id} size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">
                    <p>{event.Name__c}</p>
                    <p>{event.Start_DateTime__c}</p>
                    <p><lightning-formatted-rich-text value={event.Event_Detail__c}></lightning-formatted-rich-text></p>
            </div>
            </lightning-layout-item>
            </template>
        </lightning-layout>
    </lightning-card>
</template>
JavaScript file:
-----------------------------------------------------------------------
import { LightningElement, wire } from 'lwc';
import fetchUpcomingEvents from '@salesforce/apex/EventListLWCService.fetchUpcomingEvents';
import fetchPastEvents from '@salesforce/apex/EventListLWCService.fetchPastEvents';
export default class EventListComponent extends LightningElement {
    upcomingEvents;
    pastEvents;
    __errors;
    isSpinner=false;
    @wire(fetchUpcomingEvents)
    wiredUpcomingEventsData({ error, data }) {
      if (data) {
        console.log('Data', data);
        this.upcomingEvents=data;
      } else if (error) {
        console.error('Error:', error);
        this.upcomingEvents=undefined;
        this.__errors=error;
      }
    }
    @wire(fetchPastEvents)
    wiredPastEventsData({ error, data }) {
      if (data) {
        console.log('Data', data);
        this.fetchPastEvents=data;
      } else if (error) {
        console.error('Error:', error);
        this.fetchPastEvents=undefined;
        this.__errors=error;
      }
    }
}
Please let me know where i am doing wrong?

Thanks
 
  • February 02, 2022
  • Like
  • 0
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