Salesforce stores default community to a User Profile in NetworkAffinity object. Using apex we cannot insert the default community to a User Profile. We can make a REST API call to add default community to a User Profile.
Sample Code:
//Get Endpoint URL
String endpointURL = URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v48.0/sobjects/NetworkAffinity';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpointURL);
req.setMethod('POST');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
//Add Community Id as NetworkId and Profile/Permission Id
req.setBody('{"NetworkId":"0DB1I000000TP59WAG","ProfileId":"00e1I000001uXJUQA2"}');
Http http = new Http();
HttpResponse response = http.send(req);
System.debug('response-' + response);
Note: Add your salesforce base URL as remote site settings and then execute above code in developer console anonymous window.
Salesforce stores community members in NetworkMemberGroup object. Using apex we cannot insert the community member. So we can make a REST API call to add community member.
Sample Code:
//Get Endpoint URL
String endpointURL = URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v48.0/sobjects/NetworkMemberGroup';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpointURL);
req.setMethod('POST');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
//Add Community Id as NetworkId and Profile Id as ParentId
req.setBody('{"NetworkId":"0DB1I000000TP59WAG","ParentId":"00e1I000001uXJUQA2"}');
Http http = new Http();
HttpResponse response = http.send(req);
System.debug('response-' + response);
Note: Add your salesforce base URL as remote site settings and then execute above code in developer console anonymous window.
({
getParamValue: function(component, event, helper) {
//Get Id Parameter Value From Community URL
var idParamValue = helper.getURLParameterValue().id;
console.log('Id-' + idParamValue);
//Get Name Parameter Value From Community URL
var nameParamValue = helper.getURLParameterValue().name;
console.log('Name-' + nameParamValue);
}
})
Lightning JS Helper:
({
getURLParameterValue: function() {
var querystring = location.search.substr(1);
var paramValue = {};
querystring.split("&").forEach(function(part) {
var param = part.split("=");
paramValue[param[0]] = decodeURIComponent(param[1]);
});
console.log('paramValue-' + paramValue);
return paramValue;
}
})
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject