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
symantecAPsymantecAP 

Unexpected Token Error

 

 I get the following Error when i try to save this

 

Error: Compile Error: unexpected token: 'List' at line 4 column 4

 

 

public class createoriginalfcst {

    public static List<SMART_Product__c>ActiveSKUs  {
    List<SMART_Product__c>ActiveSKUs=[SELECT Name FROM SMART_Product__c WHERE Product_Status__c='Active']
    }


}

 

 

 

Kindly help

bob_buzzardbob_buzzard

The solution rather depends on what you are trying to do:

 

If you are attempting to define a static method called ActiveSKUs, you are missing the brackets that denote the method parameters, e.g..

 

public static List<SMART_Product__c>ActiveSKUs()  { 

 

If you are attempting to do something else, please give further details. 

symantecAPsymantecAP
Thank you for the response. I am trying to query all Active SKUs from Consumer Product Object. where my product status field is Active.
bob_buzzardbob_buzzard

Yes, I understand that - its more about what programming construct you are writing.

 

Are you trying to write a method called ActiveSKUs, or are you trying to initialize a list at object creation time, or something else. 

vintondonvintondon

You should use parentheseis () while delcaring method name in anonymous block.

Hence your code should be

 

}

public class createoriginalfcst (){

    public static List<SMART_Product__c>ActiveSKUs  { 
    List<SMART_Product__c>ActiveSKUs=[SELECT Name FROM SMART_Product__c WHERE Product_Status__c='Active']
    }

Try it out and this will run properly.

bob_buzzardbob_buzzard

This line is illegal syntax:

 

public class createoriginalfcst (){

 

You can't include parentheses on a class declaration - I think you are confusing the class with the constructor.

 

vintondonvintondon

Yes, you are right bob. I got confused with method declarationa as I overlooked class keyword.

 

vintondonvintondon

Though the following should work

 

public class createoriginalfcst {

    public static List<SMART_Product__c>ActiveSKUs () {
    List<SMART_Product__c>ActiveSKUs=[SELECT Name FROM SMART_Product__c WHERE Product_Status__c='Active']
    }


}

 

The parenthesis should be added to ActiveSKUs static method.

vintondonvintondon

I faced a similar issue and the culprit was missing parenthesis in method declaration

bob_buzzardbob_buzzard

Just to be pedantic, you'll need to return a value from that method as per its signature (and add a semi-colon to the end of the query line).

vintondonvintondon

In pedantic terms yes, but I am assuming that these details must already been taken care of by semanticAP

vintondonvintondon

Yes you are right bob, but I am assuming that these details must have been taken care of by SymanticAP.

 

Samuel RobertSamuel Robert
Hi please verify my code iam getting an error as unexpected token : insert as error.

Apple_inc__c objAppleinc = new Apple_inc__c     ();
objAppleinc.Name = 'Geoside consultant';
objAppleinc.Email__c = 'samuel@doodleblue.com';
objAppleinc.mobilenumber__c = '9941132612';
objAppleinc.Comments__c = 'Shipment should be done on 01/31/2016';
objAppleinc.delivery_date__c = 01/31/2016   
insert objAppleinc;
System.debug('Records Has been created '+objAppleinc);
Mark Brown 33Mark Brown 33
@samuel Robert, in case you never solved this, it's because you didn't end the delivery date line with a semi-colon