2

according to the salesforce documentation, we can get the list of Audience those includes a specific user using Personalization class. But when I run the apex class by passing the required parameters, I am getting an issue as below.

{"status":500,"body":{"exceptionType":"System.UnexpectedException","isUserDefinedException":false,"message":"Salesforce System Error: 1139098110-234248 (-2032847153) (-2032847153)","stackTrace":"Class.ConnectApi.Personalization.getAudiences: line 107, column 1\nClass.ContactLoginController.getAudiencesNow: line 88, column 1"},"headers":{}}

My apex class is as below: Line 88 is where I am calling the ConnectApi.Personalization.getAudiences method. I've tried debugging it but I can't seem find any related information. I can rephrase the question if unclear or provide more information. Any help on this is much appreciated.

@AuraEnabled(cacheable=true)
public static String getAudiencesNow(String contactId){
    try {
        List<User> users = new List<User>();
        List<Wrapper> wraps = new List<Wrapper>();
        System.debug('contactId: '+contactId);
        ConnectApi.AudienceCollection audCollection;
        users = [Select Id from User where ContactId =: contactId];
        if(!users.isEmpty()) {
            String userId = users[0].Id;
            List<NetworkMember> communityMembers = new List<NetworkMember>();
            communityMembers = [Select Id, MemberId, NetworkId from NetworkMember WHERE MemberId =: userId];
            List<String> communityIds = new List<String>();
            for (NetworkMember each : communityMembers) {
                communityIds.add(each.NetworkId);
            }
            System.debug('communityIds: '+communityIds);
            if (!communityIds.isEmpty()) {
                // for (String each : communityIds) {
                // ConnectApi.PublishStatus status = new ConnectApi.PublishStatus('Live');
                String str1;
                String str2;
                String str3;
                List<String> str4;

                audCollection = (ConnectApi.Personalization.getAudiences(communityIds[0], str1,
                  str2, userId,
                  ConnectApi.PublishStatus.Live,
                  true,
                  str4));
                // System.debug('coll: '+coll);
                // }
            }
        }
        return JSON.serializePretty(audCollection);
    } catch (Exception e) {
        throw new AuraHandledException(e.getMessage()+' '+e.getLineNumber());
    }

}
2
  • Looks like the error comes when the userId is specified even if it is your own. I would suggest raising it with Salesforce but you can get audience info for current user by passing null.
    – manjit5190
    Commented Sep 12, 2020 at 17:35
  • Thanks @manjit5190! It actually solved the issue. I am not receiving the error no more. However, I am not getting the expected results (actual Audience details). But I suppose that should be a different question. I asked the question here: salesforce.stackexchange.com/questions/319564/… Commented Sep 14, 2020 at 6:50

2 Answers 2

2

I was able to get the desired results by removing the last 3 characters of the UserId and pass it to ConnectApi.Personalization.getAudiences method as suggested in the answers. Below is the working code.

@AuraEnabled(cacheable=true)
public static String getAudiencesNow(String contactId){
    try {
        List<User> users = new List<User>();
        List<Wrapper> wraps = new List<Wrapper>();
        System.debug('contactId: '+contactId);
        ConnectApi.AudienceCollection audCollection;
        users = [Select Id from User where ContactId =: contactId];
        if(!users.isEmpty()) {
            String userId = users[0].Id;
            List<NetworkMember> communityMembers = new List<NetworkMember>();
            communityMembers =
            [Select Id, MemberId,
              NetworkId from NetworkMember WHERE MemberId =: userId AND Network.Name =: System.Label.Perqs_Community_Name];
            List<String> communityIds = new List<String>();
            for (NetworkMember each : communityMembers) {
                communityIds.add(each.NetworkId);
            }
            System.debug('communityIds: '+communityIds);
            if (!communityIds.isEmpty()) {
                // for (String each : communityIds) {
                // ConnectApi.PublishStatus status = new ConnectApi.PublishStatus('Live');
                System.debug('userId1: '+ userId);
                userId = userId.substring(0, userId.length()-3);
                System.debug('userId2: '+ userId);

                String str1;
                String str2;
                String str3;
                List<String> str4;
                String str = communityIds[0];

                audCollection = (ConnectApi.Personalization.getAudiences(str, str1,
                  str2, userId,
                  ConnectApi.PublishStatus.Live,
                  true,
                  str4));
                // System.debug('coll: '+coll);
                // }
            }
        }
        return JSON.serializePretty(audCollection);
    } catch (Exception e) {
        throw new AuraHandledException(e.getMessage()+' '+e.getLineNumber());
    }


    // return audCollection;
}
0

Upon checking the backend logs for the GACK ID "1139098110-234248 (-2032847153)" the error message logged is

ConnectErrorCodeException: Inserted value too large for column: "005B0000006RvYUIA0"

Please log a case with Salesforce support for further assistance if required.

Regards, Salesforce Support

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .