Skip to main content
salman khan が「#Customer Service」で質問
my Visualforce Page:

 

    <apex:page standardController="Account" extensions="AccountListViewController" recordSetVar="accounts" >

 

<apex:form >

 

 <apex:pageBlock >

 

    <apex:pageBlockSection title="Select User">

 

        <apex:inputField value="{!userId.ownerId}"/>

 

    </apex:pageBlockSection>

 

<apex:commandButton value="Send Email" action="{!SendEmail}"/>

 

 </apex:pageBlock>

 

</apex:form>

 

</apex:page>

 

->My controller

 

public with sharing class AccountListViewController {

 

    Public Account userId{set;get;}

 

    List<Account> selectedList;

 

    public AccountListViewController(ApexPages.StandardSetController controller) {

 

       userId=new Account();

 

    selectedList=(List<Account>)controller.getSelected();

 

    

 

    system.debug('selectedList--------------------'+selectedList);

 

     

 

    }

 

    

 

    public void SendEmail(){

 

    

 

    User u=[select email from user where id=:userId.ownerId];

 

    

 

    System.debug('========================='+u);

 

   

 

    

 

    //Messaging.SingleEmailMessage msg=new Messaging.SingleEmailMessage();

 

    

 

    //msg.setSubject('Selected Records');

 

    //msg.setToAddresses();

 

    //msg.setToAddresses(new String[] {u.email});

 

    //msg.setPlainTextBody(selectedList);

 

    

 

    

 

    

 

    

 

    }

 

}

 

Here I want to send selected records to user as per selected user in visualforce Page through mail But .I was getting Nullpointer exception .please let me know what i did mistack in my code

 

 
2 件の回答
  1. 2016年1月28日 14:01
    ++Sunil,

     

    SInce you have asked,Let me answer this.

     

    You have nowhere assigned userId a value..

     

    Also,You have nowhere add ed a null check.

     

    I have done soem modfictaion in the code :

     

     

    <apex:page standardController="Account" extensions="AccountListViewController" recordSetVar="accounts" >

    <apex:form >

    <apex:pageBlock >

    <apex:pageBlockSection title="Select User">

    <apex:inputField value="{!userId.ownerId}"/>

    </apex:pageBlockSection>

    <apex:commandButton value="Send Email" action="{!SendEmail}"/>

    </apex:pageBlock>

    </apex:form>

    </apex:page>

    ->My controller

    public with sharing class AccountListViewController {

    Public Account userId{set;get;}

    List<Account> selectedList;

    public AccountListViewController(ApexPages.StandardSetController controller) {

    userId=new Account();

    selectedList=(List<Account>)controller.getSelected();

    system.debug('selectedList--------------------'+selectedList);

    if(SelectedList.size()>0)

    {

    userId=SelectedList[0];

    }

    }

    public void SendEmail(){

    if(userID.ownerID!=NULL)

    User u=[select email from user where id=:userId.ownerId];

    System.debug('========================='+u);

    //Messaging.SingleEmailMessage msg=new Messaging.SingleEmailMessage();

    //msg.setSubject('Selected Records');

    //msg.setToAddresses();

    //msg.setToAddresses(new String[] {u.email});

    //msg.setPlainTextBody(selectedList);

    }

    }

     

     

     

    For any Programmatic questions related to this, Please submit to the developer forums at

     

     https://developer.salesforce.com

     

    http://salesforce.stackexchange.com/

     

    where the forums and participants are geared toward programming troubleshooting and support and the users there focus on code so you may get quicker answers as well as a wider variety of options.

     

    PS: Please Mark a best answer as well so that this thread is closed. Let's keep our community clean

     

    ++Sunil, SInce you have asked,Let me answer this. You have nowhere assigned userId a value.. Also,You have nowhere add ed a null check.
0/9000