How to write a complex reference to objects in email templates for Salesforce - salesforce

I need to create a reference in an email template. for that I need to reffer a standard Contact objecect. For that I have a Custom Object Email Info, that has a lokup to standard Accounts.
So in the email I have to have value of the custom field Email_info__c from the custom object Email_info__c(the object and it's field have the same API names) while entering the Contact.
In the end both Contacts and my custom object have the lookups to Account, but not to each other, and there is no lookup from Acount, for now.
My first guess was to refer to the first child object Email info in the header of the VF template
relatedToType="Email_Info__c"
and then refer to it in the body as
{!RelatedTo.Account_r}
but then I would need a lookup from Accounts to Email Info to be able to refer deeper
{!RelatedTo.Account_r.Email_Info__r.Email_Info__c}
but, I don't think that it'll work that way or that it meets the needed criteria. Can someone share if there is an option at all to get the Email Info to Contacts through Accounts without creating a lookup on Accounts?
The task is to have a middle referred object, not a direct lookup:

It depends a bit how you are going to use this email template. What will the send be triggered from. Account? Contact? Email Info record? Will it be fired from a workflow or user will be instructed to navigate to account record and start composing the message?
If your relatedTo is really Email_Info__c then you don't have to do anything, you have all the data hidden in {!relatedTo.Id}, {!relatedTo.Name}, {!relatedTo.Email_Info__c} (you said the field name is same as object's name)
If your email starts from "Account" and you can guarantee accounts will have 1 email info record on related list - something like this might work:
<messaging:emailTemplate subject="hi stack" recipientType="Contact" relatedToType="Account">
<messaging:plainTextEmailBody >
{!relatedTo.Opportunities[0].Id} {!relatedTo.Opportunities[0].Name} {!relatedTo.Opportunities[0].StageName} {!relatedTo.Opportunities[0].CloseDate}
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
from Account (relatedTo) I'm going down to the related list of Opportunities, I'm picking 1st one (at random... but if you have just 1 record it'll be fine) and display whatever I want.
If your relatedTo and recipient both have to be Contact it starts to get bit messier, normal visualforce syntax will not allow you to go "up" (from Contact to Account) and then "down" (from Account to related list of email infos)
You'd need to start with something like https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_templates_with_apex.htm and then figure out how to pass the Id of account to it and run a query for email infos related to this account. https://salesforce.stackexchange.com/questions/245930/pass-id-from-visualforce-email-template-to-controller might be a good start, poke me if you're stuck.

Related

Salesforce Email logging on custom object

could really use some serious help on this. Below is the current business case:
We have the standard accounts, contacts, and opportunities objects. We've also created a custom object, and let's call it 'Customers.'
As of now, 'customers' are related to accounts.
Our users have einstein activity capture on, so all the email interactions get logged to the 'Account' level that the contact is related to, which makes sense.
The problem is that I want those emails tracked on the 'Customer' activity feed too, not just the 'Account' or 'Contact' activity feed.
Will creating a junction object between contacts and customers allow this activity to be shown in the 'customer' field? Or is there a simpler way to do this? Thank you in advance as this is a major roadblock I am facing right now.
I haven't worked with Einstein Activity Capture yet. What does it save stuff as? EmailMessage? Task? Either allows adding custom fields so you could add lookup to your Customer__c. With Task it's even simpler, it has that mutant lookup thing, Customer should appear as available option if it has "Allow Activities" ticked in setup.
Assuming that gives you something - next step would be to maybe make a custom quick action with some fields prepopulated, maybe a trigger to go "up" to Account and then to Customer(s)... Because out of the box
https://help.salesforce.com/articleView?id=aac_limitations.htm&type=5
Custom objects aren’t supported. When emails are sent from a custom
object, the email is logged on the activity timeline of the associated
contact.
You can upvote an idea: https://trailblazer.salesforce.com/ideaView?id=0873A000000EAIiQAO

Sales Force sending email to non user with template from custom object

I'm need to create email in Sales Force with the recipient as a custom object rather than a User, Contact or Person. Unfortunately, it appears my client has created a custom object for the entity we need to contact.
I tried several methods in the UI and they have all ended up needing a User or Contact record to succeed.
I'm now using APEX code in a trigger, it also requires a User, but I have managed to get past that using this work around: Sending Emails in Salesforce to Non-Contacts Using Apex
Now I need to pass my custom object into the Email Template to get the merge fields from it.
I believe setWhatId is the correct approach, but it returns "Invalid entity type for whatId".
Not sure where to turn now....
In short, I have a custom object that is not a user or a contact, but it does have a related custom object with an email address field (also not user or contact).
I need to send an email to the email address recorded on the related custom object passing the custom object to the template to gain its merge fields.
Any help or guidance would be much appreciated. Can I even do this?
Best Regards,
Rod
From your comment and without knowing much more, the relationship traversal should look like this:
Contact c = [select id, Email from Contact where id=q.Client__r.Participant_Portal_Contact__r.id limit 1];
Assuming that the email address field is on a parent object you dont need to do this with code you can probably do this using a Visualforce Email template and the relatedTo set to the object with the details you want to use as merge fields. That way you can use it in workflow or process builder or flows without the need for code

Salesforce field level access determined by third variable

For the contacts object, I have a custom checkbox which represents whether the contact owner wants the contact information (email and phone) to be visible. Most of our contacts will be completely visible to everyone. However, for a few contacts, we want them to be visible but their contact information needs to be hidden to everyone except for the owner.
Is there a way to set field-level access dependent on another variable? Could you create a workflow to redirect to another page layout if the contact information is visible? If so, can you restrict objects to certain field layouts depending on whether or not you are the record owner? And would would the contact information for "hidden contacts" still show up in reports?
Redirects, custom Visualforce view page etc hacks are all nice and shiny until you realize people will be able to pull data they want via some reports, list views, Outlook integration, mobile apps etc ;)
There's no straightforward answer because field visibility is really "all or nothing" (by Profiles & Permission Sets). Owner/Role-related stuff will help you only if you'd store data in some new related objects.
Another option - Store public part in Leads (public read only for example) and sensitive part - in Contacts (private)? Some lookup to link the 2, maybe a trigger when new Contact is created and you're good to go.
Last but not least - have a look at https://salesforce.stackexchange.com/questions/777/can-i-grant-different-field-level-security-based-on-record-ownership for some ideas.
If I understood correctly (My english...) You could create a new RecordType and a new customized page layout without this fields assigned to it, then you have to create a WFR that change the Recordtype when the cheked field becomes true.
I'm assuming that you know how you have to give permissions to this new Recordtype...etc
Hope this helps.

relate an object in salesforce with multiple objects

1) I have created a custom object "Hello".
Added two lookup fields to it, one is associated to Accounts and another to Leads.
2) now my custom object appears as a related list in both Account and lead
3) if i goto an account say "**Test_account**" >> i click on the new button
on the "Hello" related list.here i have redirected to a custom
visualforce page "**Welcome**".
Now I want that on my "Welcome Page" I want to display 2 fields.
If user reached this "Welcome Page" via hello related list in accounts then label on this page is set to Accounts
but
If user reached this "Welcome Page" via hello related list in leads then label on this page is set to Leads.
I dont know how to do this.
I can get the retURL in the currentpage URL but it gives me only the id.
Now I am not sure this id belongs to Accounts or Leads.
Accounts nad leads are just examples,there could be many more ojects.
By looking at the first three characters of the id, you can tell the type of object. For example, all Accounts start with '001' and all Leads start with '00Q'. You can get all the key prefixes from the DescribeSObjectResult in either Apex or the Web Services API. The API also returns this in the DescribeGlobalResult, which is handy if you want to load all the key prefixes in one call. The REST API also has the key prefix, but you'd have to traverse all the objects to get to it.

Get a Google App Engine user by their user_id

In GAE, can you look up a User with the User object's user_id?
In other words, is there something equivalent to:
from google.appengine.api.users import User
user = User.get_by_id(user_id)
I don't think so.
... they certainly wouldn't just give you access to every holder of a google account!
The idea is that you store user ids as properties in your datastore, once they've logged in to your app.
There is a property type called UserProperty
http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html
So, you can query your list of users from your own datastore definition.
hth
This seems to be the only post on the internet regarding this and since I was looking for a solution, I thought I'd post what I found here.
What amir75 said about using the UserProperty is fine for storing the User object itself returned by the google.appengine.users module.
But if you need to lookup a User by the user_id field instead of the default email field, usually something like user = User(email = 'validmail#gmailorgapps.com')
You can use this to query by user_id. user = User(_user_id = 'validuserid') The valid user_id is something that you got earlier from calling user.user_id()
I'm not sure what amir75 is referring to about having access to all google accounts since the User object returned will only have the email address and nickname, and that too only if the user authorizes the application to access that information.
My use case for this is I want people to sign up on the site, but they need an administrator to confirm them for using the site. The form used by the administrator for confirming the users can use email id as the field to identify the checkbox for confirming the user, but given that it might change, the user_id seems to be a safer field to use.

Resources