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
RiyajRiyaj 

How do I add record from Class?

I m usng new customize object name 'Class' inside this {'Name', 'Teacher Name'} , Now I want execute query.... i want to get a class name.. but I got a error"

 

Apex Code

 

global class getClassName{
WebService static Class getClassFromTeacherName(string teachername){
List<Class> r=[SELECT Name from Class WHERE teacher_Name__c = :teachername];
if(c.size()>0){
l=new Class(Name=c[0].Name);
}
return l;
}
}

 

Error

ErrorError: Compile Error: getClassName.getClassFromTeacherName: Types cannot be marked as web services at line 2 column 25 

 

 

 

vishal@forcevishal@force

Hi,

 

Class is a custom object, so when you use it in your apex code, it should be used as "Class__c".

 

I believe here you want to send back the Class object which has the teacher name which you are sending in the parameter.

 

So this code should help you:

 

global class getClassName{
WebService static Class__c getClassFromTeacherName(string teachername){
List<Class__c> r =[SELECT Name from Class__c WHERE teacher_Name__c = :teachername];
if(r.size()>0)
   return r[0];
else
  return new Class__c(); } }
Bindhyachal Kumar SinghBindhyachal Kumar Singh
Hi Riyaz,
You giving a webservice method type so you got error
Use following code it may be works and help someone.....


global class getClassName{ public void getClassFromTeacherName(string teachername){ List<Class> r=[SELECT Name from Class WHERE teacher_Name__c = :teachername]; if(r.size()>0) String l=Name=c[0].Name; } }