-
Why do I'm getting an error on inserting and updating the address in contact mailing address?
trigger ContactMailAddr on Contact (after insert, after update) { // first you create a list to store the Account ids List<Id> accountToSearch = new List<Id>(); // get them from the contacts for (Contact contact : Trigger.new) { accountToSearch.add(contact.AccountId); } // query in the db List<Account> accounts = [SELECT Id, BillingStreet, BillingCity, BillingState, BillingCountry, BillingPostalCode FROM Account WHERE Id IN :accountToSearch]; list<contact> contacts =new list<contact>([select id,AccountId,MailingCity,MailingState,MailingStreet,MailingCountry from contact where accountid in :accountToSearch]); // iterate over the accounts and contacts for (Account account : accounts) { for (Contact contact : Trigger.new) { // if a contact is set to the account then if (contact.AccountId == account.Id && contact.AccountId != null) { // copy the contact's address to the account's fields contact.MailingStreet = account.BillingStreet; contact.MailingCountry = account.BillingCountry; contact.MailingState = account.BillingState; contact.MailingCity = account.BillingCity; contact.MailingPostalCode = account.BillingPostalCode; } } } // finally update the contacts records update contacts; }
I'm getting an error on inserting and updating the address?
Log In to reply.
Popular Salesforce Blogs
4 Benefits to Using Data Classification in Salesforce
Your Salesforce Org stores a ton of sensitive information; keeping things compliant and private — while still maintaining the pace of change — requires resources…
RemedyForce Can be Your ITSM Solution: Here’s How | Salesforce Guide
IT is changing the scene in all major professional fields, and its partnership with business management is helping enterprises in scaling and managing businesses, IT…
Salesforce Consulting Services: How can you Achieve your Business Goals in 2023?
Salesforce is a popular CRM solution. According to reports, Salesforce has helped clients increase their revenue by 25%. Salesforce technology places a strong emphasis on creating a…
Popular Salesforce Videos
Flow to Redirect User to Newly Created Record - Salesforce Flow
Scenario: Shubham is looking for functionality in Salesforce Flow Where after creating a record it redirects to that particular record detail page. Solution A: Create…
How to create an App in Lighting Experience?
Salesforce is the trusted cloud when it comes to privacy and we are sure the Lightning will strike here thrice. As Salesforce is expanding, new…
Salesforce Developer to Architect
In this video, we will look at the top considerations that are crucial to being a successful architect on the Salesforce platform. Even more, We…
Popular Salesforce Infographics
Top-notch Salesforce Development Services and Consulting
Our top-notch Salesforce development services. As a Salesforce Development Services partner, we have access to a wide range of resources and support from Salesforce, including training,…
How to Become a Salesforce Consultant?
Begin your Salesforce Consultant journey with Trailhead to learn about the modules offered by Salesforce to its users - admin, business users and developers to…
Why Salesforce End-user Training Matters for Smooth Implementation
This infographic 'Why Salesforce end-user training matters for smooth implementation' appeared first on Cynoteck. The progress of any CRM implementation depends on its general adoption…