You need to sign in to do that
Don't have an account?

Trigger to count number of Account PublicGroups
Dear Team,
I want to know count the number of public group(s)(starts with P) an account is shared with. Can anyone please help us to creating a new trigger.
Let ‘say: In one account we have number of public group’s start with P. So we want to count the public groups which are start with P. The count will be populate field called as "PublicGroup_Count__c"
Thanks
I want to know count the number of public group(s)(starts with P) an account is shared with. Can anyone please help us to creating a new trigger.
Let ‘say: In one account we have number of public group’s start with P. So we want to count the public groups which are start with P. The count will be populate field called as "PublicGroup_Count__c"
Thanks
Public Groups are not linked with any Object. How can we Identity if Public Group (p) is on account?
Thanks,
Gaurav
Thaks for your reply.Based on Account share object can we i think so?
Thanks,
Here is the solution according to what I have understood about your problem, I have created a custom object Public_Group__c which has the lookup of account and as per your requirement there is a custom field PublicGroup_Count__c on Account object. PublicGroup_Count__c field stores the number of Public_Group__c (Name starts with p) in a particular account.
Try this code.
Trigger Apex Class: Apex Trigger: Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
Regards,
Akshay
Following code works for me.Try this, Kindly Edit and Save the Account record to check the PublicGroup_Count__c value.
Hope it will satisfy your requirement.
Thanks,
Vignesh.B
Thanks for your Reply.
I have tried below trigger count is not updating. Can you please help me where i made the mistake?
Trigger:
trigger PartnerGroups on Account (before insert,before update)
{
set<id> acId=new set<id>();
for(Account ac:trigger.new)
{
acId.add(ac.id);
}
set<id> pgId=new set<id>();
// List<Group> grpquy=[select id from group where type='Regular' and Name like 'd%'];
List<PartnerSharing__c> PRSquy =[SELECT Account_Name__c,Group_Name__c,Id,Name FROM PartnerSharing__c Where Group_Name__c like 'P_%' ];
//for(Group g:grpquy)
for(PartnerSharing__c p:PRSquy)
{
pgId.add(p.id);
}
map<id,Integer> pgcount=new map<id,Integer>();
// AggregateResult[] agquy=[SELECT AccountId,count(UserOrGroupId)sum1 FROM AccountShare group by AccountId];
AggregateResult[] agquy=[SELECT AccountId,count(UserOrGroupId)sum1 FROM AccountShare group by AccountId LIMIT 1];
for(AggregateResult ag:agquy)
{
pgcount.put((Id)ag.get('AccountId'),(Integer)ag.get('sum1'));
}
for(Account ac1:trigger.new)
{
if(pgcount.containsKey(ac1.Id))
{
ac1.PartnerGroup_Count__c = pgcount.get(ac1.Id);
}
}
}
Thanks
Follow the steps:
1.Use my code as it is.Just change 'P' instead of 'd' in query (List<Group> grpquy=[select id from group where type='Regular' and Name like 'd%'];)
2.Goto Account Record Click Manual sharing button and choose Public group which name starts with 'P' and add.
3.Come back to the Account Record.Edit and save the record and see the count Value.
Note: Account should be private in Sharing Settings then only you can see Manual sharing button.
Try this and let me know the result
Thanks,
Vignesh.B
I have follwed your steps.
2.Goto Account Record Click Manual sharing button and choose Public group which name starts with 'P' and add. Means hear we need to add any groups?
Can we have a call if you are free?If ok please send me your number to my gmail -> "HariSfdc299@Gmail.com"
Thanks
Hi Hari,
As per your requirement, I would suggest you to use Schedule Apex Class to update count of public groups on Account, because we can not create the trigger on Account Share (Standard Object) and Trigger on Account is meaningless.
If you want to utilize the trigger on Account, then let me know, I will develop the code for you :)
Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com
Whatever can you please help me that would be great help for us.
Thanks,
Hari
Hari,
Yeah I can help you :)
please connect with me on gmail Id
Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com