+ Start a Discussion
pierrefrazny.ax358pierrefrazny.ax358 

Save error: unexpected token

Hello,
I have the following lines of code to get a RecordTypeId.

Id CampaignTypeId = [Select Id from RecordType where Name = 'Attendance Campaign' and SObjectType = 'Campaign'].Id;Contact[] conts = new List<Contact>();conts = [select Id, Last_Campaign_Date__c ,(select Campaign.StartDate from CampaignMembers where HasResponded = TRUE AND Campaign.RecordTypeId = CampaignTypeId order by Campaign.StartDate Desc) from Contact where ID in :contIDs ];

 


I get the following error: 
Save error: unexpected token: 'CampaignTypeId'

If I hardcode the record type id ( ex: Campaign.RecordTypeId = '01270000000AfEX'), I do *not* get the error

Any clue?

Thanks a lot.
JimRaeJimRae
It is a bind variable, and needs the : in front of it, like the contIDs part of the query.
pierrefrazny.ax358pierrefrazny.ax358

Thanks. This worked.
Along the same line (I think), the if statement does not behave as expected (if(c.Campaign.RecordTypeId == CampaignTypeId)). It works if I hard code the RecordTypeId (ex: Campaign.RecordTypeId = '01270000000AfEX' )
trigger RollupDateLastCampaign on CampaignMember (after insert) { 

 

Id CampaignTypeId = [Select Id from RecordType where Name = 'Attendance Campaign' and SObjectType = 'Campaign'].Id;if(Trigger.isInsert) { for(CampaignMember c : System.Trigger.new){ if(c.Campaign.RecordTypeId == CampaignTypeId) {contIDs.add(c.ContactId);} }

 

Any clue?

Thanks a lot 

 
JimRaeJimRae

I would recommend you try some debug lines to see what you are getting.  Then when you run your testmethod, you will see the variables being compared.

 

 

trigger RollupDateLastCampaign on CampaignMember (after insert) { Id CampaignTypeId = [Select Id from RecordType where Name = 'Attendance Campaign' and SObjectType = 'Campaign'].Id; system.debug('\n\nGOT CampaignTypeID: '+CampaignTypeId); if(Trigger.isInsert) { for(CampaignMember c : System.Trigger.new){ system.debug('\n\nIn CampMember Loop: '+c); if(c.Campaign.RecordTypeId == CampaignTypeId{ contIDs.add(c.ContactId); } } } }

 

 I think what you will see is that you are not pulling the full parent record data set in with the trigger.  So, your "c.Campaign.RecordTypeID" is probably evaluating to null;

Only way to get that for sure would be to query for it specifically, maybe holding the data in a Map to related it back to the campaign.

 

 

 

 

 

pierrefrazny.ax358pierrefrazny.ax358

You were correct. "c.Campaign.RecordTypeID" was evaluated to NULL. I created a cross object formula on CampaignMember to get the Record Type ID of the Campaign.

Thanks

Pierre