Skip to main content
Bramhaiah Bethamcherla 님이 #Apex에 질문했습니다
Hi,

I am very new to salesforce,i have tried below example am not succeded ,please find the error and code details below here.

Thanks in Adavace.

Apex class:

private final List<Id> Contactids;

    public List<Contact> Con;

    public MassEmail(Apexpages.standardController Controller)

    {

        con=[select Id from Contact limit 250];

        if(con!=null ||!con.isEmpty()){

            for(Integer i=0;i<250;i++){

                Contactids.add(con[i].Id);

                System.debug('contact Ids are:'+Contactids);

            

            }

        }

    }

        public void sendEmailCustom()

        {

            Messaging.MassEmailMessage mail=new Messaging.MassEmailMessage();

            if(Contactids!=null ||!Contactids.isEmpty()){

                mail.setTargetObjectIds(Contactids);

                Messaging.sendEmail(new Messaging.MassEmailMessage[]{mail});

            }

            

        }

    

VF Page:

<apex:page standardController="Contact" extensions="MassEmail" >

    <apex:form>

     <apex:commandButton value="Click" action="{!sendEmailCustom}"/>   

        

    </apex:form>

</apex:page>

Please help me on this, unable resolve this issue.
답변 3개
  1. 2016년 10월 1일 오전 7:44
    Bramha,

    it would be better to check for email in contacts.What if your query returns a cotact that don't have any email address?

    So I modified query.

    Try this

    private final List<Id> Contactids;

    public List<Contact> Con;

    public MassEmail(Apexpages.standardController Controller)

    {

    con=[select Id from Contact limit 250 where email!=null];

    if(con!=null ||!con.isEmpty()){

    for(Integer i=0;i<250;i++){

    Contactids.add(con[i].Id);

    System.debug('contact Ids are:'+Contactids);

    }

    }

    }

    public void sendEmailCustom()

    {

    Messaging.MassEmailMessage mail=new Messaging.MassEmailMessage();

    if(Contactids!=null ||!Contactids.isEmpty()){

    mail.setTargetObjectIds(Contactids);

    Messaging.sendEmail(new Messaging.MassEmailMessage[]{mail});

    }

    }

    Let me know if you have any issues.

    Mark it as best answer if it works./

    Thanks.

     
0/9000