Latest News
My latest ramblings.
Enjoy! I definitely got important things to say
My latest ramblings.
Enjoy! I definitely got important things to say
Hello Friends,
Today, we are going to understand about Account Contact relationship in Salesforce
Generally, how are the account and contact related to each other?
Multiple contacts are associated with one account. This means that if I am doing business with a company then there can be multiple points of contact associated with that company. This is a direct relationship between accounts and contacts.
Direct relationship:- The relationship between an account and its associated contacts is a direct relationship.
One Contact associated with multiple Accounts
Let’s understand the concept with help of an example. There is an independent consultant, Andy and he is the point of contact for multiple businesses. In that case, one contact is associated with multiple accounts.
Indirect relationship:– Multiple accounts associated with the contact represent indirect relationships.
I hope now account contact relationship is clear to you.
Enable Contact to multiple Accounts
Go to Setup Enter “Account Settings” and check the checkbox beside “Allow users to relate a contact to multiple accounts”.
Under contact to multiple Account Settings we have the following option:
When users try to delete an account that has direct contacts that are related to other accounts, choose either one of the options below.
i) Block users from deleting the account.
ii) Allow users to delete the account, and automatically delete all direct contacts even if they are related to other accounts.
When users replace the primary account on a contact record, choose the below either one of the options
i) Save the relationship between the contact and the previous primary account as an indirect relationship.
ii) Delete the relationship between the contact and the previous primary account.
Now go to Object Manager -> Account -> Page Layout -> Select the page layout in which you want to make change ->Add Related Contacts to the related list -> Save
Go to any account record -> Go to related.
You will see Related Contacts in the related List
So, as you see in the related contact, all the direct contacts of the account will automatically display here
Now Click on Add Relationship Button.
On the next screen, select the Contact that you wish to associate with this Account and their Role, and then click on Save.
Account Contact Relationship Object
The Account Contact Relationship (AccountContactRelation) is a Standard object that is like a junction object between Account and Contact. It enables the creation of many-to-many relationships between account and contact. Account Contact Relationship is having lookup to Account and contact instead of master-detail relationships.
Account and Account Hierarchy
The next topic is Account Hierarchy. Go to an Account record and there you will see a field called parent account. What is that field?
Let’s consider Wal-Mart. It will have child accounts like Wal-Mart Supercenter, Wal-Mart discount store, Wal-Mart Neighborhood Market, Wal-Mart Express know all these subsidiaries will form the child account. So, the account hierarchy is used to define the account structure.
Also, note that getting access to the parent account will not grant access to the child’s account by default. For providing access, you need to use role hierarchy or security
settings but not account hierarchy.
Summary
Apex Triggers In Salesforce
The trigger is a script or a block of code that gets fired automatically whenever DML operations are performed on the object.
· Insert
· Update
· Delete
· Undelete
· Upsert (Insert and Update)
· Merge (Update and Delete)
· emptyRecycleBin
· ConvertLead
a. Apex Triggers (Sync triggers)
The synchronous trigger is a process to perform the operation Sequential Form. It means the process waits for the task to be completed and then moves to the next task Sequentially.
Sync triggers are of two types:=
i. Before Triggers
These triggers are fired before the new data gets saved to the database.
a. Need to make changes in records that have initiated trigger.
b. Need to validate data
ii. After Triggers
These triggers are fired after the records are saved to the database.
a. Need to perform DMLs on records other than those who have initiated trigger
b. Need to call Async threads or need to make a call out to a third-party system.
b. Async Apex Triggers:=
These triggers get called asynchronously after data gets committed to the database. (In Asynchronous apex does not wait for the task to complete to move on to the next table)
Apex triggers enable you to perform custom actions before or after events to records in Salesforce, such as insertions, updates, or deletions.
Just like database systems support triggers, Apex provides trigger support for managing records.
Triggers can be defined for top-level standard objects, such as Account or Contact, custom objects, and some standard child objects. Triggers are active by default when created. Salesforce automatically fires active triggers when the specified database events occur.
Trigger Syntax:-
A trigger definition starts with the trigger keyword. It is then followed by the name of the trigger, the Salesforce object that the trigger is associated with, and the conditions under which it fires. A trigger has the following syntax.
trigger TriggerName on ObjectName (trigger_events) { code_block } |
isBefore | Returns true if this trigger was fired before any record was saved. |
isInsert | Returns true if this trigger was fired due to an insert operation, from the Salesforce user interface, Apex, or the API. |
isUpdate | Returns true if this trigger was fired due to an update operation, from the Salesforce user interface, Apex, or the API. |
isAfter | Returns true if this trigger was fired after all records were saved. |
isDelete | Returns true if this trigger was fired due to a delete operation, from the Salesforce user interface, Apex, or the API. |
isUndelete | Returns true if this trigger was fired after a record is recovered from the Recycle Bin. This recovery can occur after an undelete operation from the Salesforce user interface, Apex, or the API. |
isExecuting | Returns true if the current context for the Apex code is a trigger, not a Visualforce page, a Web service, or an executeanonymous() API call. |
new | Returns a list of the new versions of the sObject records. This sObject list is only available in insert, update, and undelete triggers, and the records can only be modified before triggers. |
newMap | A map of IDs to the new versions of the sObject records. This map is only available before update, after insert, after update, and after undelete triggers. |
old | Returns a list of the old versions of the sObject records. This sObject list is only available in update and deletes triggers. |
oldMap | A map of IDs to the old versions of the sObject records. This map is only available in update and deletes triggers. |
size | The total number of records in a trigger invocation, both old and new. |
operationType | Returns an enum of type System.TriggerOperation corresponding to the current operation. Possible values of the System.TriggerOperation enum are: BEFORE_INSERT, BEFORE_UPDATE, BEFORE_DELETE,AFTER_INSERT, AFTER_UPDATE, AFTER_DELETE, and AFTER_UNDELETE. If you vary your programming logic based on different trigger types, consider using the switch statement with different permutations of unique trigger execution enum states. |
A)Logic or manipulation which can’t be done using declarative ways:=
— A parent having child record and we want to stop deletion of parent record it cannot be possible declarative ways.
B)Operations on non-related objects:=
—we want to update Account Records and Same time update Position Records both don’t have a relationship.
C)Near real-time integration with External Systems:=
—We want to connect Salesforce org to External Org
Apex Triggers is a powerful tool for organizations looking to automate complex processes and solve complex problems that couldn’t solve with workflow and process builder. Also, follow the best practices with trigger patter that our code is reusable, maintainable, and controlling logic better way.
You can learn more about Salesforce’s Apex triggers and find code examples Also online learning platform and you can learn more about Apex triggers in detail.
Chafekar Chowk, Amit Complex, Building C-4, Chinchwad,
Pune Maharashtra 411033 India