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
Jaymin Sutarwala 7Jaymin Sutarwala 7 

Compilation error: Expecting a colon, found ','

While trying to compile the following test class I am getting a compilatio error Compilation error: Expecting a colon, found ',' at this particular line in the code 

ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, CreatedDateDesc);

Can anyone help me to get rid of this.
 
@isTest(seeAllData=true)
private class TestLeadContactFeedTrigger {

    static testmethod void initTest(){
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
         
        User u = new User(Alias = 'TLCFT', 
                          Email='TLCFTest@test.com', 
                          EmailEncodingKey='UTF-8', 
                          LastName='Testing', 
                          LanguageLocaleKey='en_US', 
                          LocaleSidKey='en_US', 
                          ProfileId = p.Id, 
                          TimeZoneSidKey='America/Los_Angeles',
                          UserName='TLCFTest@test.com');
        insert u;
        System.debug('User created: ' + u.Id);
                          
        Lead TestLead1 = new Lead(FirstName = 'Test',
                                  LastName = 'Lead1',
                                  Company = 'Test Comp1',
                                  Status ='Working-Contacted',
                                  Email ='test.lead1@test.com',
                                  OwnerId = u.Id,
//                                OwnerId = '005K0000002N5GT',
                                  Lead_Info__c = 'This is the Lead Info for a test lead John Doe1');
        insert TestLead1;
        
        ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, CreatedDateDesc);
                
         System.assertEquals('This is the Lead Info for a test lead John Doe1', TestLead1.Lead_Info__c);
    }
}


 
Best Answer chosen by Jaymin Sutarwala 7
alouie_sfdcalouie_sfdc
ConnectApi.FeedSortOrder.CreatedDateDesc is the correct value to use.

I copied your code and noticed that there's a zero-width space in "ConnectApi.FeedType.Record" between "ConnectApi." and "FeedType.Record". After I removed the zero-width space, the Apex code compiled properly.

The zero-width space was likely inserted accidentally when copying and pasting from the API documentation. Do you have a link to the page that you may have copied the value from?

All Answers

BalajiRanganathanBalajiRanganathan

ConnectApi.FeedElementPage Leadpost =ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, CreatedDateDesc);

On the line above, you are using CreatedDateDesc but you have not defined any variable as CreatedDateDesc. 

Waqar Hussain SFWaqar Hussain SF
ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, CreatedDateDesc); 

If CreateDateDesc is a fuction use it like 
CreatedDateDesc cdd = new CreatedDateDesc();
ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, cdd);
It may be string. If it is string you have to writ it like 
ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, 'CreatedDateDesc');
or you have to define CreatedDate varible in your code.
Regards Vickey
Please let me know if it works.
 
Jaymin Sutarwala 7Jaymin Sutarwala 7
It didn't work. The CreatedDateDesc is not a custom variable or function; the getFeedElementsFromFeed method signature states that it is of type ConnectApi.FeedSortOrder

getFeedElementsFromFeed(String, ConnectApi.FeedType, String, Integer, ConnectApi.FeedDensity, String, Integer, ConnectApi.FeedSortOrder)

I even tried using ConnectApi.FeedSortOrder.createdDateDesc but even then it is not working.
ConnectApi.FeedElementPage Leadpost = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.​FeedType.Record, TestLead1.id, null, 5, ConnectApi.​FeedSortOrder.CreatedDateDesc);
alouie_sfdcalouie_sfdc
ConnectApi.FeedSortOrder.CreatedDateDesc is the correct value to use.

I copied your code and noticed that there's a zero-width space in "ConnectApi.FeedType.Record" between "ConnectApi." and "FeedType.Record". After I removed the zero-width space, the Apex code compiled properly.

The zero-width space was likely inserted accidentally when copying and pasting from the API documentation. Do you have a link to the page that you may have copied the value from?
This was selected as the best answer
Jaymin Sutarwala 7Jaymin Sutarwala 7
Thanks alouie_sfdc. I don't remember the exact link I copied ConnectApi.FeedType from but after i fixed this I got a similar error with ConnectApi.FeedSortOrder which i copied from this link https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_ConnectAPI_ChatterFeeds_static_methods.htm#apex_ConnectAPI_ChatterFeeds_getFeedElementsFromFeed_6

I am using Eclipse IDE so how can i identify zero-width space in Eclipse editor in case i come across this in future ?
alouie_sfdcalouie_sfdc
Thanks, Jaymin. Detecting the zero-width space is tricky. To find yours, I used the arrow keys to move the cursor across the line that had the error, and I noticed that the cursor didn't move when it hit the zero-width space.