You need to sign in to do that
Don't have an account?
Carrie Nunemaker 10
Create a trigger to sum a custom field on the contact and display on the account
I am completely new to Apex and could really use some help with what seems to be a simple task. I have a formula on the contact, Persona_True__c, that returns a 1 if the custom field "persona" is populated and a 0 if it is blank.
I would like to have a roll-up summary that sums this field at the account level in a field called Related_Personas__c.
Because we can't roll-up from contact to account I'm reading that this type of action needs to be a trigger, but I don't even know where to start. Does anyone have any thoughts or expertise they can share to help me out?
I would like to have a roll-up summary that sums this field at the account level in a field called Related_Personas__c.
Because we can't roll-up from contact to account I'm reading that this type of action needs to be a trigger, but I don't even know where to start. Does anyone have any thoughts or expertise they can share to help me out?
Hope that your day is off to an amazing start. We've constructed a trigger to your specifications. Please test and report back if anything. Hope this helps and may God bless you abundantly.
Best Regards,
Anthony McDougald
All Answers
Hope that your day is off to an amazing start. We've constructed a trigger to your specifications. Please test and report back if anything. Hope this helps and may God bless you abundantly.
Best Regards,
Anthony McDougald
Please wirte the below trigger in Contact Object. This trigger will cover all your scenario's:
Use any one of the below Trigger:
Trigger 1: Based on Formula Field ==> Persona_True__c we are calculating the Related Persona's in Account
trigger ContactTrigger on Contact (after insert, after update, after delete, after undelete) {
Set<Id> accountIds = new Set<Id>();
Map<Id,Decimal> mapChildTotalAmount = new Map<Id,Decimal>();
List<Account> accounttoUpdate = new List<Account>();
if(trigger.isInsert || trigger.isUpdate || trigger.isUndelete){
for(Contact con:trigger.new){
if(con.AccountId != null){
accountIds.add(con.AccountId);
}
}
}
if(trigger.isUpdate || trigger.isDelete){
for(Contact con:trigger.old){
if(con.AccountId != null){
accountIds.add(con.AccountId);
}
}
}
if(!accountIds.isEmpty()){
for(AggregateResult agg: [Select AccountId accId, SUM(Persona_True__c) from Contact where AccountId IN : accountIds group by AccountId ]){
mapChildTotalAmount.put((Id)agg.get('accId'),(Decimal)agg.get('expr0'));
}
for( Account acc : [Select Id, Related_Personas__c from Account where Id IN :accountIds])
{
Decimal totalPersona = mapChildTotalAmount.get(acc.Id);
acc.Related_Personas__c = totalPersona ;
accounttoUpdate.add(acc);
}
}
if(!accounttoUpdate.IsEmpty())
{
update accounttoUpdate;
}
}
======================== OR =======================
Trigger 2 : Without using the Formula Field. So no need to create the Formula Field. we can use the below trigger directly with the help of persona__c custom field to calculate the related persona's in Account.
trigger ContactTrigger on Contact (after insert, after update, after delete, after undelete) {
Set<Id> accountIds = new Set<Id>();
Map<Id,Decimal> mapChildTotalAmount = new Map<Id,Decimal>();
List<Account> accounttoUpdate = new List<Account>();
if(trigger.isInsert || trigger.isUpdate || trigger.isUndelete){
for(Contact con:trigger.new){
if(con.AccountId != null){
accountIds.add(con.AccountId);
}
}
}
if(trigger.isUpdate || trigger.isDelete){
for(Contact con:trigger.old){
if(con.AccountId != null){
accountIds.add(con.AccountId);
}
}
}
if(!accountIds.isEmpty()){
for(AggregateResult agg: [Select AccountId accId, Count(Id) from Contact where AccountId IN : accountIds AND persona__c!=null group by AccountId ]){
mapChildTotalAmount.put((Id)agg.get('accId'),(Decimal)agg.get('expr0'));
}
for( Account acc : [Select Id, Related_Personas__c from Account where Id IN :accountIds])
{
Decimal totalPersona = mapChildTotalAmount.get(acc.Id);
acc.Related_Personas__c = totalPersona ;
accounttoUpdate.add(acc);
}
}
if(!accounttoUpdate.IsEmpty())
{
update accounttoUpdate;
}
}
Thanks,
Maharajan.C
Hope that your day is off to an amazing start. Below is a test class that you can use to get code coverage. Please test and feel free to report back if you have any questions or problems. Hope this helps and may God bless you abundantly. Best Regards,
Anthony McDougald
Regards
Marco Gasser
AA Group Financial Consulting AG
Email: MarcoGasser@Consultant.com
Email: marcoga@naver.com
kik sexting forum (https://kiksexting.co)
https://appsapkbox.com
https://whatsappstatus.vip
Norton Coupon Codes (https://www.couponstechie.com/promo-codes/norton)
Beside most propagating similar issues portrayed over, xvideos tube (https://www.xvideos.tube/) likewise little industry straightforwardness, responsibility, or dependable data accessible.
It is essentially industry informants feeling just as xnxx top (https://www.xnxx.top/) penance their professions to shout out or writers revealing insight into manhandles like those asserted against it.
However actually free xhamster llc (https://www.xhamster.llc/) going anyplace (for the time being), and some cylinder destinations can be more moral than others. New plans of action are developing that furnish free clasps.
This entertainer arranged stage is tied in with making a space where free chaturbate porn (https://www.chaturbates.net/) helps rather than harms content makers. With a configuration that spotlights entertainers who are generally simply beginning.
The sort of grounded, home video, virtuous stuff that by one way or another leaves you feeling like possibly the subject of tranny (https://www.shemalecamspro.com/) can really be a net positive for society.
Robbery is essentially a non-issue since littlesubgirl porn (https://www.sexcams.club/cam/littlesubgirl/) is prohibited from posting. Realness is esteemed to the exclusion of everything else, so you get significantly less.
This one was on the line for us, at the end of the day naughtyelle porn (https://www.sexcams.club/cam/naughtyelle/) to stand firm on disputable issues pushed it over the edge.
It can be a home for siswet19 porn (https://www.sexcams.club/cam/siswet19/) , and survivors have communicated that it is so hard to get them expelled. A long way from invulnerable to robbery, a siswet19 representative highlighted the site.
They was likewise up to speed in the anabel054 porn (https://www.sexcams.club/cam/anabel054/) debate. It impaired its anabel054 channel and started effectively bringing down the organization recordings.
At whatever point migurtt porn (https://www.sexcams.club/cam/migurtt/) is looked on the site now, it cautions clients about the studio misuses and urges watchers to report any of its recordings.
27 Good things (https://www.27goodthings.com/)
work perfectly! Thank you I have apply this page https://www.seebiz.com/vendor/luxuryperfume
Stunning Web diary! this is uncommon since you are reliably sending genuine focuses with brilliant data
I trust you will do your work proceed altogether further and you got a win early.
Dubai Escort Service (http://www.escortsdubai.org/)
Then click on the list you want to customize.
Next, click on the Edit option. Note: If you don’t see the Edit tab, click on the More Options icon and select Edit.
In the Data Field Settings scroll right to see the extra fields available.
Find the field you want to edit or add, and type in the new name in the Field Name box.
If needed, change the Field Type.
When done click on the Save option.
for more visit my website : HERE (https://moviezforum.com)
Golden Retrievers Prices in India (https://puppiesbreed.com/golden-retrievers-prices-in-usa-uk-india/)
https://printingshell.com/custom-soap-boxes/
https://printingshell.com/custom-christmas-boxes/