Friday, June 19, 2020

Converting list of string to list of lowercase in Apex

This post explains how to convert a list of strings to a list of Lowercase .


To convert a list of strings to a list of lowercase , you just need to run a loop over the list and use the "toLowerCase()"  method.



public class TolowerCase {
    public static void Cases()
    {
        List<String> Values = new List<String>{'SALES', 'MARKETING', 'SERVICE'};
            
            for(String s : Values)
        {
                s.toLowerCase();
                System.debug('OrignalWord------>>'+s);
                System.debug('LowerCaseWord------>>' + s.toLowerCase());
              
            }
    }
}


Result :-  




Easy right..........!!

Thanks,
Lovesalesforceyes


Tuesday, June 16, 2020

Apex trigger to Store File type Attachment in Document folder Whenever Article is updated

Trigger Create_Doc on Knowledge__kav (After insert) {
    list<id> ids = new list<id>();
    For(Knowledge__kav k : trigger.new)
    {
        ids.add (k.Id);
    }
    list<Knowledge__kav> recs = [select  Upload__Name__s, Upload__ContentType__s,     Upload__Length__s, Upload__Body__s from Knowledge__kav where id =: ids];
    for(Knowledge__kav k1 : recs)
    {
        Document doc = new Document();
        doc.Name = k1.Upload__Name__s;
        doc.FolderId = '00l2v000002hABpAAM';  // Document folder id
        doc.Body = k1.Upload__Body__s;
        doc.ContentType = k1.Upload__ContentType__s;
        doc.Type = k1.Upload__ContentType__s;      

        insert doc;
    
    }
}


  As I've created one article name "upload file3" with file type attachment "test.txt"



After Update this article file type attachment "text.txt" is inserted in document with folder public images





Thanks,
Lovesalesforceyes.





Saturday, June 13, 2020

Lightning component to search contact (With Name and Email)

Apex Class :


public with sharing class SearchContact {
    
    @auraEnabled
    
    public static List<contact> getContact (string name1,string email1)
 {
  
        return [select id,Name,Email,Department from Contact where(Name =: name1 and                             Email =: email1)];

    }
    
}


Component :


<aura:component controller="SearchContact">
    
    <aura:attribute name="SearchedContact" type="Contact[]" />
    
    <aura:attribute name="name1" type="string" />
    <aura:attribute name="email1" type="string" />
 
    <lightning:input  type="string" name="input1" label="name" value="{!v.name1}" />
    <lightning:input type="string"  name="input2" label="email" value="{!v.email1}"/>
    <lightning:button label="Search" onclick="{!c.Search}" />
    
    
    <aura:iteration items="{!v.SearchedContact}" var="SearchedContactIt">
        <table>
            
            <tr>
            <th>name</th><th>Email</th><th>Department</th>
            </tr>

            <tr>
                <td>{!SearchedContactIt.Name}</td><td>{!SearchedContactIt.Email}</td>
            </tr>  
            
        </table>
        
    </aura:iteration>
    
</aura:component>


Controller :


({
    Search : function(component, event, helper) {
        
        var Action = component.get("c.getContact");
        
        var N1=component.get("v.name1");
        var E1=component.get("v.email1");
        newExpense.setParams({
            "name1":N1,
            "email1":E1
        });
        
        Action.setCallback(this, function(response) {
            component.set("v.SearchedContact", response.getReturnValue());
            
        });
       
        $A.enqueueAction(Action );
        
    },
 
});


Preview :

                  Here's your component looks like this.
                You just need to enter a name or email or both and hit the search button.
                All the contact with that name and email are shown as in img.


Thanks,
LoveSalesforceYes


Get selected radio button value in LWC

This post explains how to get selected radio button in LWC. Below is demo of output : To use the radio button in LWC you have to use the  li...