• Sumit Mishra 47
  • NEWBIE
  • 30 Points
  • Member since 2022

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
Hi Everyone,

I have created apex class to pull multiple object records into single list. Where objects does not have any relationship (lets say account, contact, lead. Consider account and contact dont have any relationship). I used for loop seperately for each object and saved into wrapperlist. For threee objects I have three wrapper list. Now big challenge is I need to add three wrappers(wrapAccount, wrapContact, wrapLead)  into single list. So in that list I need all three objects records.

-------------------------------------------------------------------------
@Auraenabled(cacheable=true)  
    public static List<sObject> wrapData() {
        List<WrapperContact> wrapContact = new List<WrapperContact>();
        List<WrapperAccount> wrapAccount = new List<WrapperAccount>();
        List<WrapperLead> wrapLead = new List<WrapperLead>();
        
       
        
        for(Contact ct : [select id, name from Contact LIMIT 10]){          
            wrapContact.add(new WrapperContact(ct));            
        }
        for(Account acct : [select id, name from Account LIMIT 10]){          
            wrapAccount.add(new WrapperAccount(acct));            
        }
        for(Lead ld : [select id, name from Lead LIMIT 10]){          
            wrapLead.add(new WrapperLead(ld));            
        }
        system.debug('wrapContact'+wrapContact);
        system.debug('wrapAccount'+wrapAccount);
        system.debug('wrapLead'+wrapLead);
     List<SObject> s = new List<SObject>{
            new Contact(),
            new Account(),
            new Lead()            
        };
   //     s.add(wrapContact);
   //     s.addAll(wrapAccount);
   //         system.debug(s);
        List<sObject> objects = new List<sObject>();
    //    objects.addAll((List<sObject>)(wrapContact));
      //    objects.addAll((List<sObject>)(wrapAccount));
   //     objects.addAll(wrapLead);
          return objects;
     
    }



     public class WrapperAccount{
                
        @Auraenabled
        public Account ac{get;set;}
         
        public WrapperAccount(Account acct){
            ac=acct;
        }
        
    }

     public class WrapperContact{
        @Auraenabled
        public Contact cont{get;set;}
              
        public WrapperContact(Contact ct){
            cont=ct;
        }
                      
    }

     public class WrapperLead{
               
        @Auraenabled
        public Lead ldd{get;set;}
            
        public WrapperLead(Lead ld){
            ldd=ld;
        }
    }    

----------------------------------------------------------------------
I have used List<SObject> s = new List<SObject>{
            new Contact(),
            new Account(),
            new Lead()            
        };
   //     s.add(wrapContact);
   //     s.addAll(wrapAccount);
         s.addAll(wrapLead);
   //         system.debug(s);
But its not working. Please help me out of this.
Thanks in Advance
class--------1
public class createApprovalURL {
public static String generateApprovalURL(String recordID){
         String url='';
         List<ProcessInstanceWorkitem> workItemLst;
    workItemLst = [SELECT id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId=:recordID];
            if(workItemLst.size() > 0){
               url='https://'+ System.URL.getSalesforceBaseUrl().getHost() +   
    '/p/process/ProcessInstanceWorkitemWizardStageManager?id=' + workItemLst[0].id;
            }
    System.debug(url);
        return url;
      }
}

class2----
public class cls_CmpApprovalURL{
    //public Id myId {get;set;}
    //myId = apexpages.currentpage().getparameters().get(id);
    //System.debug(myId)
    public String recID {get; set;}
    public String urlStr{
        get{
            return createApprovalURL.generateApprovalURL(recID);
        }
    }
}
  • October 19, 2022
  • Like
  • 0
Hi Everyone,

I have created apex class to pull multiple object records into single list. Where objects does not have any relationship (lets say account, contact, lead. Consider account and contact dont have any relationship). I used for loop seperately for each object and saved into wrapperlist. For threee objects I have three wrapper list. Now big challenge is I need to add three wrappers(wrapAccount, wrapContact, wrapLead)  into single list. So in that list I need all three objects records.

-------------------------------------------------------------------------
@Auraenabled(cacheable=true)  
    public static List<sObject> wrapData() {
        List<WrapperContact> wrapContact = new List<WrapperContact>();
        List<WrapperAccount> wrapAccount = new List<WrapperAccount>();
        List<WrapperLead> wrapLead = new List<WrapperLead>();
        
       
        
        for(Contact ct : [select id, name from Contact LIMIT 10]){          
            wrapContact.add(new WrapperContact(ct));            
        }
        for(Account acct : [select id, name from Account LIMIT 10]){          
            wrapAccount.add(new WrapperAccount(acct));            
        }
        for(Lead ld : [select id, name from Lead LIMIT 10]){          
            wrapLead.add(new WrapperLead(ld));            
        }
        system.debug('wrapContact'+wrapContact);
        system.debug('wrapAccount'+wrapAccount);
        system.debug('wrapLead'+wrapLead);
     List<SObject> s = new List<SObject>{
            new Contact(),
            new Account(),
            new Lead()            
        };
   //     s.add(wrapContact);
   //     s.addAll(wrapAccount);
   //         system.debug(s);
        List<sObject> objects = new List<sObject>();
    //    objects.addAll((List<sObject>)(wrapContact));
      //    objects.addAll((List<sObject>)(wrapAccount));
   //     objects.addAll(wrapLead);
          return objects;
     
    }



     public class WrapperAccount{
                
        @Auraenabled
        public Account ac{get;set;}
         
        public WrapperAccount(Account acct){
            ac=acct;
        }
        
    }

     public class WrapperContact{
        @Auraenabled
        public Contact cont{get;set;}
              
        public WrapperContact(Contact ct){
            cont=ct;
        }
                      
    }

     public class WrapperLead{
               
        @Auraenabled
        public Lead ldd{get;set;}
            
        public WrapperLead(Lead ld){
            ldd=ld;
        }
    }    

----------------------------------------------------------------------
I have used List<SObject> s = new List<SObject>{
            new Contact(),
            new Account(),
            new Lead()            
        };
   //     s.add(wrapContact);
   //     s.addAll(wrapAccount);
         s.addAll(wrapLead);
   //         system.debug(s);
But its not working. Please help me out of this.
Thanks in Advance
Hi,

I have a requirement to enter input fields on one Visualforce page and show the output of the same field on another visual force page.

below are my Visualforce page code and apex code.

Visualforce page 1:
<apex:page standardController="Vendors_Detail__c" extensions="Vendorhandler" id="page" >
        <!-- Javascript -->
    <script type="text/javascript">
    
    function nameValidation(id)
    {
         if(id == 'page:form:pb:pdf'){
        this.clickMe();
        }
         if(id == 'page:form:pb:save'){
        this.amtValidation();
        }
        
        var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        var a = document.getElementById('{!$Component.page.form.pb.pbs.amtevent}');
         var c = document.getElementById('{!$Component.page.form.pb.pbs.city}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.country}');
        
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
        else if (a.value == ""){
            amtValidation();
            return false;
            }
            else if (b.value == "" || c.value == ""){
            clickMe();
            return false;
            }
                 
        }
    
  function amtValidation()
    {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.amtevent}');
        var savebtn = document.querySelector("[id$='save']");
        
        if(a.value == "" )
        {
            alert("Enter Amount to show Send Email Button");
            savebtn.style.visibility = 'hidden';
            return false;
        }
        else
        {
            save();   
        }
        }
    
function clickMe()
     {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.city}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.country}');
        var pdfbtn = document.querySelector("[id$='pdf']");
        
        if(a.value == "" )
        {
            alert("Enter state to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
          
        }
        else if(b.value == "")
        {
            alert("Enter Country to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
       
        }
        else
        {
            clickme();
        }
    }
   
    </script>
<!-- Javascript -->
    
    <apex:form id="form">
     <apex:pageBlock id="pb" >
        <apex:actionFunction action="{!save}" name="save" reRender="form"/>
        <apex:actionFunction action="{!clickme}" name="clickme" reRender="form"/>
        <apex:actionFunction name="toggleButton" reRender="op"/>
         <apex:param name = "paramName" value = "Value To be pass"/>
      <apex:pageBlockSection id="pbs" title="Vendor Registration Form" columns="2">
          <apex:inputText id="name" value="{!vendor.Vendor_Company_Name__c}" label="Vendor Company Name" required="true"/>
          <apex:inputText id="cperson" value="{!vendor.Vendor_Contact_Person__c}" label="Vendor Contact Person"/>
          <apex:inputText id="amtevent" value="{!vendor.Amount_Per_Event__c}" label="Amount Per Event" onchange="toggleButton()"/>
          <apex:inputText id="city" value="{!vendor.City__c}" label="City" onchange="toggleButton()"/>
          <apex:inputText id="country" value="{!vendor.Country__c}" label="Country" onchange="toggleButton()"/>
      </apex:pageBlockSection>
        
        <apex:outputPanel id="op">
        <apex:commandButton id="save" action="{!save}" value="Send Email" onclick="return nameValidation(this.id);"/>
        <apex:commandButton id="reset" action="{!reset}" value="Reset"  ></apex:commandButton>
        <apex:commandButton id="pdf" action="{!clickme}" value="Generate PDF" onclick="return nameValidation(this.id);"/>
        </apex:outputPanel>
        
     </apex:pageBlock>
    </apex:form>
   
</apex:page>
Apex Code:
public with sharing class Vendorhandler {
    public Vendors_Detail__c vendor {get; set;}
    
    public Vendorhandler(ApexPages.StandardController std) {
        vendor = (Vendors_Detail__c) std.getRecord();
    }   

    public PageReference save(){
        
        insert vendor;
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'sasanjayt@gmail.com'};
        mail.setToAddresses(toAddresses);
        String emailSub = 'Vendor Registration Details';
                mail.setSubject(emailSub);
        String content = 'Vendor Company name = ' + vendor.Vendor_Company_Name__c + ',<br/><br/>'+ 
                              ' Vendor Contact person = ' + vendor.Vendor_Contact_Person__c + ',<br/><br/>' + 
                              'Amount per Event = ' + vendor.Amount_Per_Event__c + ',<br/><br/>' + 
                              'City = '+ vendor.City__c + ',<br/><br/>'+
                              'Country = '+ vendor.Country__c + '.<br/><br/>'+
                              '<br/><br/>Thank you <br/><br/>';
        mail.setHtmlBody(content);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
       
        return null;
        
    }
    public PageReference reset() {
        PageReference newpage = new PageReference(System.currentPageReference().getURL());
        newpage.getParameters().clear();
        newpage.setRedirect(true);
        return newpage;
    }
    
     public PageReference clickme(){
         insert vendor;
         PageReference newpage = Page.Vendor_Regidtration_form_pdf;
         newpage.setRedirect(true);
        //Vendors_Detail__c v = new Vendors_Detail__c();
        // v.Vendor_Company_Name__c = vendor.Vendor_Company_Name__c;
         //v.Vendor_Contact_Person__c = vendor.Vendor_Contact_Person__c;
         //v.Amount_Per_Event__c = vendor.Amount_Per_Event__c;
         //v.City__c = vendor.City__c;
         //v.Country__c = vendor.Country__c;
         return newpage;
         
         
    }
    
}

VisualFrce page 2:
<apex:page standardController="Vendors_Detail__c" extensions="Vendorhandler" renderAs="PDF">
    <apex:form>
        <apex:pageBlock title="Vendor Registration Form" >
            <apex:pageBlockSection>
                <apex:outputField value="{!vendor.Vendor_Company_Name__c}" label="Vendor Company Name"/>
            </apex:pageBlockSection>
 
        </apex:pageBlock>
    </apex:form>
</apex:page>

Kindly help me in accessing the values of input fields of page 1 to output field of page 2.

Thanks & Regards,
Sanjay Vinayak T

 
Hello, I'm working on the Quick start: Lightning web component trail and when it comes to setting up vscode with salesforce I've been trying for the past  24 hours to no avail. Things  have and have tried so far
  • JDK 17 from oracle platform(intsalled and unistalled 3 times so far)
  • Salesfore CLI(used the link directly from salesforce and installed/uninstalled twice already
  • set the jdk path in the appropriate field in vscode
  • installed and uninstalled Salesforce extension pac (probably a gazillion times now)
  • updated vscode to latest version/ updated salesforce CLI just to make sure
Despite all these, once i create a dx project and wait a few minutes, i get some dx commands(pic attached), but nothing on create lightning web component or aura components.

Also, for my first try, when i tried to authorize org, it went through and i can see my classes but the other times, authorization goes through but i've stopped seeing anything from my org show up. Also, prettier keeps showing an error.

i've read every related issue so far and it still won't give. Someone suggested checking running extensions and i can see from here that apex is unresponsive, which is why i have installed and uninstalled the salesforce extension pac a gazillion times and it still has the same issue

Notes:
  • I use windows 10 OS
  • I have had VsCode installed previously as I have been using it for software development prior to salesforce, so I have other extensions and customizations done, Node, Tailwind and whatnot.
We have a requirement where an email (Visualforce) is sent to the customer and they can either reply Accept or Reject and that response is captured in salesforce and based on that we are sending a reverse email using salesforce sites which has an Visualforce page for Accept and Reject response.
 
Currently we are facing an issue where a customer is able to accept or reject multiple times. So, to avoid that we want to show a message to the customer that "Your response is already captured".
 
How can this be achieved? 

 

This is just some example code, I don't want the focus of what I'm doing to cloud the concept I'm trying to figure out.

 

code:

 

sobject[] something = [SELECT Contact.FirstName, Contact.Account.Name, contact.account.type from Contact];

 

I've used sobject[] here instead of contact[] because in my project the query is dynamic and could be from a different table.

 

My question is, how do I get the relationship field from this? Normally, I know you can do this:

 

string theName = something[0].Account.Name;

 

However, this results in the error: Field expression not allowed for generic SObject

 

How do I get around this?

  • April 29, 2012
  • Like
  • 1