You need to sign in to do that
Don't have an account?
force shahid
How to fetch account from opportunity object ?
Hi Friends,
I Created a custom lookup field on Opportunity object to Contact object. I need to fetch the account details when i create new opportunity under contact object.
While creating new opportunity under contact object , ihave only contact details, but i need to fetch this particular contact account details also.
Code:
Set<Id> cId=new Set<Id>();
for(Opportunity opp : newList){
cId.add(opp.Primary_Broker__c);
}
List<Contact> Updcon = new List<Contact>();
List<Contact> con = [select id,AccountId,Open_Opportunities__c from Contact where Id in:cId ];
List<Opportunity > opportunity= [select id,Primary_Broker__c,StageName from Opportunity where Primary_Broker__c in:cId AND ( StageName NOT IN ('Closed Won','Closed Lost')) ];
for(Contact c :con )
{
c.Open_Opportunities__c=opportunity.size();
Updcon.add(c);
}update Updcon;
Thanks in advance,
Shahid.
I Created a custom lookup field on Opportunity object to Contact object. I need to fetch the account details when i create new opportunity under contact object.
While creating new opportunity under contact object , ihave only contact details, but i need to fetch this particular contact account details also.
Code:
Set<Id> cId=new Set<Id>();
for(Opportunity opp : newList){
cId.add(opp.Primary_Broker__c);
}
List<Contact> Updcon = new List<Contact>();
List<Contact> con = [select id,AccountId,Open_Opportunities__c from Contact where Id in:cId ];
List<Opportunity > opportunity= [select id,Primary_Broker__c,StageName from Opportunity where Primary_Broker__c in:cId AND ( StageName NOT IN ('Closed Won','Closed Lost')) ];
for(Contact c :con )
{
c.Open_Opportunities__c=opportunity.size();
Updcon.add(c);
}update Updcon;
Thanks in advance,
Shahid.
Example: Assume you have a lookup field to Contact on your Opportunity object, say its API name is Contact__c . Now you want to display that Contact's related Account's Name in one of the field on Opportunity object. For that, create a Formula field with Text as return type on Opportunity and write the below code in it - Note: Please use the Insert Field button on the formula to insert fields and never type them as it is prone to make mistakes.
The formula field which was created on the Opportunity object is known as Cross Object Formula.
Thanks for your reply. But no need to create formula field. In opportunity object there is Account lookup field. I want to write a code on this apex class.
Thanks,
Shahid.
Yes, I need to populate the account record name on the Opportunity record
Thank you so much. My exact requirement is calculate the how many opportunities are open under this Contact record. I did this one. with the above code I mentioned in my question.
And I want to check populate account name also in opportunity new record under contact object.
( My requirement is when i create new opportunity under contact object RL , then i need to poplate Account name also according this contact record. ).
But i didn;t understand where i add this code in my code. Can you please help me.
Thanks,
Shahid.