• Eric Teseur
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies

Hello, I have a class and I need write a test
Here is my code:

public with sharing class arcListClass {

 @AuraEnabled
 public static void saveInput(List < DerexSoft__c > ListDerexSoft) {
  Insert ListDerexSoft;
 }
 @AuraEnabled
 public List < DerexSoft__c > arcList = new List < DerexSoft__c > ();

 @AuraEnabled
 public List < DerexSoft__c > softrec = new List < DerexSoft__c > ();

    @AuraEnabled
 public List < DerexSoft__c > dectrec = new List < DerexSoft__c > ();    

 @AuraEnabled(cacheable = true)
 public static List < DerexSoft__c > getArray(String query) {
  arcListClass alc = new arcListClass();
  alc.arcList = Database.query('SELECT Id, Uforted__c, Softed__c, Context__c,  LastModifiedDate FROM DerexSoft__c ORDER BY Context__c asc LIMIT 1');
  return alc.arcList;
 }
 @AuraEnabled
 public static List < DerexSoft__c > delSlctRec(List < String > slctRec) {
  arcListClass alc = new arcListClass();
  alc.dectrec = [SELECT Id FROM DerexSoft__c WHERE Id IN: slctRec];
  try {
   delete alc.dectrec;
  } catch (Exception ex) {
   throw new AuraHandledException(ex.getMessage());
  }
  alc.arcList = Database.query('SELECT Id, Uforted__c, Softed__c, Context__c, LastModifiedDate FROM DerexSoft__c LIMIT 1');

  return alc.arcList;

 }
 @AuraEnabled
 public static List < DerexSoft__c > sortSlctRec(List < String > slctRec) {
    // Integer integerExamp = 0;
  List < DerexSoft__c > softrec = new List < DerexSoft__c > ();
  arcListClass alc = new arcListClass();
 List <DerexSoft__c> sortApRec = [SELECT Id, Uforted__c, Softed__c,  Context__c FROM DerexSoft__c WHERE Id IN: slctRec];
  try {
   
        for(DerexSoft__c sortobj : sortApRec){
            String sortString = sortobj.Uforted__c;
            List<String> sortList = sortString.split(',');
            List<Integer> intList = new List<Integer>();
            for(String s : sortList){
                intList.add(Integer.valueOf(s));
            }
            Integer compl  = QuickSort.sort(intList); 
            sortString = string.join(intList,'.'); // pass  .\,\;
            sortobj.Softed__c = sortString;
            sortobj.Context__c = compl;
            softrec.add(sortobj);
            
        }    
        update softrec;  
        softrec.clear();  

  } catch (Exception ex) {
   throw new AuraHandledException(ex.getMessage());
  }
  alc.arcList = Database.query('SELECT Id, Uforted__c, Softed__c, Context__c,  LastModifiedDate FROM DerexSoft__c ORDER BY Context__c LIMIT 1');
  return alc.arcList;

 }
    
    
}
I have a tab where i save my values in Unsorted column. And when I check checkbox I want to copy value from Unsorted column then sort it and save in Sorted column
User-added image

Hi ,
How to write the trigger handler for my below code,

trigger DerexSortTrigger on DerexSoft__c (before insert, before update) {

 for( DerexSoft__c  aps:trigger.new){

Boolean valArr;
String uforted;        
String ArrPat;        
ArrPat = '^\\d?[1-9][,\\;\\.]\\d?[1-9][,\\;\\.]\\d?[1-9][,\\;\\.]\\d?[1-9][,\\;\\.]\\d?[1-9]$';

uforted = aps.Uforted__c;
valArr = Pattern.matches(ArrPat,uforted);

if(aps.Uforted__c != null && valArr!= true ){
    aps.Uforted__c.addError();                   

                }
        }
}

I have a custom object with several fields. One of them have Lookup on Contact. And in my component I try to send email with the rich-text from record to email address linking with Contact, but nothing happen. After clicking on the component, I get a modal box, then I just want to click on the Email button without entering the any address (the address is Contact.Email related to this record) My rich-text edit should be the body of the letter, but the data from my record should be stored in it. Any solutions?

Thank you

 

 

Component:

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global">

   <aura:attribute name="record" type="Rotation__c" default="{ 'sobjectType' : 'Rotation__c' }"/>
    
    <aura:attribute name="recordId" type="Id" />
   
  <aura:attribute name="isOpen" type="Boolean" default="false"/>
  
 <aura:attribute name="myVal" type="String" />
    
    <aura:attribute name="email" type="string"/>
   <aura:attribute name="subject" type="string"/>
   <aura:attribute name="bodytext" type="string"/>

    
    <!--!  <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> -->
  <!--Use "slds-m-around- -xx-large" class to add standard Large padding to the component--> 
  <div class="slds-m-around--xx-large">
    <button class="slds-button slds-button--brand" onclick="{!c.openModel}">Rotation details</button>  
  
  <!--Use aura:if tag to display Model Box, on the bese of conditions. [isOpen boolean attribute] -->   
    <aura:if isTrue="{!v.isOpen}">
      
   <!--###### MODAL BOX Start From Here ######--> 
      <div role="dialog" tabindex="-1" aria-labelledby="header99" class="slds-modal slds-fade-in-open ">
        <div class="slds-modal__container">
          <!-- ###### MODAL BOX HEADER Part Start From Here ######-->
          <div class="slds-modal__header">
            <button class="slds-button slds-modal__close slds-button--icon-inverse" title="Close" onclick="{!c.closeModel}">
            X
                
                
            <span class="slds-assistive-text">Close</span>
            </button>
              <lightning:recordEditForm
                     aura:id="editForm"
                     recordId="{!v.recordId}"
                     recordTypeId="{!v.recordTypeId}"
                     onsuccess="{!c.handleSuccess}"
                                    
                     objectApiName="Rotation__c">
                     <lightning:messages />
                  <div class="slds-form-element__control">
               <h2 id="header99" class="slds-text-heading--medium">Rotation Edit</h2>
                  <lightning:inputField fieldName="Name" value="{!v.record.Name}"/>
               </div>
                <div class="slds-form-element__control">
                  <lightning:inputField fieldName="Contact__c" value="{!v.record.Contact__c}"/>
               </div>
                 
                  
                  <div class="slds-form-element__control">
                  <lightning:inputField fieldName="Amount__c" value="{!v.record.Amount__c}"/>
               </div>
                 
                 
               </div>
                  
                   <div class="slds-form-element__control">
                  <ui:inputEmail class="slds-input" aura:id="email"  value="{!v.email}" required="true" placeholder="enter@email.com"/>
                    </div>
                  <div class="slds-form-element__control">
                        <lightning:inputField fieldName="Payment__c" value="{!v.record.Payment_Method__c}"/>
                        <lightning:inputRichText value="{!v.record.Payment__c}"/>
               </div>
         
                    </lightning:recordEditForm>
           
          </div>     
          <!--###### MODAL BOX FOOTER Part Start From Here ######-->
          <div class="slds-modal__footer">
            <button class="slds-button slds-button--neutral" onclick="{!c.closeModel}" >Cancel</button>
             <lightning:button variant="brand" label="Save" type="submit" onclick = "{!c.handleSubmit}"/>
             <lightning:button variant="brand" label="Email" type="submit" onclick = "{!c.sendMailMethod}"/>
              
         
          </div>
        </div>
      </div>
      <div class="slds-backdrop slds-backdrop--open"></div>
      <!--###### MODAL BOX Part END Here ######-->
    
 </aura:if>
  </div>
</aura:component>

Controller:

({
   openModel: function(component, event, helper) {
      // for Display Model,set the "isOpen" attribute to "true"
      component.set("v.isOpen", true);
   },
 
   closeModel: function(component, event, helper) {
      // for Hide/Close Model,set the "isOpen" attribute to "Fasle"  
      component.set("v.isOpen", false);
   },
 
    handleSubmit:function(component,event, helper){
      event.preventDefault();
      var eventFields = event.getParam("fields");
      component.find('editForm').submit(eventFields);
      //var result = component.find("editForm").submit();
       component.set("v.isOpen", false);
  },
  
   handleSuccess :function(component, helper) {
      var homeEvt = $A.get("e.force:navigateToSObject");
      homeEvt.setParams({
          "recordId": component.get("v.recordId")
      });
      homeEvt.fire();     
  },
    
 
     
    sendMailMethod: function(component, event, helper) {
        // when user click on Send button 
        // First we get all 3 fields values 	
        var getEmail = component.get("v.email");
        var getSubject = component.get("v.subject");
        var getbody = component.get("v.bodytext");
        var getrecordId = component.get("v.recordId");
    
        
        // check if Email field is Empty or not contains @ so display a alert message 
        // otherwise call call and pass the fields value to helper method    
        if ($A.util.isEmpty(getEmail) || !getEmail.includes("@")) {
            alert('Please Enter valid Email Address');
        } else {
            helper.sendHelper(component, event, helper,getEmail, getSubject, getbody, getrecordId);
        }
    },
 
    // when user click on the close buttton on message popup ,
    closeMessage: function(component, event, helper) {
        component.set("v.mailStatus", false);
        component.set("v.email", null);
        component.set("v.subject", null);
        component.set("v.bodytext", null);

}, 
   
})

Helper:

({
 sendHelper: function(component,event,helper, getEmail, getSubject, getbody, getrecordId) {
        console.log('helperrecid'+getrecordId);
        // call the server side controller method 	
        var action = component.get("c.sendMailMethod");
        // set the 3 params to sendMailMethod method 
        action.setParams({
            'mMail': getEmail,
            'mSubject': getSubject,
            'mbody': getbody,
            'recordid':getrecordId
        });
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var storeResponse = response.getReturnValue();
                var applicationEvent = $A.get("e.c:EventCloseModelPopup");
                applicationEvent.setParams({"message" : 'success'})
                applicationEvent.fire();
                console.log('cmpEvent '+applicationEvent);
                console.log('applicationEvent event fired');                
            }
            
        });
        $A.enqueueAction(action);
}
})

Apex Method:

public static void sendMailMethod(String mMail ,String mSubject ,String mbody,string recordId){

        //Inserting the record id in Email subject
        string subrec= '('+ recordId +')';  
        // For storing Relation Id
        string opcid ='';
        //Email Sending Start
        List<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
        //Create a new Email
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();        
        //Set list of people who should get the email        
        List<String> sendTo = mMail.split(',');
        //Setting Senders
        mail.setToAddresses(sendTo);        
        String addrUrl='e62ubs9wkx9ma0e6akh8qbbwtli5o6hpjy.7f-4wpbcua2.ap5.apex.salesforce.com';

        // Set who the email is sent from
        mail.setReplyTo(addrUrl); // change it with your mail address.
        mail.setSenderDisplayName(UserInfo.getName() ); 
        system.debug('>>>>>=='+ UserInfo.getName() );   
        // Subject from Email Component and Record ID
        mail.setSubject(mSubject + subrec );
        //Setting Body from Email Component
        mail.setHtmlBody(mbody);        
        // Add your email to the master list
        mails.add(mail);       
         //Add Inbound Email Message for contact
            EmailMessage caseEmailMessage = new EmailMessage();
            caseEmailMessage.fromAddress= UserInfo.getUserEmail();
            caseEmailMessage.ToAddress = mMail;
            caseEmailMessage.FromName = UserInfo.getName();
            caseEmailMessage.Subject = mSubject;
            caseEmailMessage.HtmlBody = mbody;
            caseEmailMessage.Incoming= False;
            caseEmailMessage.TextBody = mbody;
            caseEmailMessage.status = '3';

            if(recordId.startsWith('003')){
                caseEmailMessage.Contact__c = recordId;
            }

            insert caseEmailMessage;  


             // Add Email Message Relation for id of the sender
            EmailMessageRelation emr = new EmailMessageRelation();
            emr.EmailMessageId = caseEmailMessage.id;
            emr.RelationAddress = UserInfo.getUserEmail();
            emr.RelationType = 'FromAddress';

            //Contact Email Message Relation Id
            if(recordId.startsWith('003')){
                 emr.RelationId = recordId;
            }


          //Reservation Email Message Relation Id
            else if(recordId.startsWith('a1B')){
                 emr.RelationId = recordId;
            }

                        insert emr;     


            // Send all emails in the master list
            Messaging.sendEmail(mails);



}
 

 

I have a tab where i save my values in Unsorted column. And when I check checkbox I want to copy value from Unsorted column then sort it and save in Sorted column
User-added image

Hi ,
How to write the trigger handler for my below code,

trigger DerexSortTrigger on DerexSoft__c (before insert, before update) {

 for( DerexSoft__c  aps:trigger.new){

Boolean valArr;
String uforted;        
String ArrPat;        
ArrPat = '^\\d?[1-9][,\\;\\.]\\d?[1-9][,\\;\\.]\\d?[1-9][,\\;\\.]\\d?[1-9][,\\;\\.]\\d?[1-9]$';

uforted = aps.Uforted__c;
valArr = Pattern.matches(ArrPat,uforted);

if(aps.Uforted__c != null && valArr!= true ){
    aps.Uforted__c.addError();                   

                }
        }
}

I have a custom object with several fields. One of them have Lookup on Contact. And in my component I try to send email with the rich-text from record to email address linking with Contact, but nothing happen. After clicking on the component, I get a modal box, then I just want to click on the Email button without entering the any address (the address is Contact.Email related to this record) My rich-text edit should be the body of the letter, but the data from my record should be stored in it. Any solutions?

Thank you

 

 

Component:

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global">

   <aura:attribute name="record" type="Rotation__c" default="{ 'sobjectType' : 'Rotation__c' }"/>
    
    <aura:attribute name="recordId" type="Id" />
   
  <aura:attribute name="isOpen" type="Boolean" default="false"/>
  
 <aura:attribute name="myVal" type="String" />
    
    <aura:attribute name="email" type="string"/>
   <aura:attribute name="subject" type="string"/>
   <aura:attribute name="bodytext" type="string"/>

    
    <!--!  <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> -->
  <!--Use "slds-m-around- -xx-large" class to add standard Large padding to the component--> 
  <div class="slds-m-around--xx-large">
    <button class="slds-button slds-button--brand" onclick="{!c.openModel}">Rotation details</button>  
  
  <!--Use aura:if tag to display Model Box, on the bese of conditions. [isOpen boolean attribute] -->   
    <aura:if isTrue="{!v.isOpen}">
      
   <!--###### MODAL BOX Start From Here ######--> 
      <div role="dialog" tabindex="-1" aria-labelledby="header99" class="slds-modal slds-fade-in-open ">
        <div class="slds-modal__container">
          <!-- ###### MODAL BOX HEADER Part Start From Here ######-->
          <div class="slds-modal__header">
            <button class="slds-button slds-modal__close slds-button--icon-inverse" title="Close" onclick="{!c.closeModel}">
            X
                
                
            <span class="slds-assistive-text">Close</span>
            </button>
              <lightning:recordEditForm
                     aura:id="editForm"
                     recordId="{!v.recordId}"
                     recordTypeId="{!v.recordTypeId}"
                     onsuccess="{!c.handleSuccess}"
                                    
                     objectApiName="Rotation__c">
                     <lightning:messages />
                  <div class="slds-form-element__control">
               <h2 id="header99" class="slds-text-heading--medium">Rotation Edit</h2>
                  <lightning:inputField fieldName="Name" value="{!v.record.Name}"/>
               </div>
                <div class="slds-form-element__control">
                  <lightning:inputField fieldName="Contact__c" value="{!v.record.Contact__c}"/>
               </div>
                 
                  
                  <div class="slds-form-element__control">
                  <lightning:inputField fieldName="Amount__c" value="{!v.record.Amount__c}"/>
               </div>
                 
                 
               </div>
                  
                   <div class="slds-form-element__control">
                  <ui:inputEmail class="slds-input" aura:id="email"  value="{!v.email}" required="true" placeholder="enter@email.com"/>
                    </div>
                  <div class="slds-form-element__control">
                        <lightning:inputField fieldName="Payment__c" value="{!v.record.Payment_Method__c}"/>
                        <lightning:inputRichText value="{!v.record.Payment__c}"/>
               </div>
         
                    </lightning:recordEditForm>
           
          </div>     
          <!--###### MODAL BOX FOOTER Part Start From Here ######-->
          <div class="slds-modal__footer">
            <button class="slds-button slds-button--neutral" onclick="{!c.closeModel}" >Cancel</button>
             <lightning:button variant="brand" label="Save" type="submit" onclick = "{!c.handleSubmit}"/>
             <lightning:button variant="brand" label="Email" type="submit" onclick = "{!c.sendMailMethod}"/>
              
         
          </div>
        </div>
      </div>
      <div class="slds-backdrop slds-backdrop--open"></div>
      <!--###### MODAL BOX Part END Here ######-->
    
 </aura:if>
  </div>
</aura:component>

Controller:

({
   openModel: function(component, event, helper) {
      // for Display Model,set the "isOpen" attribute to "true"
      component.set("v.isOpen", true);
   },
 
   closeModel: function(component, event, helper) {
      // for Hide/Close Model,set the "isOpen" attribute to "Fasle"  
      component.set("v.isOpen", false);
   },
 
    handleSubmit:function(component,event, helper){
      event.preventDefault();
      var eventFields = event.getParam("fields");
      component.find('editForm').submit(eventFields);
      //var result = component.find("editForm").submit();
       component.set("v.isOpen", false);
  },
  
   handleSuccess :function(component, helper) {
      var homeEvt = $A.get("e.force:navigateToSObject");
      homeEvt.setParams({
          "recordId": component.get("v.recordId")
      });
      homeEvt.fire();     
  },
    
 
     
    sendMailMethod: function(component, event, helper) {
        // when user click on Send button 
        // First we get all 3 fields values 	
        var getEmail = component.get("v.email");
        var getSubject = component.get("v.subject");
        var getbody = component.get("v.bodytext");
        var getrecordId = component.get("v.recordId");
    
        
        // check if Email field is Empty or not contains @ so display a alert message 
        // otherwise call call and pass the fields value to helper method    
        if ($A.util.isEmpty(getEmail) || !getEmail.includes("@")) {
            alert('Please Enter valid Email Address');
        } else {
            helper.sendHelper(component, event, helper,getEmail, getSubject, getbody, getrecordId);
        }
    },
 
    // when user click on the close buttton on message popup ,
    closeMessage: function(component, event, helper) {
        component.set("v.mailStatus", false);
        component.set("v.email", null);
        component.set("v.subject", null);
        component.set("v.bodytext", null);

}, 
   
})

Helper:

({
 sendHelper: function(component,event,helper, getEmail, getSubject, getbody, getrecordId) {
        console.log('helperrecid'+getrecordId);
        // call the server side controller method 	
        var action = component.get("c.sendMailMethod");
        // set the 3 params to sendMailMethod method 
        action.setParams({
            'mMail': getEmail,
            'mSubject': getSubject,
            'mbody': getbody,
            'recordid':getrecordId
        });
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var storeResponse = response.getReturnValue();
                var applicationEvent = $A.get("e.c:EventCloseModelPopup");
                applicationEvent.setParams({"message" : 'success'})
                applicationEvent.fire();
                console.log('cmpEvent '+applicationEvent);
                console.log('applicationEvent event fired');                
            }
            
        });
        $A.enqueueAction(action);
}
})

Apex Method:

public static void sendMailMethod(String mMail ,String mSubject ,String mbody,string recordId){

        //Inserting the record id in Email subject
        string subrec= '('+ recordId +')';  
        // For storing Relation Id
        string opcid ='';
        //Email Sending Start
        List<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
        //Create a new Email
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();        
        //Set list of people who should get the email        
        List<String> sendTo = mMail.split(',');
        //Setting Senders
        mail.setToAddresses(sendTo);        
        String addrUrl='e62ubs9wkx9ma0e6akh8qbbwtli5o6hpjy.7f-4wpbcua2.ap5.apex.salesforce.com';

        // Set who the email is sent from
        mail.setReplyTo(addrUrl); // change it with your mail address.
        mail.setSenderDisplayName(UserInfo.getName() ); 
        system.debug('>>>>>=='+ UserInfo.getName() );   
        // Subject from Email Component and Record ID
        mail.setSubject(mSubject + subrec );
        //Setting Body from Email Component
        mail.setHtmlBody(mbody);        
        // Add your email to the master list
        mails.add(mail);       
         //Add Inbound Email Message for contact
            EmailMessage caseEmailMessage = new EmailMessage();
            caseEmailMessage.fromAddress= UserInfo.getUserEmail();
            caseEmailMessage.ToAddress = mMail;
            caseEmailMessage.FromName = UserInfo.getName();
            caseEmailMessage.Subject = mSubject;
            caseEmailMessage.HtmlBody = mbody;
            caseEmailMessage.Incoming= False;
            caseEmailMessage.TextBody = mbody;
            caseEmailMessage.status = '3';

            if(recordId.startsWith('003')){
                caseEmailMessage.Contact__c = recordId;
            }

            insert caseEmailMessage;  


             // Add Email Message Relation for id of the sender
            EmailMessageRelation emr = new EmailMessageRelation();
            emr.EmailMessageId = caseEmailMessage.id;
            emr.RelationAddress = UserInfo.getUserEmail();
            emr.RelationType = 'FromAddress';

            //Contact Email Message Relation Id
            if(recordId.startsWith('003')){
                 emr.RelationId = recordId;
            }


          //Reservation Email Message Relation Id
            else if(recordId.startsWith('a1B')){
                 emr.RelationId = recordId;
            }

                        insert emr;     


            // Send all emails in the master list
            Messaging.sendEmail(mails);



}