function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tobias HaggeTobias Hagge 

Trigger from Opportunity to Contact

I would like to do a trigger on Opportunities to rollup values into the Contact object. We don't use ContactRoles. There is a lookup fields to the relevant Contact on the Account, but the following gives a null ID.
Map<String, Opportunity> opportunityMap = new Map<String, Opportunity>();
		for(Opportunity opportunity: opportunities)
			String id = opportunity.Account.Contact__c;
			System.debug ('*****' + id);
			if(id != null)
				opportunityMap.put(opportunity.Account.Contact__c, opportunity);
Any ideas?
Best Answer chosen by Tobias Hagge
Himanshu ParasharHimanshu Parashar
Hi Tobias,

Relationship fields are not available inside so you need to query them in sepeate SOQL.

Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer.