function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Error on Trigger to add Contact as a campaign member

I am attempting to write a trigger to add contacts that meet the qualifications, to a campaign as a campaign member.  I keep getting an error that I cannot seem to fix that says "AND operator can only be applied to Boolean expressions".  The line of code presenting the error is:



       if (account.RecordTypeId = '012800000007aDe' && contact.Email_Opt_In__c = 'true' && contact.CampaignMember.CampaignID != '70180000000jlhi' ) 



The rest of the code is posted below.  I appreciate any recommendations or explanations of this error.  Thanks!



trigger triggerContactCreateCampMember on Contact (after insert, after update) {

   List<CampaignMember> CampaignMember = new List<CampaignMember>();
   List<Contact> ContactsToAdd = new List<Contact>();
    Set<Id> conIds = new Set<Id>();
	 if(Trigger.isInsert || Trigger.isUpdate)
    //Store Contact ID
    for(Contact contact:
       if (account.RecordTypeId = '012800000007aDe' && contact.Email_Opt_In__c = 'true' && contact.CampaignMember.CampaignID != '70180000000jlhi' ) 
		List<Contact> c = new List<Contact> ([SELECT c.Id,c.AccountId From Contact c
		WHERE Id IN :conIds]);

		for (Contact con : c) {

	if(conIds.size() > 0)
	{CampaignMember.add(new CampaignMember
                ContactId = c.Id,
                CampaignId = '70180000000jlhi'));

              insert CampaignMember;



Best Answer chosen by Admin (Salesforce Developers) 
Kevin SwiggumKevin Swiggum

On the comparison operator, you need to use == instead of =



if (account.RecordTypeId == '012800000007aDe' ...