You need to sign in to do that
Don't have an account?
Sarah Robertson
Account update trigger
I'm quite new to apex but can someone help me identify where i'm going wrong i keep getting this error when i try to save my trigger :
Compile Error: Expression cannot be assigned at line -1 column -1
trigger updateprimcount on Contact (before update) {
for (Contact c: Trigger.new){
if(Contact.Primary_Sales_Contact__c == TRUE ){
Account.Primary_Sales_Contact_Count__c =(integer.valueOf(Account.Primary_Sales_Contact_Count__c) + 1);
}
}}
Compile Error: Expression cannot be assigned at line -1 column -1
trigger updateprimcount on Contact (before update) {
for (Contact c: Trigger.new){
if(Contact.Primary_Sales_Contact__c == TRUE ){
Account.Primary_Sales_Contact_Count__c =(integer.valueOf(Account.Primary_Sales_Contact_Count__c) + 1);
}
}}
I am assuming your requirement is When a Contact is updated with field Primary_Sales_Contact__c = True, then its related Account's Primary_Sales_Contact_Count__c should be increased by 1.
For this, you can directly use Roll-Up Summary fields.
https://help.salesforce.com/articleView?id=fields_about_roll_up_summary_fields.htm&type=0
https://trailhead.salesforce.com/en/modules/point_click_business_logic/units/roll_up_summary_fields
It's not like discouraging about Triggers. In your trigger, you cannot direct use Account.Primary_Sales_Contact_Count__c to update. You have to store th AccountId and query the account with respect to the Contact and then update the Account.
Please find below links regarding Triggers:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm
https://trailhead.salesforce.com/en/modules/apex_triggers/units/apex_triggers_intro
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm
http://www.salesforcetutorial.com/apex-trigger-in-salesforce/
Let us know if that helps you.
Best Regards,
BALAJI
Hi Balaji
Thanks for helping me, i tried the account roll up but i could only seem to be able to do it for opportunities :(
I will look at the trigger route, so i need to use a subquery to link it to the account ? How would you reccomend i do that
Thanks
Sarah
You don't need to create a trigger for that, you can just create a process builder. It will be all configuration hence easy to maintain.