• YSP
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
We have created a custom lightning component with lookup fields to our account object. Users are currently able to search in the field however the results while typing are always ones that start with the same letters that are entered. Is is possible to have the search return results which contain the letters being typed anywhere in the account name?

Example: Account Name = Apple 
If you type "App" in the lookup field then Apple will appear as a result.
If you type "ppl"  in the lookup field then there are no results found. How can we make it so "ppl" will also return Apple as a result?

Code for Query:
 
public class Lookup {

    /**
     * Returns JSON of list of ResultWrapper to Lex Components
     * @objectName - Name of SObject
     * @fld_API_Text - API name of field to display to user while searching
     * @fld_API_Val - API name of field to be returned by Lookup COmponent
     * @lim   - Total number of record to be returned
     * @fld_API_Search - API name of field to be searched
     * @searchText - text to be searched
     * */
    @AuraEnabled 
    public static String searchDB(String objectName, String fld_API_Text, String fld_API_Val, 
                                  Integer lim,String fld_API_Search,String searchText ){
        
        searchText='\'%' + String.escapeSingleQuotes(searchText.trim()) + '%\'';

        
        String query = 'SELECT '+fld_API_Text+' ,'+fld_API_Val+
            			' FROM '+objectName+
            				' WHERE '+fld_API_Search+' LIKE '+searchText+ 
            			' LIMIT '+lim;
  • February 20, 2020
  • Like
  • 0
If I have an object in Salesforce that a profile currently does not have any access to however I want to add a button which updates a field on a record in that object is that possible?

Can there be any customization which can allow the update to happen as a user which does have access to the object or even as an admin or is giving access to the object the only option?
  • September 17, 2019
  • Like
  • 0
Hello,

I am working on an email trigger which will also attach the related files to the email. I have included the code I put together below. When I try to trigger the email I recieve an error stating the list has no rows for assignment to SObject in line 50 (contentversion cv = [Select Id, ContentDocumentId, VersionData, PathOnClient, FileType from ContentVersion where ContentDocumentId = :cd.Id];).

I was originally using ContentDocument instead of ContentDocumentLink however when the email fired none of the related files were included. Is there something I'm doing wrong?
 
trigger Send_ChecklistEmail on Food_Safety_Section_Worksheet__c (after update) {


    for(Food_Safety_Section_Worksheet__c SC : trigger.new){
        Food_Safety_Section_Worksheet__c oldSC = Trigger.oldMap.get(SC.Id);
        if(SC.Send_Email__c == true && SC.Send_Email__c != oldSC.Send_Email__c){
            
            //Retrieve Email template
            EmailTemplate et=[Select id from EmailTemplate where name=: 'Food Safety Email'];
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            //add template
            singlemail.setTemplateId(et.Id);
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
            singlemail.setWhatId(SC.Id);
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(SC.Franchisee_Email__c);
            sendTo.add(owneremail);
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
        List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();

for( ContentDocumentLink cd : [select Id, LinkedEntityId from ContentDocumentLink where LinkedEntityId =  :SC.Id]){ 
contentversion cv = [Select Id, ContentDocumentId, VersionData, PathOnClient, FileType from ContentVersion where ContentDocumentId = :cd.Id];
        
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(cv.PathOnClient);
efa.setBody(cv.VersionData);
efa.setContentType(cv.FileType);
efa.setInline(false);
fileAttachments.add(efa);
}
singlemail.setFileAttachments(fileAttachments);
       

        //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
 }  
}
}
Thanks!
 
  • July 02, 2019
  • Like
  • 0
I've been working on an email trigger which will include the attachments tied to the record when the email is sent. Below is the trigger. The email gets sent however the attachments aren't included for some reason. Is there something missing?
 
trigger Send_ChecklistEmail on Food_Safety_Section_Worksheet__c (after update, before insert) {


    for(Food_Safety_Section_Worksheet__c SC : trigger.new){
        Food_Safety_Section_Worksheet__c oldSC = Trigger.oldMap.get(SC.Id);
        if(SC.Send_Email__c == true && SC.Send_Email__c != oldSC.Send_Email__c){
            
            //Retrieve Email template
            EmailTemplate et=[Select id from EmailTemplate where name=: 'Food Safety Email'];
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            //add template
            singlemail.setTemplateId(et.Id);
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
            singlemail.setWhatId(SC.Id);
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(SC.Franchisee_Email__c);
            sendTo.add(owneremail);
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
        List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (Attachment a : [select Id, Name, Body, BodyLength, ContentType from Attachment where ParentId = : SC.Id])
        {
        // Add to attachment file list
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
        efa.setFileName(a.Name);
        efa.setBody(a.Body);
        efa.setContentType(a.ContentType);
        efa.setInline(false);
        fileAttachments.add(efa);
        }
        singlemail.setFileAttachments(fileAttachments);

        //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
 }  
}
}

 
  • June 27, 2019
  • Like
  • 0
I've been working on an email trigger which will include the attachments tied to the record when the email is sent. Below is the trigger. The email gets sent however the attachments aren't included for some reason. Is there something missing?
 
trigger Send_ChecklistEmail on Food_Safety_Section_Worksheet__c (after update, before insert) {


    for(Food_Safety_Section_Worksheet__c SC : trigger.new){
        Food_Safety_Section_Worksheet__c oldSC = Trigger.oldMap.get(SC.Id);
        if(SC.Send_Email__c == true && SC.Send_Email__c != oldSC.Send_Email__c){
            
            //Retrieve Email template
            EmailTemplate et=[Select id from EmailTemplate where name=: 'Food Safety Email'];
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            //add template
            singlemail.setTemplateId(et.Id);
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
            singlemail.setWhatId(SC.Id);
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(SC.Franchisee_Email__c);
            sendTo.add(owneremail);
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
        List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (Attachment a : [select Id, Name, Body, BodyLength, ContentType from Attachment where ParentId = : SC.Id])
        {
        // Add to attachment file list
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
        efa.setFileName(a.Name);
        efa.setBody(a.Body);
        efa.setContentType(a.ContentType);
        efa.setInline(false);
        fileAttachments.add(efa);
        }
        singlemail.setFileAttachments(fileAttachments);

        //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
 }  
}
}

 
  • June 27, 2019
  • Like
  • 0