+ Start a Discussion
MicheleMcgeoyMicheleMcgeoy 

Compile Error: expecting right curly bracket,

I am brand new to Apex, so please forgive the basic question, but I am getting the following error from this Apex class: Compile Error: expecting right curly bracket, found 'insert' at line 3

 

public class CloneClassAttendance {

Campaign NewCamp = new Campaign(Name = 'Test Campaign record');

insert NewCamp;

 

Campaign NewCamp = [SELECT Type FROM Campaign WHERE Name = 'Test Campaign record'];

NewCamp.Type = 'Class Attendance';

update NewCamp;

}

 

Any help would be much appreciated.

Thanks, Michele

mauro_offermannmauro_offermann

You must put your logic inside a constructor, method or static block, it's depends you wants.

 

public class CloneClassAttendance {
	public void doit() {
		Campaign NewCamp = new Campaign(Name = 'Test Campaign record');
		insert NewCamp;
 
		Campaign NewCamp = [SELECT Type FROM Campaign WHERE Name = 'Test Campaign record'];

		NewCamp.Type = 'Class Attendance';

		update NewCamp;
	}
}

 

Then in Execute anonymous window write:

 

CloneClassAttendance myInstance = new CloneClassAttendance();
myInstance.doit();

 

RockzzRockzz

Try it  ur missing method:

 

public class CloneClassAttendance {

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

Campaign NewCamp1 = [SELECT Type FROM Campaign WHERE Name = 'Test Campaign record'];
NewCamp.Type = 'Class Attendance';
update NewCamp1;
}
}

 

Thanks,

Cool Sfdc

MicheleMcgeoyMicheleMcgeoy

This is very helpful. Thanks!

I am now trying to call the code from within a page. I tried pulling the code that you said to execute in anonymous, but that doesn't work. How do I run the code from my page?

 

<apex:page standardController="Campaign">

CloneClassAttendance myInstance = new CloneClassAttendance();

myInstance.insertRecord();
</apex:page>

 

Thanks, Michele

RockzzRockzz

Hi MicheleMcgeoy,

 

Hit KUDOS (Star) if this solution helps you.This will help the rest of the community should they have a similar issue in the future.


Thank you!
Cool Sfdc

Satyendra RawatSatyendra Rawat

Hi Michele,

Yes i find error in your code

1. write code inside Constructore.

2 error in query added colon (:) (Name =:'Test Campaign record')

 

public class CloneClassAttendance {
public CloneClassAttendance() {
Campaign NewCamp = new Campaign(Name = 'Test Campaign record');
insert NewCamp;

Campaign NewCamp = [SELECT Type FROM Campaign WHERE Name =:'Test Campaign record' limit 1];

NewCamp.Type = 'Class Attendance';

update NewCamp;
}
}

 

If you face any problem let me know:

Enjoy

 

Thanks

Satya

MicheleMcgeoyMicheleMcgeoy

This is very helpful. Thanks!

I am now trying to call the code from within a page. I tried pulling the code that you said to execute in anonymous, but that doesn't work. How do I run the code from my page?

 

<apex:page standardController="Campaign">

CloneClassAttendance myInstance = new CloneClassAttendance();

myInstance.insertRecord();
</apex:page>

 

Thanks, Michele