• SFDC New learner
  • NEWBIE
  • 95 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 30
    Questions
  • 42
    Replies
When you click 'View All' on Related List, you get a list view of all the records. How can you customize that page?
I want to remove the 'New' action button on that page
Hi All,
I have couple of questions.
1. I have a class which is using Custom metadata type. Need to know whether this metadata type has permission to user.
How do we know that a user's profile has a permission to a metadata?
2. I have batch class which is having method and passing parameters as SObject and update the SObject. Which object will the user will need permission?
3. How to create report to track for pending approval request?

Any help will be greatly appreciated.

Thanks,
Sirisha

 
Hi All,

 Can anyone please explain to me how do you handle production issues in your project. what is the approach? 
Do you use Jira tool to raise a ticket for the case?

Say for example if we have 100 users and if one user is not receiving the email sent out of 100 users. what approach can be followed? And how can we fix the issue?

Thanks,
Sirisha
Hi All,

I have a user object with a username field. When I try to enter a letter, it should show all the values that start with that letter.

Say, for example, If I enter a letter J, it should display all the names that start with J like John, Jeff and so on.

How to implement this functionality using vf page?

Thanks,
Sirisha
Hi All,

If we have 2 record types with different fields and If we insert or update the records using data loader with specific record type like record type A.

Will it insert in that record type only or both? or If we give data to that both fields in both records irrespective of record type we give it will insert both fields in both records.

Thanks,
Sirisha
Hi All,

I am trying to create a new contact. Once the record is saved in Salesforce, an email need to be sent along with the unique id.

I have created a formula field for the Unique ID and associated record ID to this field.

Now, when I try to send an email with Unique ID, it shows null value.

<apex:page controller="SubmitNewContactController" docType="html-5.0">
   
    <apex:form>
        <apex:slds/>
    <apex:pageMessages></apex:pageMessages>
        <div class="slds-scope slds-box">
         <apex:outputPanel >
            <div class="slds-text-align_center slds-text-heading_medium"><p>Submit New Contact </p></div>
             <div class="slds-form-element">
                    <label class="slds-form-element__label"><abbr class="slds-required"></abbr> FirstName</label>
                <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!FirstName}" styleClass="slds-input" id="FirstName" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> LastName</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!LastName}" styleClass="slds-input" id="LastName" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> Phone</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!Phone}" styleClass="slds-input" id="Phone" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> Email</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!Email}" styleClass="slds-input" id="Email" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> Zipcode</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!Zipcode}" styleClass="slds-input" id="Zipcode" />
                </div>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:commandButton action="{!SubmitContact}" value="Submit"/> 
                </div>
            </div>
         </apex:outputPanel>   
        </div>
        
    
    </apex:form>
</apex:page>
public class SubmitNewContactController {
    public Contact c{get;set;}
    public String FirstName{get;set;}
    public String LastName{get;set;}
    public String phone{get;set;}
    public String Email{get;set;}
    public String Zipcode{get;set;}
    
    public SubmitNewContactController(){
        c = new Contact();
    }
    
    public PageReference SubmitContact(){
        c.FirstName = FirstName;
        c.LastName = LastName;
        c.phone = phone;
        c.Email = Email;
        c.MailingPostalCode = Zipcode;
        insert c;
        
        PageReference pr = new PageReference('/apex/ThankYouPage');
        Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
        String[] sendingTo = new String[]{c.Email};
        semail.setToAddresses(sendingTo);
        semail.setSubject('Registration is completed');
        semail.setPlainTextBody('Hi'+ c.name+'Thank you for registering.This is your UniqueID'+ c.Unique_ID__c);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
        pr.setRedirect(true);
        return pr;
        
        
        
    }
    

}

I am able to send the email but cannot capture the name and uniqueId in the email. It shows null in the email.
Can anyone please help me to fix the code?

Thanks,
Sirisha
 
Hi All,

 I am trying to pass the contact data from parent to child component on click of a button. Also, hide the parent component and show the child component using the lightning web component.
I have implemented this using lightning component.
Below is the sample code:

Parent component:
-----------------
<aura:component controller="login">
    
    <aura:attribute name="contact" type="Contact"/>
    <aura:registerEvent name="Authorizelogin" type="c:Authorizeloginevent"/>
    <div class="slds-hide" aura:id="login">
        <c:Authorizelogincontactdetails/>
    </div>
    <lightning:input name="UNAME" required="true" type="String" value="{!v.contact.LoginId__c}"/>
    <lightning:input name="PWD" required="true" type="String" value="{!v.contact.Password__c}"/>
    <lightning:button variant="brand" label="Submit" onclick="{!c.handlecontactdetails}"/>
</aura:component>

helper:
------

({
    contact : function(component,event,helper) {
        var action = component.get("c.getcontact");
        action.setParams({
            "uname":component.get("v.UNAME"),
            "pwd" : component.get("v.PWD")
        });
        action.setCallback(this,function(a){
            var response = a.getState();
            if(response==="SUCCESS"){
                var con = response.getReturnvalue();
            var myEvent = $A.get("e.c:Authorizeloginevent"); 
                myEvent.setParams({
                    "contact" : con
                });
                myEvent.fire();
            }
        });
    $A.enqueueAction(action);    
    }
})

child component:
---------------
<aura:component controller="login" >
    <aura:attribute name="FirstName" type="String"/>
    <aura:attribute name="LastName" type="String"/>
    <aura:attribute name="Email" type="String"/>
    <aura:attribute name="Phone" type="Integer"/>
    <aura:handler event="c:Authorizeloginevent" action="{!c.contactdetails}"/>
    <ui:output value="{!v.FirstName}"/>
    <ui:output value="{!v.LastName}"/>
    <ui:output value="{!v.Email}"/>
    <ui:output value="{!v.Phone}"/>
    
</aura:component>
helper:
-------
({
    contactdetails : function(component,event,helper) {
        
        var  con = event.getParam("contact");           
        
        component.find("LastName").set("v.value",con.LastName);
        component.find("FirstName").set("v.value",con.FirstName);
        component.find("Email").set("v.value",con.Email);
        component.find("Phone").set("v.value",con.Phone);
        
    }
})


I have referred to some documentation, recipes. But not able to get the idea on how to do the same in the lightning web component.
Can anyone please give me some sample code or any idea on how to do the same approach using the lightning web component.
Any help would be greatly appreciated.

Thanks
 
Hi All,
Can we make Rest API call from a batch and if so how can we call?

Thanks
Hi All,

 I am trying to push the lightning web component recipes to scratch org.
I have authorized the org, Devhub and created a scratch org.User-added image

I am not able to see the recipes in the scratch org.
User-added image
Please anyone can guide me where I am doing the mistake.
Thanks,
Sirisha
 
Hi All,

I created a user with the Standard User Profile. Now, when I log in as that user and try to clone the profile, it is saying Insufficient Permissions.

Only a System Administrator can create and Clone Profile? Can a Standard User profile clone a profile?

Thanks,
Sirisha
 
Hi All,

 I am trying to update the account upon lead update.
Need help to optimize my code. Just want to avoid multiple for loops.

public class LeadAfterUpdateHandler {
    
    public static void updateRelatedAccount(List<Lead> newLeads, Map<Id,Lead> LeadOldMap){
        List<Lead> ChangedLeads = new List<Lead>();
        Map<String,String> LeadAccFieldsMap = new Map<String,String>();
        List<Account> accList = new List<Account>();
        List<Lead_to_Account_Sync__c> csList = [Select Id,Account_Field_Name__c,Lead_field_Name__c from Lead_to_Account_Sync__c];
        for(Lead_to_Account_Sync__c cs : csList){
           
            LeadAccFieldsMap.put(cs.Lead_field_Name__c,cs.Account_Field_Name__c) ;  
            }
        }
        for(Lead l : newLeads){
            for(String cs1 : LeadAccFieldsMap.keySet()){
                if(l.get(cs1) != LeadOldMap.get(l.id).get(cs1)){
                    ChangedLeads.add(l);
                    break;
                }
            }
        }
        
        for(Lead l : ChangedLeads){
            Account a = new Account(Id = l.Account_Id__c);
            a.Name = (String)l.get('LastName');
            for(String cs1 : LeadAccFieldsMap.keySet()){
                
                a.put(LeadAccFieldsMap.get(cs1),(String)l.get(cs1));
                system.debug('for a :::' + a);
            }
            system.debug('a:::' + a);
            accList.add(a);
            
        }
        
        if(accList.size() > 0){
            update accList;
        }
    }

}
Thanks,
Sirisha
Hi All,

  I have some basic questions.
1. Using Grant Access Hierarchies or Role Hierarchy, the user can grant access to the role above the hierarchy. But what if the user in above the hierarchy wants to grant access to below the hierarchy or lower level.
e.g A (CEO)
      B ( Manager)
      C ( Sales rep)
In this case, how do B can share the record to c? Do we use Sharing rules for this requirement?

2. If there are 100 users in one profile1 and 100 users in another profile2. How to restrict the record access from each other. Profile1 should not see Profile2 records and same with Profile2 should not see Profile1's records.

Any ideas on this?

Thanks,
Sirisha
Hi All,

I am trying to get all the cases and related email that is recently sent to the customer.
 I am able to display all the casenumbers, but not the last email sent. 
Below is my code. 

public class CaseRelatedListApex {
    
    @AuraEnabled
    public static List<Case> getObject(Id  sessId){
        LIST< session__c > objsessList = new LIST< session__c >();
        LIST< Case > objCaseList = new LIST< Case >();
      
        
             if(sessId!=null)
        {
           objCaseList =[select id,session_ID__c,CaseNumber from case where  session_ID__c =:sessId  limit 4];
          
        }
         return  objCaseList;
        }
       @AuraEnabled
    public Static List<Datetime> getmessagedt(List<Case> objCaseList){
     // Case  objCase = new Case (); 
     List<DateTime> dt = new List<DateTime>();
        if(objCaseList.size()>0)
        {
            for(Case objCase :[select id,session_ID__c,CaseNumber,(select id,MessageDate from EmailMessages where incoming = False order by MessageDate desc limit 1) MessageDt from case where ID = :objCaseList ]){
                for(EmailMessage e : objCase.EmailMessages){
                    dt.add(e.MessageDate);
                }
            }
           
        } 
        return  dt;
    }
   
}
Component:
<aura:component controller = "CaseRelatedListApex" implements="force:appHostable,flexipage:availableForAllPageTypes,home:availableForDesktop,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction">
    <aura:attribute name="sessId" type="String"/>
    <aura:attribute name="cases" type="Case[]"/>
    <aura:attribute name="caseId" type="Id"/>
    <aura:attribute name ="cas" type="Case"/>
    <aura:attribute name="LastEmail" type="Datetime"/>
    <aura:handler name="init" value="{!this}" action="{!c.check}" />
    <aura:attribute name="totalCases" type="String"/>
   

    
    <form class="slds-form_horizontal" role ="list">
        <article class="slds-card">
                            <div class="slds-card__header slds-grid" >
                                <header class="slds-media slds-media--center slds-has-flexi-truncate">
                                    <div class="slds-media__figure">
                                        <lightning:icon iconName="standard:case" size ="small" alternativeText="Case" />
                                    </div>
                                    <div class="slds-media__body slds-truncate">
                                        <h2> <b> <span class="slds-text-heading--small">Cases ({!v.totalCases})   </span> </b></h2>
                                    </div>
                                </header>
                                 </div>
       <table  style ="margin-left :10px;">
           <thead>
               <tr >
                   <th scope="col" style ="font-weight:normal" >
                           <h1> <span >Case Number:</span></h1>
                    </th>
                    <th scope="col" style ="font-weight:normal">
                        <h1> <span >Last Email:</span></h1>
                    </th>
                    
               </tr>
           </thead><br/>
            <tbody>
                <aura:iteration items="{!v.cases}" var="ocas">
                  <tr class="slds-text-title" style ="font-size: .8125rem" >                  
                    <!--<td style =" color: rgb(22, 50, 92); text-decoration: dotted underline;">-->
                      <td>
                        <a href="#"  data-recId="{!ocas.Id}"  onclick="{!c.handleClick}">{!ocas.CaseNumber}</a>
                      </td>
                    <!--</td>-->
                    <td>
                        {!v.LastEmail}
                    </td>
                                       
                  </tr>
                </aura:iteration> 
            </tbody>
        </table><br/>
        </article>
    </form>
       
      
</aura:component>
Helper:
({
    getCases : function(Component,event,helper) {
        var action= Component.get("c.getObject");
        var sessId = Component.get("v.recordId");
        
        action.setParams({
            "sessId" :sessId
        });
        action.setCallback(this,function(response){
            var state=response.getState();
                       
            if (Component.isValid() && state === "SUCCESS") {               
                //alert('Cases');
                 Component.set("v.cases",response.getReturnValue());
                 var caseCount = Component.get("v.cases").length;
                 Component.set("v.totalCases",caseCount);
                 console.log("caseCount "+caseCount);
                 var action1 = component.get("c.getmessagedt");
                 var cas = Componenet.get("v.cases");
                 action1.setParams({
                    "objCaseList":cas
                });
                action1.setCallback(this,function(response){
                var state=response.getState();
                       
                if (Component.isValid() && state === "SUCCESS") {               
                //alert('Cases');
                Component.set("v.LastEmail",response.getReturnValue());
                
            }
        });
           $A.enqueueAction(action1);     
            }
        });
        
        $A.enqueueAction(action);
    },
    navigateTorecordDetails :function(Component,event,helper){
       console.log('@@@ MovetoDetailPage method calls');
        var idstr = event.target.getAttribute("data-recId")
        console.log('@@@ CaseId ==> ' + idstr);
       var navEvt = $A.get("e.force:navigateToSObject");
       if(navEvt!=undefined){
           navEvt.setParams({
               "recordId": idstr
           });
           navEvt.fire();
       }
        $A.enqueueAction(action);
    }
})

getting error as "This page has an error. You might just need to refresh it. Error in $A.getCallback() [component is not defined] Callback failed: apex://CaseRelatedListApex/ACTION$getObject" 
Please help me to fix the error.

Thanks,
Sirisha
Hi All,

Trying to display a list of records in the related list for the custom object using lightning component.
I am getting the custom object Id and displaying all the cases related to that object.
But I m not able to display all record in a proper format and also on click of casenumber link should navigate to sobject details page.
App:
<aura:application extends = "force:slds" >
    <aura:attribute name="sessId"  type="String"   access="public" />
    <c:CaseRelatedListComponent sessId="{!v.sessId}" />
</aura:application>
Component:
<aura:component controller = "CaseRelatedListApex" >
    <aura:attribute name="sessId" type="string"/>
    <aura:attribute name="cases" type="Case[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.check}" />
   <!-- <aura:attribute name="Cases" type="list"/>-->
    <aura:attribute name="recordId" type="String" />
    <aura:handler event="c:CaseRelatedListEvent" action="{!c.handleCSDetailsEvent}" />
    <div class="slds-col slds-col--padded slds-p-top--large">
 
  

  <!-- BOXED AREA -->
  <fieldset class="slds-box slds-theme--default slds-container--small">

    <legend id="Login form" class="slds-text-heading--small 
      slds-p-vertical--medium">
      
    </legend>

    
    <form class="slds-form--stacked">
       <aura:iteration items="{!v.cases}" var="ocas">
       <li>
       <!--javascript:void(0)-->
        <a href="javascript:void(0)" onclick="{!c.handleClick}">

            <ui:outputText value="{!ocas.CaseNumber}" /><br/>
           </a>
           
        <label class="slds-form-element__label" for="Name">Case Status</label>
        <div class="slds-float_right">
            <ui:outputText value="{!ocas.Status}"/>    <br/><br/>
         </div>
                              
           
         <label class="slds-form-element__label" for="Name">Subject</label>
        <div class="slds-float_right">
            <ui:outputText value="{!ocas.Subject}"/><br/>    
         </div>
           
           </li>
        </aura:iteration>
        
      
    </form>
        
      </fieldset>
        </div>
    </div>
</aura:component>
Javascript:
({
    check : function(component, event, helper){
        console.log('inside controller');
        helper.getCases(component,event,helper);
    }
    ,
    
    handleClick : function(component,event,helper){
        helper.navigateTorecordDetails(component,event);
    }
})
Helper:
({
    getCases : function(Component,event,helper) {
        var action= Component.get("c.getObject");
        var sessId = Component.get("v.sessId");
        action.setParams({
            "sessId" :sessId
            
        });
        action.setCallback(this,function(response){
            var state=response.getState();
                       
            if (Component.isValid() && state === "SUCCESS") {               
                alert('Cases');
                Component.set("v.cases",response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    navigateTorecordDetails :function(Component,event,helper){
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": Component.get("v.recordId")
        });

        navEvt.fire();
    },
    
})

Apex:

@AuraEnabled
    public static List<Case> getObject(string  sessId){
        LIST< session__c > objsessList = new LIST< session__c >();
        LIST< Case > objCaseList = new LIST< Case >();
             
        
             if(sessId!=null)
        {
           objCaseList =[select id,subject,session_ID__c,CaseNumber,Status from case where session_ID__c =:sessId  limit 4];
            //return  objCaseList;       
           
        }
         return  objCaseList;
        }
       
        

}
When I click on CaseNumber it shows error as 
Action failed: c:CaseRelatedListComponent$controller$handleClick [Cannot read property 'setParams' of undefined] Failing descriptor: {c:CaseRelatedListComponent$controller$handleClick}

Do I need to create the event for this? How to pass the recordId to display the case details?
Pls, help me to fix this code.
Thanks,
Sirisha
Hi All,
I am just a beginner learning how to write bulkified code.
I have created a Batch which updates a field in Case and then updates the Status in my Custom Object.
Before creating Batch, I am creating two records with Status as "Sent" and another one "Scheduled".
My Batch should run daily and updates the case and sends out the email.



So basically 4 things happen in my code.
1) Through Process Builder , I am updating the case picklist field to say 'XX' .
2) When Case trigger fires , It needs to Insert two records in my Custom object  with one status as 'Sent' and  another one as  'Scheduled'.
3) Batch runs daily and checks for the Scheduled records on that day and updates the case field picklist as say 'YY'.
4) Once the case field is updated to 'YY' ,sends out email and updates my Custom object Status as "Sent".

I can able to update the case and send the email once. But when multiple records updates the case for multiple opportunities then my code is fetching only one record.
I am capturing those cases from my Custom Object whose status is Scheduled and kept them in a list and iterating on those list of cases, contactid and templateid sending out the email.
Once the email is success ,I am trying to insert two records.So, I am facing problem to get the caseid from the list of cases while sending the email.
If I use map ,it is capturing one case and  If I use list I am not able to get the multiple cases.

This is code for capturing all the cases 
for(Case cs : newList){
                system.debug('inside case'+cs);
              
                ListEmailtemplateCase.add(cs.Email_Template__c);
                system.debug('cs email template @@'+cs.Email_Template__c);
                
            }
This code will get the developername from the Emailtemplate object for those cases
for(EmailTemplate et:[Select id,DeveloperName,Name,body from EmailTemplate where DeveloperName IN: ListDeveloperName]){
                system.debug('et'+et.Name);
                system.debug('et Id'+et.Id);
             
              EmailTemplateList.add(et.DeveloperName);
                EmailTemplateId.add(et.Id);
          }
This code to capture the template id and cases sends the email to that contact.
integer i=0;
         for(Case c: newList)
            {
                system.debug('newlist size***'+newList.size());
                try{  
                if(c.Email_Template__c != NULL){ 
                    system.debug('inside case emailtemplate');
                system.debug('email template'+c.Email_Template__c);
                    Id templateId = EmailTemplateId[i];
                system.debug('templateid'+templateId);
                
            //caseLists.add(c.Id);
                
    Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
            mail.setTemplateId(templateId);
            
                if(c.ContactId != NULL){
                    system.debug('contactid'+c.ContactId);
            mail.setTargetObjectId(c.ContactId);
                }
            mail.setWhatId(c.Id);
            
             if ( owea.size() > 0 ) {
                 system.debug('owea size'+owea.size());
                mail.setOrgWideEmailAddressId(owea[0].Id);
            }
                
            mails.add(mail);
            
            List<Id> caseIdlist = new List<Id>();
            List<Case> caselist = new List<Case>();
                system.debug('sendemail'+Messaging.sendEmail(mails));
            List<Messaging.SendEmailResult> list_mr =Messaging.sendEmail(mails);
             Integer j=0;
            for(Messaging.SendEmailResult ser : list_mr){
               Map<Id,Case> casemap = new Map<Id,Case>();
                system.debug('inside messaging email result');
                if(ser.isSuccess()){
                    system.debug('inside if');
                    Messaging.SingleEmailMessage maill = mails[j];
                    Id caseId = maill.getwhatId();
                    system.debug('caseId'+caseId);
                    caseIdlist.add(caseId);
                    system.debug('caseIdlist'+caseIdlist);
                    system.debug('caseIdlist'+caseIdlist);
                    Case cas = casemap.get(caseId);
                    system.debug('case'+cas);
                    caselist.add(cas);
                    system.debug('caselist'+caselist);
                    system.debug('caselist'+caselist.size());
                    createEmailNotifications(caselist);
                    
                }
                }
                    j++;
            }
            }
This line  Case cas = casemap.get(caseId) is not getting all those list of cases.
Please help me with this functionality. Any help would be greatly appreciated. 

Thanks





 
Hi All,

I am trying to get the object prefix of Parent objects from child object.
In Case, I have the lookup to Opportunity and 2 custom objects. Here In my scenario, I am trying to create 2 records if an email is sent out to the customer. So, If an email is sent related to Opportunity object, my custom object field need to populate only opportunity id. Similarly with other objects should populate the caseid and that objectid.
I have written my code something like this.
 for(Case cs : Trigger.New){
        
        if(cs.Email_Template__c != Null && cs.Email_Template__c != ''){
            
            e = new EmailNotifications();
            e.CaseId= cs.id;
            e.OpporunityId = cs.Opportunity__c;
            e.EngagementId = cs.Engagement_ID__c;
            e.SessionId = cs.Session_ID__c;
            EmailList.add(e);            
        } 
        
    }
        if(EmailList.size()>0){
            CaseHandler.sendEmail(EmailList,MapEmailTemplate);
        }
public static void sendEmail(List <EmailNotifications> EmailList ,Map <String , CaseEN__c > MapParentEmailTemplate){
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        List<Email_Notification__c> reminderNotification = new List<Email_Notification__c>();
        List<Email_Notification__c> updatereminderNotification = new List<Email_Notification__c>();
Map<Id, Id> map_Formfields = new Map<Id, Id>();
        
        for(EmailNotifications en:Emaillist){
           
            string myIdPrefix;
            myIdPrefix = String.valueOf(en.CaseId).substring(0,3);
            if(myIdPrefix == '006'){
            map_Formfields.put(en.CaseId,en.OpporunityId);
            }
            if(myIdPrefix == 'a00'){
                map_Formfields.put(en.CaseId,en.EngagementId);
            }
            if(myIdPrefix == 'a05'){
                map_Formfields.put(en.CaseId,en.SessionId);
            }
            Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {'abc@abc.com'};
                system.debug('toAddresses' +toAddresses);
            mail.setToAddresses(toAddresses);
            mail.setSubject('Hi');
            system.debug('hi');
            mail.setSenderDisplayName('Hi');
            system.debug('xyz');
           
            String body = 'Dear ' + cas.ContactEmail + ', ';
            body += 'First mail';
            system.debug('body'+body);
            mail.setHtmlBody(body);
            mail.setWhatId(cas.Id);
            mails.add(mail);
           
            List<Messaging.SendEmailResult> list_mr =Messaging.sendEmail(mails);
             Integer i=0;
            for(Messaging.SendEmailResult ser : list_mr){
                if(ser.isSuccess()){
                    Messaging.SingleEmailMessage maill = mails[i];
                    Id caseId = maill.getwhatId();
                    system.debug('caseId'+caseId);
                    Id ObjId = map_Formfields.get(caseId);
                   ManageEmailNotification( etname , myIdPrefix , ObjId,caseId,Emaillist);
                }
            }
             public static void ManageEmailNotification(String EmailTemplateName , String ObjectType , String ObjectId , Id caseId,List <EmailNotifications> EmailList){
                   list<Email_Notification__c> notificationlist = new list<Email_Notification__c>();
                List<Email_Notification__c> reminderNotification = new List<Email_Notification__c>();
                List<Email_Notification__c> updatereminderNotification = new List<Email_Notification__c>();
                for(EmailNotifications en : EmailList){
                    if (ObjectType == '006') 
                {
                     en.OpporunityId = ObjectId;  
                } 
               if (ObjectType == 'a00') 
                {
                     en.EngagementId= ObjectId;  
                } 
                if (ObjectType == 'a05')
                {
                    system.debug('ObjectType'+ObjectType);
                    en.SessionId = ObjectId; 
                    system.debug('ObjectId'+ObjectId);
                   system.debug('ObjectId'+en.SessionId); 
                }
            /*After Sending the Scheduled Email , Details will be updated to  Email Notification Object*/ 
            Email_Notification__c em= new Email_Notification__c();
            if(en.ScheduledFlag == False){
                system.debug('scheduled flag'+en.ScheduledFlag);
                if(en.OpporunityId != null)
                             {
                                 em.opportunity__c = en.OpporunityId;
                             }
                             else if (en.SessionId != NUll){
                                 em.Session__c = en.SessionId;
                             }
                             else if (en.EngagementId != NULL){
                                 em.Engagement__c = en.EngagementId;
                             }
                em.Case__c = en.CaseId; 
                em.Status__c = 'Sent';
               
                em.Email_Template__c = en.EmailName;
                notificationlist.add(em);    
            }
            /*After Sending the Scheduled Email , Details will be updated to  Email Notification Object*/  
            system.debug('Scheduled Flag boolean'+en.ScheduledFlag);
            system.debug('EmailTemplateName'+en.EmailTemplateName);
            
            if(en.ScheduledFlag == True){
                system.debug('update ');
                Email_Notification__c updatelist = new Email_Notification__c();
                system.debug('opp id'+en.OpporunityId);
                system.debug('Email_Template__c :::'+ en.EmailName );
                
                updatelist = [select id,status__c,Sent_Date__c from Email_Notification__c where   Opportunity__c = :en.OpporunityId ];
               
                updatelist.Status__c = 'Sent';
                
                updatereminderNotification.add(updatelist);
                break;
                
            }
           
            /*Check if the any remainder emails need scheduled*/
            if(en.ParentEmail == em.Email_Template__c ){
                
                Email_Notification__c em1 = new Email_Notification__c();
                if(en.OpporunityId != null)
                             {
                                 em1.opportunity__c = en.OpporunityId;
                             }
                             else if (en.SessionId != NUll){
                                 em1.Session__c = en.SessionId;
                             }
                             else if (en.EngagementId != NULL){
                                 em1.Engagement__c = en.EngagementId;
                             }
                em1.Case__c = en.CaseId;
               
                em1.Status__c = 'Scheduled';
                system.debug('em1'+em1.Status__c);
               
                system.debug('em1'+em1.Scheduled_Date__c);
                em1.Email_Template__c = en.getParentname(en.ParentEmail).Name;
                system.debug('em1'+em1.Email_Template__c);
                
               
                reminderNotification.add(em1); 
                
                
            }
        }
        if(notificationlist.size()>0){
           
            insert notificationlist;
        }
        if(updatereminderNotification.size()>0){
           
            Update updatereminderNotification;
        }
        if(reminderNotification.size()>0){
           
            
            insert reminderNotification;
        }
    }

1) How to dynamically I pass the object Id for that particular case?
2) Is there any way I can pass the object name and get the Opportunity prefix or other custom objects?
3) How to avoid writing code multiple times?
4) How to pass id dynamically in Update query 
select id,status__c,Sent_Date__c from Email_Notification__c where   Opportunity__c = :en.OpporunityId

Please anyone help me on this?
Any help will be greatly appreciated.

Thanks,
Sirisha         
Hi All,

I am trying to execute a batch which needs to handle more than one record.
My batch will run daily and checks for the status scheduled and batch rundate should be today. Then  I am getting the email template picklist and a related case in it and updating the case picklist field. I am identifying the records which are needed to be updated and looping those list of records and getting the caseid.
Now if there are multiple records that are scheduled on the same day which are having different caseID's and with different email templates. How to handle more than one record using batch?
Below is my code:
global class BatchClassSample implements Schedulable,Database.Batchable<SObject> {
  
    Date todaysdate = system.today() ;
    
    global database.QueryLocator start(Database.BatchableContext bc){
        return database.getQueryLocator('SELECT Id,Name,Case__c,Email_Template_Name__c,Email_Template__c from Email_Notification__c where Status__c =\'Scheduled\' AND Scheduled_Date__c = :todaysdate');
        
    }
    
    global void execute(Database.BatchableContext bc, List<Email_Notification__c> scope){
        list<Case> updateReminderFlag = new list<Case>();
        Map<String,Email_Notification__c> UpdateReminderFlagmap = new Map<String,Email_Notification__c>();
        Map<Id,Case> casemap = new Map<Id,Case>();
        Set<id> caselist = new set<id>(); 
       
        system.debug('scope'+scope);
        for(Email_Notification__c sc : scope){
            caselist.add(sc.case__c);
            UpdateReminderFlagmap.put(sc.Email_Template__c,sc);
        }
        List<Case> c1 = [select id,Email_Template__c from case where id IN :caselist];
        
        for(Email_Notification__c em : UpdateReminderFlagmap.values()){
           
            for(Case c :c1){
               
                if(em.Email_Template_Name__c != NULL){
//put the email template in case and update the case picklist
                    c.Email_Template__c = em.Email_Template__c;
                    
                    updateReminderFlag.add(c);
                    
                }
            } 
        }
        
        casemap.putall(updateReminderFlag);
        if(casemap.size()>0)
            
            Update casemap.values();
            
        } 
    global void finish(Database.BatchableContext bc){
        
    }
    global void execute(SchedulableContext scon) {
      Database.executeBatch(new BatchClassSample(),2000);
   }
}

will my code works for multiple records also.Please anyone help me on this.
Any help will be greatly appreciated.
Thanks,
Sirisha
Hi All,

I have 10 fields in my lead which are common in Account.Im trying to insert Account record before i insert in lead and get that accountid and populate the acctid in lead.
I tried below code.It is inserting the record in Account object and also getting the accountId in lead ,but i want remaining fields need to be populate in that record when account record is inserted.I see fields are showing the values but in my UI the fields are blank.
below is the code i tried:

trigger AccountCreationOnLead on Lead (before insert,after Insert,after Update) {
   
    list<Account> accountlist = new List<Account>();
    List<Lead> updateleadacctId = new List<Lead>();
     
   
   
     //Collect list of leads being inserted without an account
    List<Lead> needAccounts = new List<Lead>();
    for (Lead c : trigger.new) {
        if (String.isBlank(c.Account_Id__c)) {
            needAccounts.add(c);
        }
    }
        
        if (needAccounts.size() > 0) {
        List<Account> newAccounts = new List<Account>();
        Map<String,Lead> LeadsByNameKeys = new Map<String,Lead>();
        Map<String,Lead> LeadsByPhoneKeys = new Map<String,Lead>();
        Map<String,Lead> LeadsByWebsiteKeys = new Map<String,Lead>();
        //Create account for each lead
        for (Lead c : needAccounts) {
            String accountName = c.firstname + ' ' + c.lastname;
            
            String phone = c.Phone;
            String website = c.Website;
            LeadsByNameKeys.put(accountName,c);
            LeadsByPhoneKeys.put(phone,c);
            LeadsByWebsiteKeys.put(website,c);
            Account a = new Account(name=accountName,Phone = phone,Website = website);
            newAccounts.add(a);
            system.debug('new account'+newAccounts);
        }
            insert newAccounts;
            system.debug('inserted'+newAccounts);
        
        
        for (Account a : newAccounts) {
            //Put account ids on leads
            if (LeadsByNameKeys.containsKey(a.Name)) {
                LeadsByNameKeys.get(a.Name).Account_Id__c = a.Id;
            }
            
        }
        
       
        
    }
}
            
 Account a = new Account(name=accountName,Phone = phone,Website = website)
above line shows me value in debug log as 04:20:02:180 USER_DEBUG [35]|DEBUG|inserted(Account:{Name=sai Not Assigned, Phone=8987879, Website=www.test.com, Id=0014D00000EnHcWQAV})     
    Please can anyone help me on this.Any help will be greatly appreciated.

Thanks,
Sirisha
       
        
        
    
    
    
 
Hi All,

I am trying to insert and update records based on certain condition.

Map<Id,List<ObjectName>> mapname = new Map<Id,List<ObjectName>>();
for(CustomsettingObject cso : [select id , name ,flag,parentname from CustomsettingObject  where  name =:casepicklistval or parentname =:casepicklistval]{
List<ObjectName> tmp = mapname.get(cso.id);
if(tmp == null) 
tmp = new tmp();
mapname.put(cso.id,tmp);
//how to loop over the map here??
}

CUSTOM SETTING object has records as 
Name                                           TemplateName           Flag             parentname
 SendSurveyForm                               1                         False
SendSurveyAgainwithindays                2                         True            SendSurveyForm

If the flag is False and Parenname is null need to insert in an object and If the Flag is True and Parentname = picklistval then insert another record.
I have written a trigger which get the picklist value and checks for in the Customsetting object and iterates over the map and inserts in the custom object.

How to write this logic?Can anyone give some idea on this that how to loop through the list and insert into a custom object?

Thanks,
SFDC New learner

Hi All,
 I am trying to write a trigger which fires on Cases Object based on certain criteria on Opportunity .Once Case field is updated ,I am trying to send an email to that contact and also trying to insert two records with status as 'Sent' and another one with status as 'Scheduled'.
I have used Custome setting object  and a Class as a Custom object .
Below is my code.Can anyone help me on this issue and also can give me better solution.
trigger CaseEmailNotificationTrigger on Case (after update) {
   Map<ID,Case> addemailtemplate = new Map<ID,Case>();
   set<String> setEmailTemplateName = new set<String>();
   CaseEmailNotificationhandler handler = new CaseEmailNotificationhandler();
   if(Trigger.isUpdate){
       
       
   /*Fetch the Custom Setting and keep in the Map*/    
    Map <String , CaseEN__c > MapEmailTemplate  = new Map<String , CaseEN__c>();
  List<CaseEN__c> CaseENObject= [select Id, Name, Email_Code__c,Email_Template_Id__c,ScheduledEmail__c  from CaseEN__c];
       
   For (CaseEN__c CEN :CaseENObject )
   {
       MapEmailTemplate.put(CEN.Name , CEN);
   }
       
           
    List <EmailNotifications> EmailList = New List <EmailNotifications>();   
    EmailNotifications e;    
       
   for(Case cs : Trigger.New){
       system.debug('emailtemplate'+cs.Email_Template__c);
       if(cs.Email_Template__c != NUll){
           
           e = new EmailNotifications();
           e.CaseId= cs.id;
           e.EmailName = cs.Email_Template__c;
           e.EmailTemplateName = MapEmailTemplate.get(cs.Email_Template__c).Email_Template_Id__c;
           e.ScheduledFlag=  (boolean) MapEmailTemplate.get(cs.Email_Template__c).ScheduledEmail__c;
           e.ParentEmail = cs.Email_Template__c;
           e.OpporunityId = cs.Opportunity__c;
           e.EngagementId = cs.Engagement_ID__c;
           e.SessionId = cs.Session_ID__c;
           EmailList.add(e);            
       }
       
   }
       if(EmailList.size()>0){
           //CaseEN handler = new CaseEN();
          // handler.sendEmail(EmailList);
           sendEmail(EmailList);
       }
       
public void sendEmail(list<EmailNotifications> Emaillist){
       List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
       
        List<OrgWideEmailAddress> owea = [select Id from OrgWideEmailAddress where Address =: System.Label.Feed_From_Address];
       Map<Id, Id> map_Formfields = new Map<Id, Id>();
       for(EmailNotifications en:Emaillist){
           case cas = en.CaseId;
           
           Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
           String[] toAddresses = new String[] {'sirisha.yada@gmail.com'};
   system.debug('toAddresses' +toAddresses);
           mail.setToAddresses(toAddresses);
           mail.setSubject('Hi');
           system.debug('hi');
           mail.setSenderDisplayName('Siri');
           system.debug('siri');
         
          String body = 'Dear ' + cas.ContactEmail + ', ';
           body += 'First mail';
           system.debug('body'+body);
           mail.setHtmlBody(body);
           mail.setWhatId(cas.Id);
           mails.add(mail);
           
           list<Email_Notification__c> notificationlist = new list<Email_Notification__c>();
           List<Email_Notification__c> reminderNotification = new List<Email_Notification__c>();
           List<Email_Notification__c> updatereminderNotification = new List<Email_Notification__c>();
           Email_Notification__c em;
           if(en.ScheduledEmail__c == False){
             em.Opportunity__c = en.OpporunityId;
             em.Case__c = en.CaseId;
             em.Status__c = 'Sent';
             em.Sent_Date__c = System.today();
             em.Immediate__c = True;
             em.Scheduled_Date__c = System.today();
             em.Email_Template_Name__c = en.EmailTemplateName;
             em.Name = en.EmailName;
             em.Email_Template__c = en.EmailName;
               notificationlist.add(em);    
   }
           if(en.ScheduledEmail__c == True){
               Email_Notification__c updatelist = new Email_Notification__c();
               
               updatelist = [select id,status__c,Sent_Date__c from Email_Notification__c where   Opportunity__c = en.OpporunityId and Email_Template_Name__c = en.EmailTemplateName and Status__c = 'Scheduled'];
                   updatelist.Sent_Date__c =system.today();
               updatereminderNotification.add(updatelist);
               
           }
           if(en.ParentEmail == em.Email_Template_Name__c ){
                 
                     Email_Notification__c em1 = new Email_Notification__c();
                     em1.Name = emailtemplatename;
                     em1.Status__c = 'Scheduled';
                     system.debug('em1'+em1.Status__c);
                     em1.Immediate__c = false;
                     system.debug('em1'+em1.Immediate__c);
                     em1.Scheduled_Date__c = System.today() + 7;
                     system.debug('em1'+em1.Scheduled_Date__c);
                     em1.Email_Template_Name__c = etId;
                     system.debug('em1'+em1.Email_Template_Name__c);
                     em.Email_Template__c = emailtemplatename;
                     system.debug('em1'+em1.Email_Template__c);
            reminderNotification.add(em1);
           
              
         }
   }
   if(notificationlist.size()>0){
                   system.debug('size'+notificationlist.size());
                       
                   insert notificationlist;
   }
   if(updatereminderNotification.size()>0){
       system.debug('size of ren'+updatereminderNotification.size());
       Update updatereminderNotification;
   }
       if(reminderNotification.size()>0){
                   system.debug('size'+reminderNotification.size());
                       
                   insert reminderNotification;
   }
   }     
   
   
   
   }
   
}      



I really appreciate for your help.
Thanks,
Sirisha
 
Hi All,

I have a requirement where I need to show all field values in the related list section using lightning component.

I have a custom object which has lookup with opportunity and has the following fields as Name,Created Date,SentDate,Scheduled Date,Status.
It shows few fields like Name,SentDate ,Status.But I want to display all the fields.

Can anyone share the code?

Thanks,
Sirisha
 
Hi All,

I have created login form with username and passsword.I have created new custom fields in the contact object.
On click of submit button.It will validates the contact is existing or not and returns contact's FirstName,LastName,Email,Phone.

For this I created a RESTAPI which will take the username and password as a parameters and validates against the credentials and  returns the contact details for that valid user.Login form i have created in my org. using lightning.

Now my challenge is  when the user clicks on submit button it should get the contact details from the RESTAPI and maps with the contact object fields and   reload or refresh the page with contact details and displays the field values FirstName,LastName,Email and Phone.
I am trying to pass the variables or map the variables which are returned from REST API to APEX.

How can I acheive this scenario.Do I need to create another lightning component to refresh the parent component to child component and returns the login contact details.

If anyone can provide a sample code that would be a great help.

Any help would be greatly appreciated.

Thanks,
Sirisha
Hi All,

 Can anyone please explain to me how do you handle production issues in your project. what is the approach? 
Do you use Jira tool to raise a ticket for the case?

Say for example if we have 100 users and if one user is not receiving the email sent out of 100 users. what approach can be followed? And how can we fix the issue?

Thanks,
Sirisha
When you click 'View All' on Related List, you get a list view of all the records. How can you customize that page?
I want to remove the 'New' action button on that page
If any contact or lead have the birthday, they should receive SMS
  • July 04, 2019
  • Like
  • 0
Hi All,

I am trying to create a new contact. Once the record is saved in Salesforce, an email need to be sent along with the unique id.

I have created a formula field for the Unique ID and associated record ID to this field.

Now, when I try to send an email with Unique ID, it shows null value.

<apex:page controller="SubmitNewContactController" docType="html-5.0">
   
    <apex:form>
        <apex:slds/>
    <apex:pageMessages></apex:pageMessages>
        <div class="slds-scope slds-box">
         <apex:outputPanel >
            <div class="slds-text-align_center slds-text-heading_medium"><p>Submit New Contact </p></div>
             <div class="slds-form-element">
                    <label class="slds-form-element__label"><abbr class="slds-required"></abbr> FirstName</label>
                <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!FirstName}" styleClass="slds-input" id="FirstName" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> LastName</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!LastName}" styleClass="slds-input" id="LastName" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> Phone</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!Phone}" styleClass="slds-input" id="Phone" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> Email</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!Email}" styleClass="slds-input" id="Email" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> Zipcode</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!Zipcode}" styleClass="slds-input" id="Zipcode" />
                </div>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:commandButton action="{!SubmitContact}" value="Submit"/> 
                </div>
            </div>
         </apex:outputPanel>   
        </div>
        
    
    </apex:form>
</apex:page>
public class SubmitNewContactController {
    public Contact c{get;set;}
    public String FirstName{get;set;}
    public String LastName{get;set;}
    public String phone{get;set;}
    public String Email{get;set;}
    public String Zipcode{get;set;}
    
    public SubmitNewContactController(){
        c = new Contact();
    }
    
    public PageReference SubmitContact(){
        c.FirstName = FirstName;
        c.LastName = LastName;
        c.phone = phone;
        c.Email = Email;
        c.MailingPostalCode = Zipcode;
        insert c;
        
        PageReference pr = new PageReference('/apex/ThankYouPage');
        Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
        String[] sendingTo = new String[]{c.Email};
        semail.setToAddresses(sendingTo);
        semail.setSubject('Registration is completed');
        semail.setPlainTextBody('Hi'+ c.name+'Thank you for registering.This is your UniqueID'+ c.Unique_ID__c);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
        pr.setRedirect(true);
        return pr;
        
        
        
    }
    

}

I am able to send the email but cannot capture the name and uniqueId in the email. It shows null in the email.
Can anyone please help me to fix the code?

Thanks,
Sirisha
 
Hi All,

 I am trying to pass the contact data from parent to child component on click of a button. Also, hide the parent component and show the child component using the lightning web component.
I have implemented this using lightning component.
Below is the sample code:

Parent component:
-----------------
<aura:component controller="login">
    
    <aura:attribute name="contact" type="Contact"/>
    <aura:registerEvent name="Authorizelogin" type="c:Authorizeloginevent"/>
    <div class="slds-hide" aura:id="login">
        <c:Authorizelogincontactdetails/>
    </div>
    <lightning:input name="UNAME" required="true" type="String" value="{!v.contact.LoginId__c}"/>
    <lightning:input name="PWD" required="true" type="String" value="{!v.contact.Password__c}"/>
    <lightning:button variant="brand" label="Submit" onclick="{!c.handlecontactdetails}"/>
</aura:component>

helper:
------

({
    contact : function(component,event,helper) {
        var action = component.get("c.getcontact");
        action.setParams({
            "uname":component.get("v.UNAME"),
            "pwd" : component.get("v.PWD")
        });
        action.setCallback(this,function(a){
            var response = a.getState();
            if(response==="SUCCESS"){
                var con = response.getReturnvalue();
            var myEvent = $A.get("e.c:Authorizeloginevent"); 
                myEvent.setParams({
                    "contact" : con
                });
                myEvent.fire();
            }
        });
    $A.enqueueAction(action);    
    }
})

child component:
---------------
<aura:component controller="login" >
    <aura:attribute name="FirstName" type="String"/>
    <aura:attribute name="LastName" type="String"/>
    <aura:attribute name="Email" type="String"/>
    <aura:attribute name="Phone" type="Integer"/>
    <aura:handler event="c:Authorizeloginevent" action="{!c.contactdetails}"/>
    <ui:output value="{!v.FirstName}"/>
    <ui:output value="{!v.LastName}"/>
    <ui:output value="{!v.Email}"/>
    <ui:output value="{!v.Phone}"/>
    
</aura:component>
helper:
-------
({
    contactdetails : function(component,event,helper) {
        
        var  con = event.getParam("contact");           
        
        component.find("LastName").set("v.value",con.LastName);
        component.find("FirstName").set("v.value",con.FirstName);
        component.find("Email").set("v.value",con.Email);
        component.find("Phone").set("v.value",con.Phone);
        
    }
})


I have referred to some documentation, recipes. But not able to get the idea on how to do the same in the lightning web component.
Can anyone please give me some sample code or any idea on how to do the same approach using the lightning web component.
Any help would be greatly appreciated.

Thanks
 
Hi All,

 I am trying to push the lightning web component recipes to scratch org.
I have authorized the org, Devhub and created a scratch org.User-added image

I am not able to see the recipes in the scratch org.
User-added image
Please anyone can guide me where I am doing the mistake.
Thanks,
Sirisha
 
Hi All,

I created a user with the Standard User Profile. Now, when I log in as that user and try to clone the profile, it is saying Insufficient Permissions.

Only a System Administrator can create and Clone Profile? Can a Standard User profile clone a profile?

Thanks,
Sirisha
 
Hi All,

 I am trying to update the account upon lead update.
Need help to optimize my code. Just want to avoid multiple for loops.

public class LeadAfterUpdateHandler {
    
    public static void updateRelatedAccount(List<Lead> newLeads, Map<Id,Lead> LeadOldMap){
        List<Lead> ChangedLeads = new List<Lead>();
        Map<String,String> LeadAccFieldsMap = new Map<String,String>();
        List<Account> accList = new List<Account>();
        List<Lead_to_Account_Sync__c> csList = [Select Id,Account_Field_Name__c,Lead_field_Name__c from Lead_to_Account_Sync__c];
        for(Lead_to_Account_Sync__c cs : csList){
           
            LeadAccFieldsMap.put(cs.Lead_field_Name__c,cs.Account_Field_Name__c) ;  
            }
        }
        for(Lead l : newLeads){
            for(String cs1 : LeadAccFieldsMap.keySet()){
                if(l.get(cs1) != LeadOldMap.get(l.id).get(cs1)){
                    ChangedLeads.add(l);
                    break;
                }
            }
        }
        
        for(Lead l : ChangedLeads){
            Account a = new Account(Id = l.Account_Id__c);
            a.Name = (String)l.get('LastName');
            for(String cs1 : LeadAccFieldsMap.keySet()){
                
                a.put(LeadAccFieldsMap.get(cs1),(String)l.get(cs1));
                system.debug('for a :::' + a);
            }
            system.debug('a:::' + a);
            accList.add(a);
            
        }
        
        if(accList.size() > 0){
            update accList;
        }
    }

}
Thanks,
Sirisha
Hi All,

I am trying to get all the cases and related email that is recently sent to the customer.
 I am able to display all the casenumbers, but not the last email sent. 
Below is my code. 

public class CaseRelatedListApex {
    
    @AuraEnabled
    public static List<Case> getObject(Id  sessId){
        LIST< session__c > objsessList = new LIST< session__c >();
        LIST< Case > objCaseList = new LIST< Case >();
      
        
             if(sessId!=null)
        {
           objCaseList =[select id,session_ID__c,CaseNumber from case where  session_ID__c =:sessId  limit 4];
          
        }
         return  objCaseList;
        }
       @AuraEnabled
    public Static List<Datetime> getmessagedt(List<Case> objCaseList){
     // Case  objCase = new Case (); 
     List<DateTime> dt = new List<DateTime>();
        if(objCaseList.size()>0)
        {
            for(Case objCase :[select id,session_ID__c,CaseNumber,(select id,MessageDate from EmailMessages where incoming = False order by MessageDate desc limit 1) MessageDt from case where ID = :objCaseList ]){
                for(EmailMessage e : objCase.EmailMessages){
                    dt.add(e.MessageDate);
                }
            }
           
        } 
        return  dt;
    }
   
}
Component:
<aura:component controller = "CaseRelatedListApex" implements="force:appHostable,flexipage:availableForAllPageTypes,home:availableForDesktop,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction">
    <aura:attribute name="sessId" type="String"/>
    <aura:attribute name="cases" type="Case[]"/>
    <aura:attribute name="caseId" type="Id"/>
    <aura:attribute name ="cas" type="Case"/>
    <aura:attribute name="LastEmail" type="Datetime"/>
    <aura:handler name="init" value="{!this}" action="{!c.check}" />
    <aura:attribute name="totalCases" type="String"/>
   

    
    <form class="slds-form_horizontal" role ="list">
        <article class="slds-card">
                            <div class="slds-card__header slds-grid" >
                                <header class="slds-media slds-media--center slds-has-flexi-truncate">
                                    <div class="slds-media__figure">
                                        <lightning:icon iconName="standard:case" size ="small" alternativeText="Case" />
                                    </div>
                                    <div class="slds-media__body slds-truncate">
                                        <h2> <b> <span class="slds-text-heading--small">Cases ({!v.totalCases})   </span> </b></h2>
                                    </div>
                                </header>
                                 </div>
       <table  style ="margin-left :10px;">
           <thead>
               <tr >
                   <th scope="col" style ="font-weight:normal" >
                           <h1> <span >Case Number:</span></h1>
                    </th>
                    <th scope="col" style ="font-weight:normal">
                        <h1> <span >Last Email:</span></h1>
                    </th>
                    
               </tr>
           </thead><br/>
            <tbody>
                <aura:iteration items="{!v.cases}" var="ocas">
                  <tr class="slds-text-title" style ="font-size: .8125rem" >                  
                    <!--<td style =" color: rgb(22, 50, 92); text-decoration: dotted underline;">-->
                      <td>
                        <a href="#"  data-recId="{!ocas.Id}"  onclick="{!c.handleClick}">{!ocas.CaseNumber}</a>
                      </td>
                    <!--</td>-->
                    <td>
                        {!v.LastEmail}
                    </td>
                                       
                  </tr>
                </aura:iteration> 
            </tbody>
        </table><br/>
        </article>
    </form>
       
      
</aura:component>
Helper:
({
    getCases : function(Component,event,helper) {
        var action= Component.get("c.getObject");
        var sessId = Component.get("v.recordId");
        
        action.setParams({
            "sessId" :sessId
        });
        action.setCallback(this,function(response){
            var state=response.getState();
                       
            if (Component.isValid() && state === "SUCCESS") {               
                //alert('Cases');
                 Component.set("v.cases",response.getReturnValue());
                 var caseCount = Component.get("v.cases").length;
                 Component.set("v.totalCases",caseCount);
                 console.log("caseCount "+caseCount);
                 var action1 = component.get("c.getmessagedt");
                 var cas = Componenet.get("v.cases");
                 action1.setParams({
                    "objCaseList":cas
                });
                action1.setCallback(this,function(response){
                var state=response.getState();
                       
                if (Component.isValid() && state === "SUCCESS") {               
                //alert('Cases');
                Component.set("v.LastEmail",response.getReturnValue());
                
            }
        });
           $A.enqueueAction(action1);     
            }
        });
        
        $A.enqueueAction(action);
    },
    navigateTorecordDetails :function(Component,event,helper){
       console.log('@@@ MovetoDetailPage method calls');
        var idstr = event.target.getAttribute("data-recId")
        console.log('@@@ CaseId ==> ' + idstr);
       var navEvt = $A.get("e.force:navigateToSObject");
       if(navEvt!=undefined){
           navEvt.setParams({
               "recordId": idstr
           });
           navEvt.fire();
       }
        $A.enqueueAction(action);
    }
})

getting error as "This page has an error. You might just need to refresh it. Error in $A.getCallback() [component is not defined] Callback failed: apex://CaseRelatedListApex/ACTION$getObject" 
Please help me to fix the error.

Thanks,
Sirisha
Hi All,

I am trying to get the object prefix of Parent objects from child object.
In Case, I have the lookup to Opportunity and 2 custom objects. Here In my scenario, I am trying to create 2 records if an email is sent out to the customer. So, If an email is sent related to Opportunity object, my custom object field need to populate only opportunity id. Similarly with other objects should populate the caseid and that objectid.
I have written my code something like this.
 for(Case cs : Trigger.New){
        
        if(cs.Email_Template__c != Null && cs.Email_Template__c != ''){
            
            e = new EmailNotifications();
            e.CaseId= cs.id;
            e.OpporunityId = cs.Opportunity__c;
            e.EngagementId = cs.Engagement_ID__c;
            e.SessionId = cs.Session_ID__c;
            EmailList.add(e);            
        } 
        
    }
        if(EmailList.size()>0){
            CaseHandler.sendEmail(EmailList,MapEmailTemplate);
        }
public static void sendEmail(List <EmailNotifications> EmailList ,Map <String , CaseEN__c > MapParentEmailTemplate){
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        List<Email_Notification__c> reminderNotification = new List<Email_Notification__c>();
        List<Email_Notification__c> updatereminderNotification = new List<Email_Notification__c>();
Map<Id, Id> map_Formfields = new Map<Id, Id>();
        
        for(EmailNotifications en:Emaillist){
           
            string myIdPrefix;
            myIdPrefix = String.valueOf(en.CaseId).substring(0,3);
            if(myIdPrefix == '006'){
            map_Formfields.put(en.CaseId,en.OpporunityId);
            }
            if(myIdPrefix == 'a00'){
                map_Formfields.put(en.CaseId,en.EngagementId);
            }
            if(myIdPrefix == 'a05'){
                map_Formfields.put(en.CaseId,en.SessionId);
            }
            Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {'abc@abc.com'};
                system.debug('toAddresses' +toAddresses);
            mail.setToAddresses(toAddresses);
            mail.setSubject('Hi');
            system.debug('hi');
            mail.setSenderDisplayName('Hi');
            system.debug('xyz');
           
            String body = 'Dear ' + cas.ContactEmail + ', ';
            body += 'First mail';
            system.debug('body'+body);
            mail.setHtmlBody(body);
            mail.setWhatId(cas.Id);
            mails.add(mail);
           
            List<Messaging.SendEmailResult> list_mr =Messaging.sendEmail(mails);
             Integer i=0;
            for(Messaging.SendEmailResult ser : list_mr){
                if(ser.isSuccess()){
                    Messaging.SingleEmailMessage maill = mails[i];
                    Id caseId = maill.getwhatId();
                    system.debug('caseId'+caseId);
                    Id ObjId = map_Formfields.get(caseId);
                   ManageEmailNotification( etname , myIdPrefix , ObjId,caseId,Emaillist);
                }
            }
             public static void ManageEmailNotification(String EmailTemplateName , String ObjectType , String ObjectId , Id caseId,List <EmailNotifications> EmailList){
                   list<Email_Notification__c> notificationlist = new list<Email_Notification__c>();
                List<Email_Notification__c> reminderNotification = new List<Email_Notification__c>();
                List<Email_Notification__c> updatereminderNotification = new List<Email_Notification__c>();
                for(EmailNotifications en : EmailList){
                    if (ObjectType == '006') 
                {
                     en.OpporunityId = ObjectId;  
                } 
               if (ObjectType == 'a00') 
                {
                     en.EngagementId= ObjectId;  
                } 
                if (ObjectType == 'a05')
                {
                    system.debug('ObjectType'+ObjectType);
                    en.SessionId = ObjectId; 
                    system.debug('ObjectId'+ObjectId);
                   system.debug('ObjectId'+en.SessionId); 
                }
            /*After Sending the Scheduled Email , Details will be updated to  Email Notification Object*/ 
            Email_Notification__c em= new Email_Notification__c();
            if(en.ScheduledFlag == False){
                system.debug('scheduled flag'+en.ScheduledFlag);
                if(en.OpporunityId != null)
                             {
                                 em.opportunity__c = en.OpporunityId;
                             }
                             else if (en.SessionId != NUll){
                                 em.Session__c = en.SessionId;
                             }
                             else if (en.EngagementId != NULL){
                                 em.Engagement__c = en.EngagementId;
                             }
                em.Case__c = en.CaseId; 
                em.Status__c = 'Sent';
               
                em.Email_Template__c = en.EmailName;
                notificationlist.add(em);    
            }
            /*After Sending the Scheduled Email , Details will be updated to  Email Notification Object*/  
            system.debug('Scheduled Flag boolean'+en.ScheduledFlag);
            system.debug('EmailTemplateName'+en.EmailTemplateName);
            
            if(en.ScheduledFlag == True){
                system.debug('update ');
                Email_Notification__c updatelist = new Email_Notification__c();
                system.debug('opp id'+en.OpporunityId);
                system.debug('Email_Template__c :::'+ en.EmailName );
                
                updatelist = [select id,status__c,Sent_Date__c from Email_Notification__c where   Opportunity__c = :en.OpporunityId ];
               
                updatelist.Status__c = 'Sent';
                
                updatereminderNotification.add(updatelist);
                break;
                
            }
           
            /*Check if the any remainder emails need scheduled*/
            if(en.ParentEmail == em.Email_Template__c ){
                
                Email_Notification__c em1 = new Email_Notification__c();
                if(en.OpporunityId != null)
                             {
                                 em1.opportunity__c = en.OpporunityId;
                             }
                             else if (en.SessionId != NUll){
                                 em1.Session__c = en.SessionId;
                             }
                             else if (en.EngagementId != NULL){
                                 em1.Engagement__c = en.EngagementId;
                             }
                em1.Case__c = en.CaseId;
               
                em1.Status__c = 'Scheduled';
                system.debug('em1'+em1.Status__c);
               
                system.debug('em1'+em1.Scheduled_Date__c);
                em1.Email_Template__c = en.getParentname(en.ParentEmail).Name;
                system.debug('em1'+em1.Email_Template__c);
                
               
                reminderNotification.add(em1); 
                
                
            }
        }
        if(notificationlist.size()>0){
           
            insert notificationlist;
        }
        if(updatereminderNotification.size()>0){
           
            Update updatereminderNotification;
        }
        if(reminderNotification.size()>0){
           
            
            insert reminderNotification;
        }
    }

1) How to dynamically I pass the object Id for that particular case?
2) Is there any way I can pass the object name and get the Opportunity prefix or other custom objects?
3) How to avoid writing code multiple times?
4) How to pass id dynamically in Update query 
select id,status__c,Sent_Date__c from Email_Notification__c where   Opportunity__c = :en.OpporunityId

Please anyone help me on this?
Any help will be greatly appreciated.

Thanks,
Sirisha         
Hi All,

I have 10 fields in my lead which are common in Account.Im trying to insert Account record before i insert in lead and get that accountid and populate the acctid in lead.
I tried below code.It is inserting the record in Account object and also getting the accountId in lead ,but i want remaining fields need to be populate in that record when account record is inserted.I see fields are showing the values but in my UI the fields are blank.
below is the code i tried:

trigger AccountCreationOnLead on Lead (before insert,after Insert,after Update) {
   
    list<Account> accountlist = new List<Account>();
    List<Lead> updateleadacctId = new List<Lead>();
     
   
   
     //Collect list of leads being inserted without an account
    List<Lead> needAccounts = new List<Lead>();
    for (Lead c : trigger.new) {
        if (String.isBlank(c.Account_Id__c)) {
            needAccounts.add(c);
        }
    }
        
        if (needAccounts.size() > 0) {
        List<Account> newAccounts = new List<Account>();
        Map<String,Lead> LeadsByNameKeys = new Map<String,Lead>();
        Map<String,Lead> LeadsByPhoneKeys = new Map<String,Lead>();
        Map<String,Lead> LeadsByWebsiteKeys = new Map<String,Lead>();
        //Create account for each lead
        for (Lead c : needAccounts) {
            String accountName = c.firstname + ' ' + c.lastname;
            
            String phone = c.Phone;
            String website = c.Website;
            LeadsByNameKeys.put(accountName,c);
            LeadsByPhoneKeys.put(phone,c);
            LeadsByWebsiteKeys.put(website,c);
            Account a = new Account(name=accountName,Phone = phone,Website = website);
            newAccounts.add(a);
            system.debug('new account'+newAccounts);
        }
            insert newAccounts;
            system.debug('inserted'+newAccounts);
        
        
        for (Account a : newAccounts) {
            //Put account ids on leads
            if (LeadsByNameKeys.containsKey(a.Name)) {
                LeadsByNameKeys.get(a.Name).Account_Id__c = a.Id;
            }
            
        }
        
       
        
    }
}
            
 Account a = new Account(name=accountName,Phone = phone,Website = website)
above line shows me value in debug log as 04:20:02:180 USER_DEBUG [35]|DEBUG|inserted(Account:{Name=sai Not Assigned, Phone=8987879, Website=www.test.com, Id=0014D00000EnHcWQAV})     
    Please can anyone help me on this.Any help will be greatly appreciated.

Thanks,
Sirisha
       
        
        
    
    
    
 
Hi 
Please help me i want to fetch the details user who doesn't login in the instance (environment) since last 2 weeks.how to write the soql to fetch this information.

Thanks,
Saif.
  • November 02, 2018
  • Like
  • 0
Hi All,

 I am trying to display the name in the user signature in the email template body.

Hi {!User.FirstName},

body

Regards,
{!if(User.FirstName = "XYZ","Team","null")}

If the user's first name is XYZ ,it should appear as

Regards ,
Team

else it should appear as

Regards,
XYZ

Please help me on this.

Thanks,
Sirisha
 
Hi All,

I have created login form with username and passsword.I have created new custom fields in the contact object.
On click of submit button.It will validates the contact is existing or not and returns contact's FirstName,LastName,Email,Phone.

For this I created a RESTAPI which will take the username and password as a parameters and validates against the credentials and  returns the contact details for that valid user.Login form i have created in my org. using lightning.

Now my challenge is  when the user clicks on submit button it should get the contact details from the RESTAPI and maps with the contact object fields and   reload or refresh the page with contact details and displays the field values FirstName,LastName,Email and Phone.
I am trying to pass the variables or map the variables which are returned from REST API to APEX.

How can I acheive this scenario.Do I need to create another lightning component to refresh the parent component to child component and returns the login contact details.

If anyone can provide a sample code that would be a great help.

Any help would be greatly appreciated.

Thanks,
Sirisha