You need to sign in to do that
Don't have an account?
Ashique Khan 7
Relate Event to Opportunity based on Contact Role
Trying to relate events for contact roles to the opportunity. I'm getting an 'Error: Compile Error: unexpected token: WHERE at line 3 column 122'. Here's the code:
trigger ChangeRelatedTo on Event (before insert) { List<OpportunityContactRole> contactsToCheck = [SELECT ContactId, OpportunityId, CreatedDate FROM OpportunityContactRole WHERE IsDeleted = FALSE ORDER BY CreatedDate DESC]; for( Event e : Trigger.new){ if (e.WhoId != null){ for ( OpportunityContactRole c: contactsToCheck ){ if (e.WhoId.equals(c.ContactId) ){ String oId = c.OpportunityId; List<Opportunity> opportunity; opportunity o = new opportunity(); o = [SELECT IsClosed, Id From Opportunity WHERE Id = :c.OpportunityId]; if (!o.IsClosed){ e.WhatId = c.OpportunityId; break; } } } } } }
Hi Ashique,
Try to open the code in notepad++ , as it is your code is having garbage characters like '[][]'
SELECT ContactId, OpportunityId, CreatedDate[][] FROM OpportunityContactRole WHERE IsDeleted = FALSE ORDER BY CreatedDate DESC
Remove those characters and then again try to save, it should work fine.
Hope this helps. :)
All Answers
Hi Ashique,
Try to open the code in notepad++ , as it is your code is having garbage characters like '[][]'
SELECT ContactId, OpportunityId, CreatedDate[][] FROM OpportunityContactRole WHERE IsDeleted = FALSE ORDER BY CreatedDate DESC
Remove those characters and then again try to save, it should work fine.
Hope this helps. :)
I'm new to this trigger / test class word - how would I write a test class for this? Are there apex class generators I can use?
I don't think that there is apex class generators that can create testclass automatically. You need to create the test class manually.
You can learn writing testclasses using trailhead .
https://trailhead.salesforce.com/modules/apex_testing/units/apex_testing_intro
Also you can check out below links , This will help you
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_test.htm
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Thanks,
Dushyant