I need to send an email notification to the record owner and manager once the opportunity is closed-won.
adding only owner email works fine
adding only manager email works fine
But if I add both together with coma, {!$Record.Owner.Email},{!$Record.Engagement_Manager__r.Email} I'm getting error.
what is the correct way to add it?
You can try creating a Formula Resource in your flow like this but, in your case, using $Record.Owner.Email and $Record.Engagement_Manager__r.Email:
Then, you can use this Resource in your Email Action:
Try the below code and let me know if it works.
global class SendPurchaseOrderEmail {
WebService static void sendEmail(String poId) {
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
String theTemplate = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Purchase_Order_With_Items'].Id;
User theUser = [SELECT Id FROM User WHERE Name = 'user name goes here'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSaveAsActivity(false);
mail.setTemplateId(theTemplate);
mail.setWhatId(poId);
mail.setTargetObjectId(theUser.Id);
mail.setToAddresses(new String[] { 'TestUser#salesforce.com' ,'abc#test.com'}); //add other emails here.
emails.add(mail);
Messaging.sendEmail(emails);
}
}
Please refer below link for more details.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_sendemail.htm
This is because you have to pass a direct email address there.
Instead of that, you can create a collection variable, store the emails into it, then pass that variable to email addresses (collection) field.
Note: you can only store upto 5 emails into that colllection variable at a time.
Hi For that you can simply add collection Variable.
For that variable assign multiple values to it. So that you can send email to both record owner as well as manager.
From New Resource Select the Variable and click Allow Multiple Values and Data-type as text.
Then by using Assignment. Add the following email Address to it Please refer the below image.
I hope you have got the solution
Thanks
Related
I just started learning Apex recently, and there's still a lot of topics that are hard for me to navigate at this time. I've searched everywhere for a solution that works, but I still haven't been able to figure it out.
I've created a button on my Salesforce org that renders a PDF from a visualforce page, and attaches it to the record as a File. This is to be used with Docusign later on to capture signatures for contracts. The problem is that, when using merge fields in the VF page, they either do not show at all, or I get this exception: "sObject row was retrieved via SOQL without querying the requested field".
Now, the exception explicitly says that I need to query the fields, and this is what I've found I need to do to make this work, but I have not been able to figure out how to do this properly. I've tried running a query in several places in my controller extension to no avail (I am using a standardController that SF created for my custom object).
Here's my extension's code:
public class attachPDFToQuote {
public final i360__Quote__c q {get; set;} //Quote object
//constructor
public attachPDFToQuote (ApexPages.StandardController stdController) {
q = (i360__Quote__c)stdController.getRecord();
/* for(i360__Quote__c query:[SELECT Id, Correspondence_Name__c, Name FROM i360__Quote__c WHERE Id=: q.Id]){
System.debug(i360__Quote__c.Correspondence_Name__c);
}*/
}
public PageReference attachPDF() {
/* for(i360__Quote__c query:[SELECT Id, Correspondence_Name__c, Name FROM i360__Quote__c WHERE Id=: q.Id]){
System.debug(i360__Quote__c.Correspondence_Name__c);
}*/
//generate and attach the PDF document
PageReference pdfPage = Page.ProjectAgreement;
Blob pdfBlob; //create a blob for the PDF content
if (!Test.isRunningTest()) { //if we are not in testing context
pdfBlob = pdfPage.getContent(); //generate the pdf blob
} else { //otherwise, we are in testing context. Create the blob manually.
pdfBlob = Blob.valueOf('PDF');
}
ContentVersion cvAttach = new ContentVersion(ContentLocation= 'S');
cvAttach.PathOnClient= 'Project Agreement.pdf';
cvAttach.Title= 'Project Agreement';
cvAttach.VersionData= pdfBlob;
insert cvAttach;
Id conDoc = [SELECT ContentDocumentID FROM ContentVersion WHERE Id=: cvAttach.Id].ContentDocumentId;
ContentDocumentLink ConDocLink = new COntentDocumentLink();
conDocLink.LinkedEntityId= q.Id;
conDocLink.ContentDocumentId= conDoc;
conDocLink.ShareType= 'V';
insert conDocLink;
//redirect the user
PageReference pageWhereWeWantToGo = new ApexPages.StandardController(q).view(); //redirect the User back to the Quote detail page
pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side
return pageWhereWeWantToGo; //send the User on their way
}
}
I kept the commented code where I try to query the object fields so they show in VF. I also tried a couple of different ways, but nothing seems to work. Please let me know if I need to add anything else.
Thank you!
You didn't post your Visualforce page's code.
Even if it's same page (if your apex class is used in ProjectAgreement VF as <apex:page standardController="i360__Quote__c" extensions="attachPDFToQuote" - the act of grabbing a PDF version of the page counts as callout, a separate http traffic to fresh instance of the page so to speak.
So I suspect you need something like
PageReference pdfPage = Page.ProjectAgreement;
pdfPage.getParameters().put('id', q.Id);
Blob = pdfPage.getContent();
If that works... next step would be to look at your VF code.
If the page has merge fields such as {!i360__Quote__c.Name}, {!i360__Quote__c.Correspondence_Name__c} then magic should happen. Salesforce should figure out which fields are needed by looking at your VF page and silently query them for you. So you wouldn't even need the query in your constructor, you could just save stdController.getId() to class variable and then use that id in pdfPage.getParameters().set(...)
But if your VF page has references to {!quote.Correspondence_Name__c} then you need to keep the explicit query in there.
Currently we are re-running the test when a Test Fails using TestNG iRetryAnalyzer.
Problem that we are facing is:
We have a Test to 'Add a user'. For the first time after adding a user, in the process of checking the success message exception occurred (Timeout/NosuchElement) etc But the user is added in the database.
Now again when we re-run the test with same data, the Test Fails as user is already Added.
How can i overcome this??
As here the Data, the user email id unique field. Atleast I should be able to change the Email Id when im re-running it for the second time.
Please help me.
If you just need to create a unique, fake email address that you don't need to actually use, you can always append a date/time stamp to some base email you get from your DataProvider:
#Test(dataProvider = "dp")
public void emailTest(String userName, String emailShortname) {
//Get the current time
long time = System.currentTimeMillis();
//append it to the email from your DataProvider
StringBuilder emailBuilder= new StringBuilder();
emailBuilder.append(emailShortname).append("_").append(time).append("#gmail.com");
//do user creation code below using emailBuilder result...
I would say that if you are going to do these sorts of tests using Selenium, you're going to fill up your database with junk test IDs, so I'd suggest your team create a mechanism to clean these out either as part of the test run or after it.
Ideally, if there is a way to delete a user. You should use that in the #aftertest method and remove that user.
This way the next time you will be again able to use the same email id irrespective of the test is successful or not.
If not and if the email id is never verified ( I mean like some confirmation email which you use to confirm the user) you can create fake email id on the fly like xyz123#gmail.com. If the email id is verified then i guess you are in trouble.
i use the php framework cakePHP to create a web app. There,i want the user to insert in a field as many email addresses as he desires and by hitting the Send button,a message would be emailed to all of the emails.
To achieve that,i have to use bcc.
My problem is that i do not know how can i "read" from the user his email addresses in the right form so that i use them in bcc.
Till now,i have a variable $to = $this->request->data['Mail']['to']; ,where 'Mail' is my model name,and in case the user inserts just one email address,the recipient receives the mail correctly. But how can i enable it to receive multiple email addresses (maybe in an array??) so that i use the variable $to at this piece of code:
$Email = new CakeEmail();
$Email->from($from)
->**bcc($to)**
->subject($subject)
->send($message);
and help is welcomed :)
thank you in advance!
There is the API ( http://api.cakephp.org/2.3/class-CakeEmail.html#_addBcc ) and the code is open source. They all provide the information you are looking for.
If you open the class CakeEmail you will find ( https://github.com/cakephp/cakephp/blob/master/lib/Cake/Network/Email/CakeEmail.php#L482 ):
public function addBcc()
which is different from bcc() since it can be used multiple times to add multiple bcc addresses.
I am developing a site in Visualforce and would like to offer user a simple form to send me feedback via email. There would be 3-4 fields like name, user's email, reason and feedback and "send" button. Clicking the send button should automatically send that message to my email address.
I do not want to store the form data in salesforce at least for now...All the stuff I found online about visualforce/apex and email is about saving that data to salesforce too.
Can I just make use of apex's email capabilities and send out email without storing that data anywhere in salesforce?
Thanks,
Calvin
It's not required to insert/update/delete any records in the database when executing an action on a VisualForce page. You can leverage the Outbound Email functionality to send out your notification. For something like this, you will probably want to familiarize yourself with the SingleEmailMessage methods.
A simple example to get you going:
public PageReference actionSend() {
String[] recipients = new String[]{'myemailaddress#somedomain.com'};
Messaging.reserveSingleEmailCapacity(recipients.size());
Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
msg.setToAddresses(recipients);
msg.setSubject('Test Email Subject');
msg.setHtmlBody('Test body including HTML markup');
msg.setPlainTextBody('Test body excluding HTML markup');
msg.setSaveAsActivity(false);
msg.setUseSignature(false);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {msg}, false);
return null;
}
If you are interested in sending these outbound messages from a dedicated email address (something like noreply#somecompany.com), you can set these up through the Setup -> Administration Setup -> Email Administration -> Organization-Wide Addresses menu. Once you have created an org-wide address, grab the Id from the URL and use the setOrgWideEmailAddressId(Id) method on your instance of Messaging.SingleEmailMessage.
Is there somthing in the dotnetnuke framework which will allow me to pass it a userId and it would return the UserInfo object filled with details of that userId.
If not what would be the normal way of doing this?
Try this (in DNN 5.x with C#)
private UserInfo _currentUser =
DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
Then use the UserInfo later...
int UserID = _currentUser.UserID
I used the way posted by bdukes with one modification: PortalId can be get from PortalSettings:
DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUser(PortalSettings.PortalId, user_id, true);
To get the current user, as of version 7.3 all of the above have been deprecated. Now you need to use access the user info via the Instance property and the GetCurrentUserInfo() method, i.e.:
DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo()
Hence you could get the UserId as so:
DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo().UserID
So, given a user id, you could get the user's info like this:
UserController.GetUserById(PortalId,your_user_id)
Note that PortalId is a property provided by the DNN context, so you can simply type it as above.
I hope this helps.
I believe that DotNetNuke.Entities.Users.UserController has a method (GetUser) that will do that, if you also have a portal ID. Users can be shared across portals, so it's (apparently) necessary to know the portal for which you're requesting the user information before they can properly fill the UserInfo object.
If you only have a user ID and no portal ID, I'd first suggest that you see if you can get a portal ID, too. If not, you'll need to go to the database to get what you need. Ideally, you'll be in there as little as you can be (since the database isn't a guaranteed API). So, if you just do a quick query to get a portal ID for the user:
SELECT PortalID From {databaseOwner}{objectQualifier}UserPortals WHERE UserID = #userId
You can then use UserController.GetUser to retrieve what you need.
It's not return User ID what is the problem
Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo
response.write(nowUser)
If you need to get the current user it's simpler:
Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo
Just a note.