• Kunal Kaushik
  • 5 Points
  • Member since 2017

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 3
Hi ,

I have written the below trigger code. It is working fine but is not at all optimised. It is having three for loops. Can anyone please guide me with a code snippet.
trigger AttachmentTrigger on Attachment (after insert) {
    List<Account> accountList = new List<Account>();
    List<Lead> leadlist = new List<Lead>();
    List<String> emails = new List<String>();
    Set<Id> accIds = new Set<Id>();
    List<Attachment> atts = new List<Attachment>();
    for(Attachment att : trigger.New){
        if(att.ParentId.getSobjectType() == Lead.SobjectType){
        leadList = [Select id , email from lead where id in : accIds];
        for(Lead l : leadlist){
        accountList = [select id, Email__c from Account where email__c in : emails];
        if(accountList!=null && accountList.size()>0){
            for(Account acc : accountList){
                for(Lead ld : leadlist){
                    if(ld.email == acc.email__c){
                        Attachment newFile = new attachment();
                        newfile.Body = att.Body;
                        newfile.Name = att.Name;
                        newfile.Description = att.Description;
                        newfile.ParentId = acc.id;
        insert atts;

  • April 14, 2019
  • Like
  • 0

Could you please help me how to scan substring within the string.

Scanned String - Ankit

Example - My Name is Ankit -- Search found and answer should be True or Ankit.

Example - My Name is Ankita -- Search not found (As user searching for Ankit not Ankita) and answer should be False.

I am trying to use indexOfIgnoreCase(string) , but this is failing in second scenario.
Hi all - I'm trying to create a validation rule where the date of a child record can't exceed the date of the master record.  In other words, if the master record had an end date of 7/30/19, the child record cannot have an end date of 7/31/19.

The error I get is: Error: Incorrect parameter type for operator '>'. Expected Date, received Object

This is what I tried: Implementation_Date_Best_Case__c > $ObjectType.Project_Detail__c.Fields.Project_End_Date__c

Any ideas? I'm thinking it's a validation rule but if it's another function, any advice would be appreciated. thx!