You need to sign in to do that
Don't have an account?
MaheemSam
How to add or sum boolean values in code
Hi,
I have a below code which is working as expected it gives list of account names and contact name top to bottom
Now my requirement is in contact we have NSE1 and NSE2 has two feilds this needs to be added or sum and displayed when it is views from partner account
Example;
Account A is Top Parent Has 1 Contacts NSE1 = 1 and NSE2 = 1
Account B is Child of Account A Has 1 Contacts NSE1= 1 and NSE2 = 1
Account C is Child of Account B Has 1 Contacts NSE1= 0 and NSE2 = 1
If I see Account A Contact NSE1 and NSE2 should be NSE1 = 2 and NSE2 = 3
If I see Account A Contact NSE1 and NSE2 should be NSE1 = 1 and NSE2 = 2
If I see Account A Contact NSE1 and NSE2 should be NSE1 = 0 and NSE2 = 1
Code should display values as above. Please suggest me how to obtain this sum or add up the boolean values at parent level.
Thanks
Sudhir
I have a below code which is working as expected it gives list of account names and contact name top to bottom
Now my requirement is in contact we have NSE1 and NSE2 has two feilds this needs to be added or sum and displayed when it is views from partner account
Example;
Account A is Top Parent Has 1 Contacts NSE1 = 1 and NSE2 = 1
Account B is Child of Account A Has 1 Contacts NSE1= 1 and NSE2 = 1
Account C is Child of Account B Has 1 Contacts NSE1= 0 and NSE2 = 1
If I see Account A Contact NSE1 and NSE2 should be NSE1 = 2 and NSE2 = 3
If I see Account A Contact NSE1 and NSE2 should be NSE1 = 1 and NSE2 = 2
If I see Account A Contact NSE1 and NSE2 should be NSE1 = 0 and NSE2 = 1
Code should display values as above. Please suggest me how to obtain this sum or add up the boolean values at parent level.
set<id> setactid = new set<id>(); Id accountId = '001W000000aDqeA'; Account[] allparents = new Account[] {}; Set<Id> parentIds = new Set<Id>{accountId}; Account[] parent; do { parent = [select Id,ParentId, Name from Account where Id in :parentIds]; allparents.addAll(parent); parentIds.clear(); for (Account par : parent) parentIds.add(par.ParentId); } while (parent.size() > 0); list<Account> Act = [select id, name from account where id in :allparents]; for(Account A : Act){ system.debug(a.name); setactid.add(a.id); //dispaly here the sum of NSE1 and NSE2 account level grouping the contacts for(Contact C : [select id,name,NSE_1__c,NSE_2__c from contact where accountid in :setactid]){ system.debug(c.name); system.debug('NSE_1__c ' + c.NSE_1__c); //How to add this boolean values system.debug('NSE_2__c ' + c.NSE_2__c); } }
Thanks
Sudhir
Try this, Hope it works fine.
Thanks!!!
If it helps you, please mark is as best answer, so it will be helpful for other developers.
All Answers
You can use If Condition
Eg:
Integer NSE = 0;
if(NSE_1__c )
NSE = NSE + 1;
From your code, Line 03 is Child Account ID. So, are you trying to get data from Child - to - Account..?
Thanks!!!
Yes I am trying to get data from child to account, can you suggest me how to group the child and get account wise.
Thanks
Sudhir
Try this,
Thanks!!!!
If it helps you, please mark is as best answer, so it will be helpful for other developers.
Add System.debug("Acc ID==>"+i+"NSE -1==>"+NSEmap1.get(i)); // in Line 23
Add System.debug("Acc ID==>"+i+"NSE -2==>"+NSEmap2.get(i)); // in Line 32
You will get which account and its NSE values.
Thanks..!!!
Thanks very much for your help one part is not working looks like NSE1 AND NSE2 is not grouping like blow please see below example
Parent Account - 1 (Account level NSE1 = 5 and NSE2=4)
Have 2 Contacts with NSE1 = 1 AND NSE2= 1
Child Account - 2 (Parent Account-1) (Account level NSE1 = 4 and NSE2=3)
Have 2 Contacts with NSE1 = 2 AND NSE2= 1
Sub Child Acount - 3 (Child Account - 2) (Account level NSE1 = 2 and NSE2=2)
Have 2 Contacts with NSE1 = 2 AND NSE2= 2
At account level NSE1 AND NSE2 should populate as how it is poopulated let me know if this is not clear i can explain in another example
Thanks for your help your genious
Thanks
Sudhir
What output are you getting..?
and
Is NSE1 and NSE2 are Boolean Values..?
I understood your example.
Thanks!!!
I miss this.
Replace Line 47 - 52 as below Hope it works now.
Thanks!!!
If it helps you, please mark is as best answer, so it will be helpful for other developers.
Line: 45, Column: 7
Unexpected token 'ChildToParnet'.
Thanks
Sudhir
Please ignor my previous msg its working Thanks Buddy you solved my issue I am doing some more testing.
Thanks
Sudhir
Thanks!!!
I was doing testing on your code there seems to be one bug
If I am doing for top parent
Account - 1
Has only one Contact with NSE1 = true and NSE2 = true
When I run your code it is updating as value in Account NSE1 = 2 and NSE2 = 2 Please check and let me know
Thanks very much for your help
Thanks
Sudhir
I fixed above it is working I need you suggestion for insert now the code is working as expected for update Please suggest me.
Thanks
Sudhir
Hi Sudhir,
Which object are plan to insert..?
and what field values to be inserted in that object.
Thanks!!!
Hi Gokul,
It will be same logic In account I will be creating new conact with NSE1 = true and NSE2 = true this will update to the existing values.
Also Please let me know how to perform same for delete if any contact is deleted it must reduce Please let me know if you understand else will give in a example
Update is working fine with abvove code.
Thanks
Sudhir
Try this,
For Deletions, you need to go Trigger.
Thanks..
I do not want insert code of contact all I need is when a new record is inserted (Contact) NSE1 and NSE2 value should rollup to account NSE1 and NSE2 Please find the trigger logic how i am using I think we must do a after update with existing account NSE1 NSE2 to new contact NSE1 AND NSE2
Please let me know if your not clear
Thanks
Sudhir
Thank!!!
Let me explain you again What I am trying to do is just update the account NSE1 and NSE2 with new contact NSE1 and NSE2 Please find code below
Trigger
Helper Class Sorry code is not aligned But I am having issue when contact insert is made it must update the account
I am getting below error now.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ContactTrigger caused an unexpected exception, contact your administrator: ContactTrigger: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: ()
Thanks
Sudhir
Try this, Hope it works fine.
Thanks!!!
If it helps you, please mark is as best answer, so it will be helpful for other developers.
Thanks
Sudhir
Need your help finally I test only the update part it was working I am trying to create a new contact it is giving me below error from you code.
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger ContactTrigger caused an unexpected exception, contact your administrator: ContactTrigger: execution of AfterUpdate caused by: System.ListException: Duplicate id in list: 001W000000aDqeAIAS: Class.ContactCertificateRollupHandlerNew.accountRollupInsert: line 46, column 1".
Also please help me with Delete part Thanks for you help.
Thanks
Sudhir
I wrote different methods for Insert Update and Delete,
Insert and Delete is working fine without any issue Please suggest me how to add the Delete method I am trying to update all contacts of parent after the contact is is deleted it is not working
Thanks
Sudhir
Need you help very much on the same request can you please help me I have opened a new case for the continuation of the request.
Please see below link
https://developer.salesforce.com/forums/ForumsMain?id=9060G000000MVRqQAO#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=9060G0000005SAKQA2
Your code is working perfect for account hierarchy if it is linear or same if multiple accounts have same account then it is not working can you please suggest me.
Thanks
Sudhir