You need to sign in to do that
Don't have an account?
Suresh_SFDC
Opportunity related account contact Email Validation using formula
Hi,
How to write a formula Opportunity related account contact Email field is populated or notbecause i have a custom button on opportunity detail page when i clik on that button i want to validate opportunity has account, account has contact,contact email has populated.
in my on click java script custom button these contact fields are not available to check
my idea is to write a formula on account,contact email using this formula i want to validate in button
If you want to validate email on all contacts then you may follow one of below methods
1) You can directly query Contacts of Account form Java script
var Contacts = sforce.connection.query("SELECTId,Name,email FROM Contact WHERE Id = Opportunity.AccountId") ;
You can compare no of contacts and no of contacts having email in Java script.
2) Create 2 number fields No Of Contacts, No Of Contacts have email on Account object. Populate these fields by using contact trigger(u can find this code easily in google).(If Account fields are not available on bjava script, then by using formula fields get these 2 fields in to Opportunities). Now compare two fields in your Java script.
Thanks Prasd. Am using your code in my button like
{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
var o = new sforce.SObject("Opportunity");
var result = sforce.connection.query(" select a.Id, a.Name, a.Industry, " +
" (select c.LastName, c.LeadSource, c.Email from a.Contacts c) " +
" from account a WHERE a.Id = {!Opportunity.AccountId} ");
var its = new sforce.QueryResultIterator(result);
o.id ="{!Opportunity.Id}";
o.StageName="{!Opportunity.StageName}";
if ( o.StageName != 'Closed Won' )
{
alert("You are not allowed StageName without Closed Won");
}
else
{
window.open('/apex/CreateOrder?aid={!Account.Id }&oid={!Opportunity.Id}');
}
Am getting below Error! Can you please help what am worng?
Thanks in advance
var result = sforce.connection.query(" select Id, Name, Industry, " +
" (select LastName, LeadSource, Email from Contacts) " +
" from account WHERE Id = {!Opportunity.AccountId} ");
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
var o = new sforce.SObject("Opportunity");
var result = sforce.connection.query(" select Id, Name, Industry, " +
" (select LastName, LeadSource, Email from Contacts) " +
" from account WHERE Id = {!Opportunity.AccountId} ");
Your code is not clear. You are querying Contcat records, but no where you are refering that.In the code given above you r not checking email of contacts. Paste your entire code here along with your clear requirement .