+ Start a Discussion
MicheleMcgeoyMicheleMcgeoy 

getting variable from Campaign

I am new to Visual Force, so please excuse me if it's a basic question. I am trying to clone a campaign and all it's members and am having trouble pulling the new campaign id into the members, but I don't seem to be able to get the campaignid from the original campaign that i'm cloning. I get the error message:

Compile Error: unexpected token: 'Camp.id' at line 32

 

Here's the code:

public class CloneClassAttendance {
    private final Campaign camp;
    
    public CloneClassAttendance(ApexPages.StandardController stdController){
        this.camp = (Campaign)stdController.getRecord();
    }

    public void insertRecord(){
// Clone the campaign record
        Campaign NewCamp = new Campaign(Name = 'Test Campaign record');
        insert NewCamp;

        Campaign NewCamp1 = [SELECT Type, Status FROM Campaign WHERE Name = 'Test Campaign record'];
        NewCamp1.Type = 'Class Attendance';
        NewCamp1.IsActive = true;      
        NewCamp1.Name = camp.name + camp.startdate + 7;
        NewCamp1.Parentid = camp.id;
        NewCamp1.Startdate = camp.startdate + 7;
        
        update NewCamp1;

// Clone all records in CampaignMember
// Select records in CampaignMember from new campaign
//Create list of members for new campaign above.

 

//This line is where I get the error: Compile Error: unexpected token: 'Camp.id'
List<CampaignMember> Members = [SELECT id, contactid,status from CampaignMember where campaignid = Camp.id ];

// Change campaign ids

 

for(CampaignMember m : members){
   m.id = Newcamp1.id;
}

// Update the database
insert members;
    }
}

 

The Visual Force page is called from a button on the Campaign record:

<apex:page standardController="Campaign" extensions="CloneClassAttendance" action="{!insertRecord}">

  <h1>Cloning Attendance</h1>
  <p> Class name is {! campaign.name} </p>
  <p> Class id is:   {! campaign.id} </p>
  <p> Class start date is:   {! campaign.startdate} </p>
  <p> Class end date is:   {! campaign.enddate} </p>
  <p> Next week is: {! campaign.startdate+7} </p>
</apex:page>

Sonam_SFDCSonam_SFDC

Please try the following: 

List<CampaignMember> Members = [SELECT id, contactid,status from CampaignMember where campaignid = Camp.id ];

 

replace by : 

List<CampaignMember> Members = [SELECT id, contactid,status from CampaignMember where campaignid =: Camp.id ];