String csvHeader = 'AccountId, Latest Opp \n'; string mainContent = csvHeader; Map opps = new Map(); for(Opportunity op: [select AccountId, Billing_Frequency__c,Customer_Type__c , closedate from Opportunity where closedate >2019-03-01 and closedate <2020-03-31 and StageName='Closed Won' order by closedate asc]){ opps.put(op.AccountId, op); } for (Id oid : opps.keySet()) { mainContent+= oid+','+opps.get(oid).Id+'\n'; } Messaging.SingleEmailMessage singEmail = new Messaging.SingleEmailMessage (); String [] toAddresses = new list {'ayub.salsforce@gmail.com'}; //Set recipient list singEmail.setToAddresses (toAddresses); String subject = 'Retroactively Created Agreements'; singEmail.setSubject (subject); singEmail.setPlainTextBody (mainContent); Messaging.SendEmailResult [] r = Messaging.sendEmail (new Messaging.SingleEmailMessage [] {singEmail});
175 thoughts on “Generate CSV using apex and email as attachment”
Comments are closed.
Very nice article, exactly what I wanted to find.
I enjoy what you guys are up too. This kind of clever work and exposure!
Keep up the awesome works guys I’ve added you guys to my personal blogroll.
After I originally commented I seem to have clicked the -Notify me when new comments are added-
checkbox and now every time a comment is added I receive 4 emails with the
exact same comment. There has to be a means you are able to remove me from
that service? Thanks a lot!
Thanks for the marvelous posting! I genuinely enjoyed reading it, you are a great author.
I will make certain to bookmark your blog and will eventually come back
later in life. I want to encourage you continue your great work, have a nice evening!
We are a group of volunteers and starting a brand new
scheme in our community. Your website offered us with helpful information to
paintings on. You have done a formidable task and our whole community shall be thankful to you.
My homepage … fahl.uk
Superb, what a blog it is! This web site presents useful facts
to us, keep it up.
I truly love your website.. Great colors & theme.
Did you create this site yourself? Please reply back as I’m attempting
to create my own personal site and want to learn where you got this from or just
what the theme is called. Appreciate it!
Thanks for another informative blog. Where else may I get that type of
info written in such a perfect method? I have a venture that I’m
just now operating on, and I’ve been at the look out
for such info.
Very nice article. I certainly appreciate this website.
Thanks!
It’s a pity you don’t have a donate button! I’d certainly donate
to this excellent blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account.
I look forward to new updates and will share this site with my Facebook group.
Talk soon!
Amazing! This blog looks just like my old one! It’s on a completely different topic
but it has pretty much the same page layout and design. Wonderful choice of colors!
Very nice post. I certainly appreciate this site.
Continue the good work!
Everyone loves it when individuals come together and share ideas.
Great site, continue the good work!
My relatives always say that I am wasting my time here at net,
except I know I am getting experience all the time by reading thes nice articles.
I think the admin of this website is actually working hard for his website, as here every data
is quality based stuff.
Also visit my website rftitanforge.com
Thank you, I’ve recently been looking for information about this topic
for ages and yours is the best I’ve found out so far. However, what in regards
to the bottom line? Are you positive concerning
the source?
hello!,I like your writing so much! share we be in contact more about your article
on AOL? I need a specialist in this area to resolve my problem.
May be that’s you! Taking a look ahead to
see you.
We are a bunch of volunteers and starting a brand new scheme in our community.
Your web site offered us with helpful info to work on. You’ve performed a formidable process and
our whole group will probably be thankful to you.
my web page fahl.uk
It’s remarkable to go to see this web site and reading the views of all mates
about this piece of writing, while I am also keen of getting experience.
Keep on writing, great job!