You need to sign in to do that
Don't have an account?
Newbie: Is there a way to query Contact's Email by ReportsToId?
Dear all,
as many, I've just started coding for Visualforce. I have achieved to get a Lookup Field in my CUSTOM CONTROLLER where I can select a Contact. by digging deep into the web.
The only value I have been able to pull from that field is ReportsToId - which is - Ive looked it up - somekind of data object. The value I get in return is a string (e.g. 0031100000FAWcUAAX), though - which I cannot use to query for the Contact's Email Address (which will then be used for some Template Modification and Sending out those modified templates).
Maybe there is a way to convert that string back into something that can be used to do the SOQL Query.
One last thing: The Lookup field is mandatory. Obviously there are other possibilities, but it is a requirement.
Here is my custom controller:
[code]
public class Teszt2 {
// creating dummy apex property
public Contact con {get;set;}
// creating dummy method
public String getcon() {
return null;
}
public String contactEmail {get; set;}
public List<Contact> contactDetails {get; set;}
//List<Contact> contactDetails = new List<Contact>();
public pagereference searchdata()
{
//you can fetch dummy lookup field vale here and process accordingly.
System.debug('@@@@@@@@@@@'+con.ReportsToId);
contactDetails = [SELECT Name, Firstname, Email FROM Contact WHERE ReportsToId=:con.ReportsToId AND AccountId = :ApexPages.currentPage().getParameters().get('id')];
contactEmail = con.ReportsToId; //contactDetails[0].Email;
return null;
}
public Teszt2()
{
// instantiate your dummy object
con = new Contact();
}
}
[/code]
And heres the page:
[code]
<apex:page controller="Teszt2">
<apex:form >
<apex:inputField value="{!con.ReportsToId}" label="CustomerTo" id="CustomerTo" required="true"/>
<apex:commandButton action="{!searchdata}" rerender="EmailBody" id="search" value="search"/>
</apex:form>
Boooya
<b>Emailbody: </b><apex:outputText value="{!contactEmail}" id="EmailBody"></apex:outputText>
</apex:page>
[/code]
Thank you!
Thank you so far, it was late, so I am sorry for any confusion.
Alright, let's make things clearer and put them into perspective.
Above image is as far as I got from Scratch without any prior knowledge. Again, I am not using any standardController so far.
Top Select an Email Template (name, description, accepted types: txt, html)
Bottom Middle: Body of selected Email Templates gets inserted into Textarea which can be edited by the user
Bottom left: Lookup field for Contacts (basically using the code given in my first post, so I have a con.ReportsToId in the input field)
Goal: By selecting a Contact from the Lookup field, you can email the edited body to the Contact.
Where I got problems right now: getting a Lookup Contact Field and extracting the email address. ReportsToId seems to lead nowhere except that I get to display the Contacts I need.
<apex:inputField value="{!account.Contact}" /> did not work as expected:
Error: Could not resolve field 'Contact' from <apex:inputField> value binding '{!account.Contact}' in page
Which drove me mad, since I believed the error was my mistake as a Newbie.
It seems someone in the company must have tempered with the Field Contact....
<apex:inputField value="{!account.Contact__c}" /> did the trick, got a contact Lookup Field now. Yay!