• vicky kr 3
  • NEWBIE
  • 20 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 5
    Replies
Here Is My Apex Code,
It working well,Test class stuck at 62%

APEX
@RestResource(urlMapping='/v1/tcwc/')
global class testingCaseWithContact {
   @HttpPost
    global static Case casecreate(String Email,String lastName){
        
        List<Contact> cont=[Select Id,lastName,Email from Contact];
        for(Contact con:cont){
            
            if(con.Email!='Email'){ System.debug('=====ERROR====='); }
        
            else{
                Case newCase=new Case(Subject='CaseWithContactInsert',Origin='Chat',Status='Open');

                insert newCase;  
                 newCase=[Select Id,CaseNumber,ContactId from Case ORDER BY CreatedDate DESC LIMIT 1];
               
            }
        }
        
        return [Select Id,CaseNumber,ContactId from Case ORDER BY CreatedDate DESC LIMIT 1];  

    }
    
}


TEST CLASS

@isTest(SeeAllData=false)
public class testingCaseWithContact_Test {
    @IsTest
    static void testDoPost(){
        Contact c = new contact(LastName='Demo',Email='test@gmail.com');
        Insert c;
        
        Case  TestOpp=new Case ();
        TestOpp.Subject='CaseDataWithContactInsert';
        TestOpp.Origin='Chat';
        TestOpp.Status='Open';
        TestOpp.ChatHistory__c='Chat For demo';
        TestOpp.ContactID=c.id;
        insert TestOpp;
        
        Integer count=[select count() from case where Id=:TestOpp.Id Limit 1];
        System.assertEquals(1,count);
        
        testingCaseWithContact reqst=new testingCaseWithContact();
        String JsonMsg=JSON.serialize(reqst);
        Test.startTest();
        
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();
        
        req.requestURI = '/services/apexrest/v1/tcwc/';  //Request URL
        req.httpMethod = 'POST';//HTTP Request Type
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
        // Test.startTest();
        testingCaseWithContact.casecreate('test@gmail.com','Demo');
        insert TestOpp;
        Case a=[Select Id,Status from Case Where Id=:TestOpp.Id ORDER BY CreatedDate DESC LIMIT 1];
        System.assertEquals('Open',a.Status);
        Test.stopTest();
        
 }
}


 
Case priority picklist values=['low','Mid','High']

Case status picklist values=['New','Open','Escalated','Close']

I want a lightning component with controller with fill filter record based on my picklist values selection

Eg:1
If i select
 case priority:'High' and  case Status:'New'

It displays all cases whose priority is high and status is new
 

Eg2
If i choose 
case priority:'High' 
Only Show all cases with high priority ,
inspite of there staus

Eg3
If i choose 
case status:'New' 
Only Show all cases with status:'New'  ,
inspite of there priority
I want to filter record with help of input checkbox
Like for Priority of case low,high, medium should be come in drop down with checkbox in those options
and
Origin of case Email,phone,weebsite dropdown will come with checkbox in those options
and 
Status of case New,Working,Esclated dropdown will come with checkbox in those options

Now ,,
based on that we check it shows the records Eg
if u check high,medium fron Priority of case
And
if u check Email,phone from Origin of case
And
if u check New,Working from status of case

Then it will filter records based on selection


Its Really Very Urgent for me to do this,

i am very new to lightning 
Any Help from your end would be very Appericiated

I want to filter record with help of input checkbox
Like for Priority of case low,high, medium should be come in drop down with checkbox in those options
and
Origin of case Email,phone,weebsite dropdown will come with checkbox in those options
and 
Status of case New,Working,Esclated dropdown will come with checkbox in those options

Now ,,
based on that we check it shows the records Eg
if u check high,medium fron Priority of case
And
if u check Email,phone from Origin of case
And
if u check New,Working from status of case

Then it will filter records based on selection


Its Really Very Urgent for me to do this,

i am very new to lightning 
Any Help from your end would be very Appericiated
public class eventCreation {
//eventCreation.demoEvent();
    public static void demoEvent(){
Event newEvent = new Event();
newEvent.OwnerId = '0055i000003MTGlAAO';
newEvent.Subject ='Testing Demo event';
//newEvent.WhatId = recordId;
newEvent.ActivityDate = System.today();
newEvent.IsRecurrence = true;
newEvent.RecurrenceStartDateTime = System.today();
newEvent.RecurrenceEndDateOnly = System.today()+30;
newEvent.RecurrenceType = 'RecursDaily';
newEvent.RecurrenceInterval = 1;
newEvent.IsAllDayEvent =true;
newEvent.DurationInMinutes =1440;

insert newEvent;
    }
}
SOURCE FROM WHERE I REFFERED:

https://salesforce.stackexchange.com/questions/218915/upload-file-and-save-it-as-attachment-using-lightning-component

In My Apex Class M getting ERROR  Here:

 efa.setBody(EncodingUtil.base64Decode(a.ContentDocument.LatestPublishedVersion.VersionData));

Error is:
Method does not exist or incorrect signature: void base64Decode(Blob) from the type System.EncodingUtil

BELOW IS MY APEX CODE(JUST PASTE IN YOUR ORG and Try)

public with sharing class SendEmailController {
    @AuraEnabled
    public static void sendEmailAction(String eTo, String eCc, String eBcc, String eSubject, String eBody, String eFrom, List<String> attach){
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        
        System.debug('attach--'+attach);
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        mail.setToAddresses(new List<String>{eTo});
        
        if(eCc != '' && eCc != null)
            mail.setCcAddresses(new List<String>{eCc});
        
        if(eBcc != '' && eBcc != null)
            mail.setBccAddresses(new List<String>{eBcc});
        
        mail.setSubject(eSubject);
        if(eFrom != null)
            mail.setInReplyTo(eFrom);
        
        List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (ContentDocumentLink a : [SELECT id,ContentDocument.Title,ContentDocument.FileType,ContentDocument.FileExtension,
                                      ContentDocument.LatestPublishedVersionId,ContentDocument.LatestPublishedVersion.VersionData  
                                      FROM ContentDocumentLink WHERE LinkedEntityID =:attach])
        {
            Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
            
           
                       
            //a.ContentDocument.LatestPublishedVersion.VersionData is a Base64 String. Converting it into Blob
              
            
            //BELOW LINE SHOWING THE ERROR  
           efa.setBody(EncodingUtil.base64Decode(a.ContentDocument.LatestPublishedVersion.VersionData));
         
            /*ERROR====>
          Method does not exist or incorrect signature: void base64Decode(Blob) from the type System.EncodingUtil
          */      
            
            fileAttachments.add(efa);
        }
        mail.setEntityAttachments(attach);
        mail.setHtmlBody(eBody);
        mails.add(mail);
        System.debug('Email-->>'+mails);
        /*Messaging.SendEmailResult[] results = Messaging.sendEmail(mails);

if (results[0].success)
System.debug('The email was sent successfully.');
else
System.debug('The email failed to send: ' + results[0].errors[0].message);*/
    }
    
    @AuraEnabled
    public static List<OrgWideEmailAddress> getOrgWideEmailAddress(){
        return [SELECT Id, Address, DisplayName from OrgWideEmailAddress];
    }
}



LIGHTNING COMPONENT:SendEmailController

SendEmailController.cmp

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="SendEmailController">
<aura:attribute name="to" type="String"/>
<aura:attribute name="cc" type="String"/>
<aura:attribute name="bcc" type="String"/>
<aura:attribute name="subject" type="String"/>
<aura:attribute name="body" type="String"/>
<aura:attribute name="from" type="OrgWideEmailAddress[]" />
<aura:attribute name="files" type="List"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>

<div class="slds-container--medium">
    <div class="slds-form">
        <div class="slds-form-element">
            <div class="slds-form-element__control">
                <lightning:select name="select" label="From:" aura:id="fromId">
                    <option value="">--None--</option>
                    <aura:iteration items="{!v.from}" var="frmAdd">
                        <option text="{!frmAdd.DisplayName}" value="{!frmAdd.Address}"></option>
                    </aura:iteration>
                </lightning:select>
            </div>
        </div>
        <div class="slds-form-element">
            <div class="slds-form-element__control">
                <lightning:input type="email" aura:id="isValid" label="To:" value="{!v.to}" name="toAddress" required="true" messageWhenRangeUnderflow="Please provide valid email"/>
            </div>
        </div>
        <div class="slds-form-element">
            <div class="slds-form-element__control">
                <lightning:input type="email" aura:id="isValid" label="CC:" value="{!v.cc}" name="cc" messageWhenRangeUnderflow="Please provide valid email"/>
            </div>
        </div>
        <div class="slds-form-element">
            <div class="slds-form-element__control">
                <lightning:input type="email" aura:id="isValid" label="BCC:" value="{!v.bcc}" name="bcc" messageWhenRangeUnderflow="Please provide valid email"/>
            </div>  
        </div>
        <div class="slds-form-element">
            <div class="slds-form-element__control">
                <lightning:input type="text" label="Subject:" name="subject" value="{!v.subject}"/>
            </div>
        </div>
        <div class="slds-form-element">
            <div class="slds-form-element__control">
                <label class="slds-form-element__label" >Body:</label>
                <lightning:inputRichText placeholder="Type email body" value="{!v.body}"/>
            </div>
        </div>
        <div class="slds-form-element">
            <div class="slds-form-element__control">    
                 <lightning:fileUpload label="Upload File" multiple="true" accept=".pdf, .png, .txt" recordId="{!v.recordId}" aura:id="multifileUpload" onuploadfinished="{!c.uploadFile}" />
            </div>
        </div>
        <div class="slds-form-element">
            <div class="slds-form-element__control">    
                <lightning:button class="slds-button slds-button--brand" onclick="{!c.sendEmail}">Send</lightning:button>
            </div>
        </div>
    </div>
</div>
</aura:component>


CONTROLLER:



({

    doInit: function(component, event, helper) {
        var action = component.get("c.getOrgWideEmailAddress");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.from", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
        $A.enqueueAction(action);
    },
    sendEmail: function(component, event, helper) {
        var to = component.get("v.to");
        var cc = component.get("v.cc");
        var bcc = component.get("v.bcc");
        var subject = component.get("v.subject");
        var body = component.get("v.body");
        var from = component.find("fromId").get("v.value");
        //console.log('files before send--'+JSON.stringify(component.get("v.files")));
        var attachments = component.get("v.files");
        //console.log('Added attachments--'+attachments.length);
        var validEmail = component.find('isValid').reduce(function (validSoFar, inputCmp) {
                inputCmp.showHelpMessageIfInvalid();
            return validSoFar && inputCmp.get('v.validity').valid;
        }, true);
        if(validEmail){
            console.log('attachments---'+JSON.stringify(attachments));
            helper.sendEmailHelper(component, to, cc, bcc, subject, body, from, attachments);
        }
    },
    uploadFile: function(component, event, helper){
        var uploadedFiles = component.get("v.files");
        var singleFile = event.getParam("files");
        //console.log('document Id2-->'+singleFile.get('documentId'));
        for(var i = 0; i < singleFile.length; i++){
            console.log('elements--'+JSON.stringify(singleFile[i].documentId));
            uploadedFiles.push(JSON.stringify(singleFile[i].documentId));
        }
        component.set("v.files", uploadedFiles);
    }
})

HELPER

({
    sendEmailHelper : function(component, getTo, getCc, getBcc, getSubject, getBody, getFrom,getAttachments) {
        var action = component.get("c.sendEmailAction");
        console.log('getAttachments in helper--'+JSON.stringify(getAttachments));
        action.setParams({
            'eTo' : getTo,
            'eCc' : getCc,
            'eBcc': getBcc,
            'eSubject' : getSubject,
            'eBody' : getBody,
            'eFrom' : getFrom,
            'attach' : getAttachments
        });
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state == "SUCCESS")
                alert('Email Send successfully..!!');
            else
                alert('Failed to send Email..!!');
        });
        
        $A.enqueueAction(action);
    }
})
Here Is My Apex Code,
It working well,Test class stuck at 62%

APEX
@RestResource(urlMapping='/v1/tcwc/')
global class testingCaseWithContact {
   @HttpPost
    global static Case casecreate(String Email,String lastName){
        
        List<Contact> cont=[Select Id,lastName,Email from Contact];
        for(Contact con:cont){
            
            if(con.Email!='Email'){ System.debug('=====ERROR====='); }
        
            else{
                Case newCase=new Case(Subject='CaseWithContactInsert',Origin='Chat',Status='Open');

                insert newCase;  
                 newCase=[Select Id,CaseNumber,ContactId from Case ORDER BY CreatedDate DESC LIMIT 1];
               
            }
        }
        
        return [Select Id,CaseNumber,ContactId from Case ORDER BY CreatedDate DESC LIMIT 1];  

    }
    
}


TEST CLASS

@isTest(SeeAllData=false)
public class testingCaseWithContact_Test {
    @IsTest
    static void testDoPost(){
        Contact c = new contact(LastName='Demo',Email='test@gmail.com');
        Insert c;
        
        Case  TestOpp=new Case ();
        TestOpp.Subject='CaseDataWithContactInsert';
        TestOpp.Origin='Chat';
        TestOpp.Status='Open';
        TestOpp.ChatHistory__c='Chat For demo';
        TestOpp.ContactID=c.id;
        insert TestOpp;
        
        Integer count=[select count() from case where Id=:TestOpp.Id Limit 1];
        System.assertEquals(1,count);
        
        testingCaseWithContact reqst=new testingCaseWithContact();
        String JsonMsg=JSON.serialize(reqst);
        Test.startTest();
        
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();
        
        req.requestURI = '/services/apexrest/v1/tcwc/';  //Request URL
        req.httpMethod = 'POST';//HTTP Request Type
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
        // Test.startTest();
        testingCaseWithContact.casecreate('test@gmail.com','Demo');
        insert TestOpp;
        Case a=[Select Id,Status from Case Where Id=:TestOpp.Id ORDER BY CreatedDate DESC LIMIT 1];
        System.assertEquals('Open',a.Status);
        Test.stopTest();
        
 }
}


 
Case priority picklist values=['low','Mid','High']

Case status picklist values=['New','Open','Escalated','Close']

I want a lightning component with controller with fill filter record based on my picklist values selection

Eg:1
If i select
 case priority:'High' and  case Status:'New'

It displays all cases whose priority is high and status is new
 

Eg2
If i choose 
case priority:'High' 
Only Show all cases with high priority ,
inspite of there staus

Eg3
If i choose 
case status:'New' 
Only Show all cases with status:'New'  ,
inspite of there priority
public class eventCreation {
//eventCreation.demoEvent();
    public static void demoEvent(){
Event newEvent = new Event();
newEvent.OwnerId = '0055i000003MTGlAAO';
newEvent.Subject ='Testing Demo event';
//newEvent.WhatId = recordId;
newEvent.ActivityDate = System.today();
newEvent.IsRecurrence = true;
newEvent.RecurrenceStartDateTime = System.today();
newEvent.RecurrenceEndDateOnly = System.today()+30;
newEvent.RecurrenceType = 'RecursDaily';
newEvent.RecurrenceInterval = 1;
newEvent.IsAllDayEvent =true;
newEvent.DurationInMinutes =1440;

insert newEvent;
    }
}