You need to sign in to do that
Don't have an account?
nilesh walke 6
private test class 2 remaning code of previous code thnaks for helping me in test class
@RemoteAction
global static List<SObject> getRecords(Map<String, Object> paramatersMap ){
List<Sobject> records = new List<Sobject>();
return records;
}
@RemoteAction
global static List<SObject> getCollabGroupMemberIds(Map<String, Object> paramatersMap ){
String groupId = (String)paramatersMap.get('groupId');
List<Id>groupIds = new List<Id>();
List<Sobject> records;
try{
if(!String.isBlank(groupId)){
groupIds.add(Id.valueOf(groupId));
String query = '';
query = 'SELECT MemberId,Member.Email FROM CollaborationGroupMember WHERE CollaborationGroupId IN :groupIds AND Member.IsActive=true WITH SECURITY_ENFORCED';
records = Database.query(query.escapeHtml4());
}
}
catch(Exception e){
System.debug(e.getMessage()+ ' - line no: '+e.getLineNumber());
}
return records;
}
@RemoteAction
global static Map<String, Id> uploadAttachment(Map<String, Object> attributeMap){
Map<String, Id> returnMap = new Map<String, Id>();
String[] attachmentIdArray = new String[]{};
GNT__EmailQueue__c emailObj;
Attachment attachment = new Attachment();
String content = (String)attributeMap.get('AttachmentBody');
String attachmentId = (String)attributeMap.get('AttachmentId');
Boolean isUploadDone = (Boolean)attributeMap.get('UploadDone');
String EmailQueueIdStr = (String)attributeMap.get('EmailQueueId');
String parentId = (String)attributeMap.get('ParentId');
Id EmailQueueId = (Id)attributeMap.get('EmailQueueId');
System.debug('attachId----'+attachmentId);
if(String.isNotEmpty(attachmentId)){
attachment = [SELECT Id,Body FROM Attachment WHERE Id =:attachmentId WITH SECURITY_ENFORCED];
String newBody = '';
Blob AttachmentBlob = attachment.Body;
if(AttachmentBlob != null) {
newBody = EncodingUtil.base64Encode(AttachmentBlob);
}
newBody += content;
//attch.Body = Blob.valueOf(newBody);
if(Schema.sObjectType.Attachment.fields.Body.isCreateable() && Schema.sObjectType.Attachment.fields.Body.isupdateable()){
attachment.Body = EncodingUtil.base64Decode(newBody);
}
if(Schema.sObjectType.Attachment.isCreateable() && Schema.sObjectType.Attachment.isupdateable()){
upsert attachment;
}
returnMap.put('AttchId', attachment.Id);
System.debug('New Attachment----'+attachment.Id);
}else{
if(content !=null){
String[] base64result = safeSplit(content,',');
System.debug('Attachment Size --->'+base64result.size());
if(base64result !=null && base64result.size() > 1){
System.debug('Attachment Body3--->'+base64result[1]);
if(Schema.sObjectType.Attachment.fields.Body.isCreateable()){
attachment.Body = EncodingUtil.base64Decode(base64result[1]);
}
System.debug('base64Decode3-->'+attachment.Body);
if(Schema.sObjectType.Attachment.fields.Name.isCreateable()){
attachment.Name = (String)attributeMap.get('AttachmentName');
}
if(Schema.sObjectType.Attachment.fields.ParentId.isCreateable()){
attachment.ParentId = (Id)attributeMap.get('EmailQueueId');
}
if(Schema.sObjectType.Attachment.isCreateable()){
insert attachment;
}
returnMap.put('AttchId', attachment.Id);
System.debug('New Attachment----'+attachment.Id);
}
}
}
if(isUploadDone){
emailObj = getEmailQueueDetails(EmailQueueIdStr);
attachmentIdArray = getAttachmentIdOnEmailQueueforId(EmailQueueId);
System.debug('GNT__EmailQueue__c Update...'+emailObj);
System.debug('Attachment Array Id..'+attachmentIdArray);
Boolean sendACopyToMe = (Boolean)attributeMap.get('sendACopyToMe');
// add to address, cc address, Bcc address in map, GNT__Subject__c and email body
String toAddress =(String)attributeMap.get('toAddress');
String ccAddress =(String)attributeMap.get('ccAddress');
String subject =(String)attributeMap.get('GNT__Subject__c');
String emailBody=(String)attributeMap.get('body');
String bccAddress = '';
if(sendACopyToMe){
bccAddress = UserInfo.getUserEmail();
}
sendEMail(emailObj, parentId, sendACopyToMe, attachmentIdArray, toAddress, ccAddress, bccAddress, subject, emailBody);
}
return returnMap;
}
global static List<SObject> getRecords(Map<String, Object> paramatersMap ){
List<Sobject> records = new List<Sobject>();
return records;
}
@RemoteAction
global static List<SObject> getCollabGroupMemberIds(Map<String, Object> paramatersMap ){
String groupId = (String)paramatersMap.get('groupId');
List<Id>groupIds = new List<Id>();
List<Sobject> records;
try{
if(!String.isBlank(groupId)){
groupIds.add(Id.valueOf(groupId));
String query = '';
query = 'SELECT MemberId,Member.Email FROM CollaborationGroupMember WHERE CollaborationGroupId IN :groupIds AND Member.IsActive=true WITH SECURITY_ENFORCED';
records = Database.query(query.escapeHtml4());
}
}
catch(Exception e){
System.debug(e.getMessage()+ ' - line no: '+e.getLineNumber());
}
return records;
}
@RemoteAction
global static Map<String, Id> uploadAttachment(Map<String, Object> attributeMap){
Map<String, Id> returnMap = new Map<String, Id>();
String[] attachmentIdArray = new String[]{};
GNT__EmailQueue__c emailObj;
Attachment attachment = new Attachment();
String content = (String)attributeMap.get('AttachmentBody');
String attachmentId = (String)attributeMap.get('AttachmentId');
Boolean isUploadDone = (Boolean)attributeMap.get('UploadDone');
String EmailQueueIdStr = (String)attributeMap.get('EmailQueueId');
String parentId = (String)attributeMap.get('ParentId');
Id EmailQueueId = (Id)attributeMap.get('EmailQueueId');
System.debug('attachId----'+attachmentId);
if(String.isNotEmpty(attachmentId)){
attachment = [SELECT Id,Body FROM Attachment WHERE Id =:attachmentId WITH SECURITY_ENFORCED];
String newBody = '';
Blob AttachmentBlob = attachment.Body;
if(AttachmentBlob != null) {
newBody = EncodingUtil.base64Encode(AttachmentBlob);
}
newBody += content;
//attch.Body = Blob.valueOf(newBody);
if(Schema.sObjectType.Attachment.fields.Body.isCreateable() && Schema.sObjectType.Attachment.fields.Body.isupdateable()){
attachment.Body = EncodingUtil.base64Decode(newBody);
}
if(Schema.sObjectType.Attachment.isCreateable() && Schema.sObjectType.Attachment.isupdateable()){
upsert attachment;
}
returnMap.put('AttchId', attachment.Id);
System.debug('New Attachment----'+attachment.Id);
}else{
if(content !=null){
String[] base64result = safeSplit(content,',');
System.debug('Attachment Size --->'+base64result.size());
if(base64result !=null && base64result.size() > 1){
System.debug('Attachment Body3--->'+base64result[1]);
if(Schema.sObjectType.Attachment.fields.Body.isCreateable()){
attachment.Body = EncodingUtil.base64Decode(base64result[1]);
}
System.debug('base64Decode3-->'+attachment.Body);
if(Schema.sObjectType.Attachment.fields.Name.isCreateable()){
attachment.Name = (String)attributeMap.get('AttachmentName');
}
if(Schema.sObjectType.Attachment.fields.ParentId.isCreateable()){
attachment.ParentId = (Id)attributeMap.get('EmailQueueId');
}
if(Schema.sObjectType.Attachment.isCreateable()){
insert attachment;
}
returnMap.put('AttchId', attachment.Id);
System.debug('New Attachment----'+attachment.Id);
}
}
}
if(isUploadDone){
emailObj = getEmailQueueDetails(EmailQueueIdStr);
attachmentIdArray = getAttachmentIdOnEmailQueueforId(EmailQueueId);
System.debug('GNT__EmailQueue__c Update...'+emailObj);
System.debug('Attachment Array Id..'+attachmentIdArray);
Boolean sendACopyToMe = (Boolean)attributeMap.get('sendACopyToMe');
// add to address, cc address, Bcc address in map, GNT__Subject__c and email body
String toAddress =(String)attributeMap.get('toAddress');
String ccAddress =(String)attributeMap.get('ccAddress');
String subject =(String)attributeMap.get('GNT__Subject__c');
String emailBody=(String)attributeMap.get('body');
String bccAddress = '';
if(sendACopyToMe){
bccAddress = UserInfo.getUserEmail();
}
sendEMail(emailObj, parentId, sendACopyToMe, attachmentIdArray, toAddress, ccAddress, bccAddress, subject, emailBody);
}
return returnMap;
}
https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
If you face any specific issue while attempting do post that here.
Thanks!