• Karunakar Burugu
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hi All,
I have a requirement to gather data using the below format from Account and opportunity. could you please help me how to achieve this format? I mean is it possible with collections?
 
Account NameOpportunity CreatedDateOpportunity Name
SamsungJan-22Opp1
  Opp2
  Opp3
AppleFeb-22Opp1
  Opp2
  Opp3
SamsungFeb-22Opp4
  Opp5
  Opp6
Please help me with the error detailed as in the comments section. I declared static variable and trying to add values in 'ProcessEmail" method but getting the error as explained in the comments in the code.

Also, trying to retrieve the List in Finish method, but assigned a null.
Code:
global class BatchController implements Database.Batchable<sObject>{
    
   public static List<Messaging.SingleEmailMessage> Emails;
   
    global Database.QueryLocator start(Database.BatchableContext bc){
       return Database.getQueryLocator([SELECT Id, Name, Client__r.Name, Status__c, Pri__c, NSR__c FROM scope__c
                                         WHERE Status__c IN (1,2,3) ]);  
    }
    
    global void execute(Database.BatchableContext bc, List<scope__c> scopeList){
        
        if(scopeList != NULL && scopeList.size() > 0){
            for(scope__c prc : scopeList){
                BatchController.processEmail(prc);               
            }
        }
    }
    
    global void finish(Database.BatchableContext bc){
            system.debug('Finish method '+ BatchController.Emails); // Error: This is printing null value, as this is the static variable and added values in 'processEmail' method.
              Messaging.SendEmailResult[] results = Messaging.sendEmail(BatchController.Emails, false);// Error : Internal Salesforce error
    }
    
    global static void processEmail(scope__c prc){
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        /* Some Custom Email Code to fill all the mail fields */
        
       
        BatchController.Emails.add(mail); //Error: |FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object
        System.debug('Process method '+ BatchController.Emails);
    } 
    
   
        
}
I am trying to learn Wrapper class in Salesforce development but I am getting the below error, could some one please help me te resolve this error.
Below are the error details, Apex code and VFPage code

Error:
Unknown property 'Wrapperclass.lstWrapperDisplay'

VFPage code:
<apex:page controller = "Wrapperclass">
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockSection>
                <apex:pageBlockTable value="{!lstWrapperDisplay}" var="w">
                    
                    <apex:column headerValue="Action">
                        <apex:inputCheckbox/>
                    </apex:column>
                    
                    <apex:column headerValue="Account Name">
                        {!w.accname}
                    </apex:column>
                    
                    <apex:column headervalue="Account Number">
                        {!w.accnum}
                    </apex:column>
                    
                    <apex:column headervalue="Industry">
                        {!w.accind}
                    </apex:column>
                    
                    <apex:column headervalue="Opportunity Name">
                        {!w.oppname}
                    </apex:column>
                    
                    <apex:column headervalue="Opportunity Amount">
                        {!w.oppamt}
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex class
public class Wrapperclass {
   public Wrapperclass(){
    lstAcc = new List<Account>();   
    lstOpp  = new List<Opportunity>();
   }

  //Name, accountnumber,Industry from Account
  //Name, ammount from opportunity
  //Instanitate List for Account, Opportunity
 
 public List<Account> lstAcc {get;set;}
 public List<Opportunity> lstOpp {get;set;}
    
  //List for Wrapper Class
 
 public List<Wrapper> lstw;
    
    public void lstWrapperDisplay(){
        lstAcc = [select name,accountnumber,Industry from Account];
        lstOpp = [select name,amount from Opportunity];
        
        for(integer i=0;i<lstOpp.size();i++){
            lstw.add(new Wrapper(lstAcc[i].name,lstAcc[i].accountnumber, lstAcc[i].Industry,lstOpp[i].name,lstOpp[i].amount));
                }
            //return lstw;
    }
 
    public class Wrapper{
        public String accname {set;get;}
        public String accnum {set;get;}
        public String accind {set;get;}
        public String oppname {set;get;}
        public Decimal oppamt {set;get;}

        
        public Wrapper(String accname, String accnum, String accind, String oppname, Decimal oppamt){
            this.accname = accname;
            this.accnum = accnum;
            this.accind = accind;
            this.oppname = oppname;
            this.oppamt = oppamt;
        }   
    }
}
I am trying to learn Wrapper class in Salesforce development but I am getting the below error, could some one please help me te resolve this error.
Below are the error details, Apex code and VFPage code

Error:
Unknown property 'Wrapperclass.lstWrapperDisplay'

VFPage code:
<apex:page controller = "Wrapperclass">
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockSection>
                <apex:pageBlockTable value="{!lstWrapperDisplay}" var="w">
                    
                    <apex:column headerValue="Action">
                        <apex:inputCheckbox/>
                    </apex:column>
                    
                    <apex:column headerValue="Account Name">
                        {!w.accname}
                    </apex:column>
                    
                    <apex:column headervalue="Account Number">
                        {!w.accnum}
                    </apex:column>
                    
                    <apex:column headervalue="Industry">
                        {!w.accind}
                    </apex:column>
                    
                    <apex:column headervalue="Opportunity Name">
                        {!w.oppname}
                    </apex:column>
                    
                    <apex:column headervalue="Opportunity Amount">
                        {!w.oppamt}
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex class
public class Wrapperclass {
   public Wrapperclass(){
    lstAcc = new List<Account>();   
    lstOpp  = new List<Opportunity>();
   }

  //Name, accountnumber,Industry from Account
  //Name, ammount from opportunity
  //Instanitate List for Account, Opportunity
 
 public List<Account> lstAcc {get;set;}
 public List<Opportunity> lstOpp {get;set;}
    
  //List for Wrapper Class
 
 public List<Wrapper> lstw;
    
    public void lstWrapperDisplay(){
        lstAcc = [select name,accountnumber,Industry from Account];
        lstOpp = [select name,amount from Opportunity];
        
        for(integer i=0;i<lstOpp.size();i++){
            lstw.add(new Wrapper(lstAcc[i].name,lstAcc[i].accountnumber, lstAcc[i].Industry,lstOpp[i].name,lstOpp[i].amount));
                }
            //return lstw;
    }
 
    public class Wrapper{
        public String accname {set;get;}
        public String accnum {set;get;}
        public String accind {set;get;}
        public String oppname {set;get;}
        public Decimal oppamt {set;get;}

        
        public Wrapper(String accname, String accnum, String accind, String oppname, Decimal oppamt){
            this.accname = accname;
            this.accnum = accnum;
            this.accind = accind;
            this.oppname = oppname;
            this.oppamt = oppamt;
        }   
    }
}