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
pranav_sanvatsarkarpranav_sanvatsarkar 

Variable does not exist: ConnectApi

Hello there,

I am trying to use ConnectAPI to implement some custom chatter functionality in my developer edition org. However, while trying to save the following code, I am getting the error, "Variable does not exist: ConnectApi"

This is the code that I am trying to deploy in a non-static public method in an Apex class.
ConnectApi.ChatterGroupInput groupInput = ConnectApi.ChatterGroupInput();

I may be missing a very simple piece of prerequisite, however, not able to find the same on internet.

Thanks in advance!
Best Answer chosen by pranav_sanvatsarkar
BeckBeck
Hi Pranav,

It looks like you're missing a "new" to the right of the "=".
ConnectApi.ChatterGroupInput groupInput = new ConnectApi.ChatterGroupInput();

You might also be interested in the answer to the question below, which has an answer that gives a ConnectApi example:
https://salesforce.stackexchange.com/questions/18666/how-to-dynamically-creating-chatter-groups-in-apex/18668

Good luck!
Beck

All Answers

pranav_sanvatsarkarpranav_sanvatsarkar
Well, working for too long may result into silly mistakes like this. This is how, I should have written the code instead of the above one,
ConnectApi.ChatterGroupInput groupInput = new ConnectApi.ChatterGroupInput();

Where the keyword "new" was missing!

Thanks for looking into this.
BeckBeck
Hi Pranav,

It looks like you're missing a "new" to the right of the "=".
ConnectApi.ChatterGroupInput groupInput = new ConnectApi.ChatterGroupInput();

You might also be interested in the answer to the question below, which has an answer that gives a ConnectApi example:
https://salesforce.stackexchange.com/questions/18666/how-to-dynamically-creating-chatter-groups-in-apex/18668

Good luck!
Beck
This was selected as the best answer