You need to sign in to do that
Don't have an account?
Heshan Weerasekera 5
trigger - Campaign Member
Hi - I am very new to dev ( like 1 week :) )... i need to try and write a trigger calculating the unique number of campaign member companies attached to a campaign. For example a campaign can have 50 members representing 10 companies. I need that 10. Would anyone have a similar trigger they can share which I will try and edit ? many many thanks
This is possible via an Apex Trigger. I am also pretty positive that this cannot be achieve with a trigger.
You need to have a trigger on a CAMPAIGNMEMBER object in salesforce.
I would recommed doing following,
1) Create a field on CampaignMember object named Contact_s_AccountID__c which would pull contact's Account's ID. Here is a formula for it. 2) Create a field on Campaign object which tracks the different Account number named Total_Different_Companies__c It's a number field with no decimal.
3) Create a trigger on campaign member object. Below is a trigger code you can use. This trigger would work in all conditions such us Insert, Update, Delete, Undelete etc.. If you are adding one of your campaign member who belongs to a new account then trigger will update Total_Different_Companies__c appropriately. Same thing goes for deleting same record etc..
Trigger Code:
If you would like to see the visual representation then here we go,
Heshan, if this answers your question then please mark it as Best Answer by clicking best anwer link!
Thanks.
All Answers
This is possible via an Apex Trigger. I am also pretty positive that this cannot be achieve with a trigger.
You need to have a trigger on a CAMPAIGNMEMBER object in salesforce.
I would recommed doing following,
1) Create a field on CampaignMember object named Contact_s_AccountID__c which would pull contact's Account's ID. Here is a formula for it. 2) Create a field on Campaign object which tracks the different Account number named Total_Different_Companies__c It's a number field with no decimal.
3) Create a trigger on campaign member object. Below is a trigger code you can use. This trigger would work in all conditions such us Insert, Update, Delete, Undelete etc.. If you are adding one of your campaign member who belongs to a new account then trigger will update Total_Different_Companies__c appropriately. Same thing goes for deleting same record etc..
Trigger Code:
If you would like to see the visual representation then here we go,
Heshan, if this answers your question then please mark it as Best Answer by clicking best anwer link!
Thanks.