Trigger to Count records in self relationship salesforce

0 votes
I am working on one scenario.

I have an object called "Property_Assignment__c" which has two record types. 1) Primary Property Assignment 2) Secondary Property Assignment Its also having a self lookup relationship and this lookup field "Primary_Assignemnt__c" is available on "Secondary Property Assignment" page layout which is lookup to "Primary Property Assignment". Now if I create any records in "Secondary Property Assignment" record type then I need to count and save in "Number_Of__Dependents" field in "Primary Property Assignment".

How can this problem be solved?
Mar 9, 2022 in SalesForce by surbhi
• 3,820 points
1,288 views

1 answer to this question.

0 votes

You should only use triggers if you want to count the Secondary Property Assignment entries. When the master-detail relationship is accessible, we can utilise Rollup summary to count the number of Secondary Property Assignment data.

However, you have self-relationship here. As a result, you can create a trigger that counts the number of records.

Hope this helps!

Enroll in our Salesforce Course here to learn more about creating a trigger in Salesforce.

Thanks!

answered Mar 9, 2022 by CoolCoder
• 4,420 points

Related Questions In SalesForce

0 votes
1 answer

Json response to be deserialized in Apex salesforce lightning

Because some fields in Apex Salesforce are ...READ MORE

answered Mar 2, 2022 in SalesForce by surbhi
• 3,820 points
3,588 views
0 votes
1 answer

Apex Class and Apex Trigger is invisible in Salesforce Developer Console

You'll need to create a new developer ...READ MORE

answered Mar 8, 2022 in SalesForce by anonymous

edited Jun 19, 2023 by Khan Sarfaraz 2,752 views
0 votes
1 answer

How to add days to date time in Salesforce Apex?

Beware the DST issue! The "addDays" function ...READ MORE

answered Mar 15, 2022 in SalesForce by CoolCoder
• 4,420 points

edited Jun 19, 2023 by Khan Sarfaraz 7,601 views
0 votes
1 answer

How to find an element in Salesforce applauncher pop up using Selenium Webdriver?

Try if this works:- driver.findElement(By.xpath(".//p[text() ='Marketing']")).click(); Hope this helps! Check ...READ MORE

answered Mar 17, 2022 in SalesForce by CoolCoder
• 4,420 points
1,008 views
+2 votes
2 answers

Salesforce Interview questions

Here are some questions very important for ...READ MORE

answered Jan 11, 2019 in Career Counselling by Suresh
• 720 points
3,462 views
0 votes
1 answer

How to connect to salesforce from tableau?

Hi, follow these steps to connect to Salesforce: 1. ...READ MORE

answered Mar 25, 2019 in Tableau by Cherukuri
• 33,030 points
1,071 views
0 votes
1 answer

Power BI - Salesforce

Hi, Follow below steps: 1. Go to Data source. 2. ...READ MORE

answered Mar 25, 2019 in Power BI by Cherukuri
• 33,030 points
788 views
0 votes
2 answers

What is the best training for Salesforce ADM-201 Exam?

Hi @Vardhan, I took Edureka's Salesforce Online Training, ...READ MORE

answered Jun 3, 2021 in Others by Jaya
• 140 points

edited Dec 22, 2021 by Soumya 753 views
0 votes
2 answers

Creating Many to Many relationship between the accounts records in salesforce

In Salesforce, it is not possible to ...READ MORE

answered Jun 19, 2023 in SalesForce by Khan Sarfaraz
• 700 points
1,351 views
0 votes
1 answer

How to Update RecordTypeId field in Lightning record form in salesforce?

A critical action that messes everything up ...READ MORE

answered Mar 3, 2022 in SalesForce by CoolCoder
• 4,420 points
3,374 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP