• Harry1008
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 14
    Replies
Hi,
Could you please explain me how to bypass a validation rule in the below trigger. The validation rule is to restrict the users not to change the Status manually. The trigger changes the status from Engagement to Negotiation when the user upload the file on Engagement Status. Please see the below trigger and validation rule. I am getting the errors. Could someone please help.
Triiger:
trigger FileUploadonLead on ContentVersion (before insert, after insert, before update, after update) {
map <id,string> lmap = new map <id,string>();
    list<lead> leadlist = new list <lead>();
    
    //Add file upload logic to run this trigger
    //if(Fileupload)
    
    
        if(Trigger.isBefore)
        {
            for(contentversion cv : trigger.new)
            {
                 for(LeadRecord objL: [SELECT Id, Status FROM Lead Where Id = cv.FirstPublishLocationId AND Status = 'Engagement'])
                 {
              objL.On_and_Off__c = true;
                              }
             }
        }
    else
    {
        for(contentversion cv : trigger.new)
        {
            id x = cv.FirstPublishLocationId;
            if(string.valueof(x.getSobjecttype()) == 'lead' && cv.On_and_off__c == true)
            {
                lmap.put(cv.FirstPublishLocationId,'Negotiation');
            }
        }
        
        for(Lead l : [SELECT Id,Status FROM Lead Where Id IN : lmap.KeySet() AND Status = 'Engagement']){
        System.debug('lmap.get()'+ lmap.get(l.id) );
            l.status = lmap.get(l.id);
            leadlist.add(l);
        }
        
        if(leadlist.size()>0){
            system.debug('leadlist' + leadlist);
            update leadlist;
        }
    }
  
    
}

Validation Rule:

OR( 
IF(On_and_Off__c=FALSE, TRUE, FALSE), 
ISCHANGED(Status), 
AND( 
NOT(ISPICKVAL(Status,"Negotiation Lost")), 
OR( 
$Profile.Name <> "System Administrator"
)))
Hi,
Could you please explain me how to bypass a validation rule in the below trigger. The validation rule is to restrict the users not to change the Status manually. The trigger changes the status if they upload a file. I have created a checkbox called "On and OFF" but couldn't figure out how to include.
rigger FileUploadonLead on ContentVersion (after insert) {
map <id,string> lmap = new map <id,string>();
    list<lead> leadlist = new list <lead>();
    for(contentversion cv : trigger.new){
        id x = cv.FirstPublishLocationId;
        if(string.valueof(x.getsobjecttype()) == 'lead'){
            system.debug('inside test');
            lmap.put(cv.FirstPublishLocationId,'Negotiation');
            
            
        }
        
        
    }
    
    for(Lead l : [SELECT Id,Status FROM Lead Where Id IN : lmap.keySet() AND Status = 'Engagement']){
    system.debug('lmap.get() '+ lmap.get(l.id) );
        l.status = lmap.get(l.id);
        leadlist.add(l);
        
    }
    
    if(leadlist.size()>0){
        system.debug('leadlist ' + leadlist );
        update leadlist;
    }
}

 
Hi All,
I have written a Trigger to update the lead status from Engagement to Negotiation when a file is uploaded on Lead when the status is Engagement. I want to restrict the trigger to fire when the file is uploaded on Engagement status and update the status to negotiation thats it. The trigger should not fire if the lead is on another status and if a user upload the file. Could you please help me how to achieve this in the below code.
trigger FileUploadonLead on ContentVersion (after insert) {
map <id,string> lmap = new map <id,string>();
    list<lead> leadlist = new list <lead>();
    for(contentversion cv : trigger.new){
        id x = cv.FirstPublishLocationId;
        if(string.valueof(x.getsobjecttype()) == 'lead'){
            system.debug('inside test');
            lmap.put(cv.FirstPublishLocationId,'Negotiation');
            
            
        }
        
        
    }
    
    for(lead l : [select id,status from lead where id in : lmap.keySet()]){
    system.debug('lmap.get() '+ lmap.get(l.id) );
        l.status = lmap.get(l.id);
        leadlist.add(l);
        
    }
    
    if(leadlist.size()>0){
        system.debug('leadlist ' + leadlist );
        update leadlist;
    }
}

 
Hi All,
I wrote a Trigger on ContentVersion. The requirement is when I upload a file on the lead when the lead is only on the status "Engagement" then the status should change to "Negotiation". with the below trigger which ever the status is if I upload the file the lead status is changing to "Converted".
Could someone help please.
trigger FileUploadonLead on ContentVersion (after insert) {
map <id,string> lmap = new map <id,string>();
    list<lead> leadlist = new list <lead>();
    for(contentversion cv : trigger.new){
        id x = cv.FirstPublishLocationId;
        if(string.valueof(x.getsobjecttype()) == 'lead'){
            system.debug('inside test');
            lmap.put(cv.FirstPublishLocationId,'Negotiation');
            
            
        }
        
        
    }
    
    for(lead l : [select id,status from lead where id in : lmap.keySet()]){
        l.status = lmap.get(l.id);
        leadlist.add(l);
        
    }
    
    if(leadlist.size()>0){
        
        update leadlist;
    }
}

 
HI all,
Could you please help me in writing a test class for the following apex trigger. The trigger is to change the lead status to Negotiation when the user attach the file on to the lead.
Thank you for your help.
trigger UploadFileLead on Attachment (after insert, after update) {
    List <Lead> LeadList = new List<Lead>();
      List <Lead> LeadListToUpdate = new List<Lead>();
    Set <Id> LeadIds = new Set <Id>();
    if(trigger.isInsert || trigger.isUpdate)
    {
        for (Attachment attach : trigger.New) {
            //Check if added attachment is related to Lead or not
            if(attach.ParentId.getSobjectType() == Lead.SobjectType){
                if(string.valueOf(attach.Name).startswith('.xls'))
                    LeadIds.add(attach.ParentId);
                
            }
        }
    }
     
 
LeadList = [select id, status from Lead where id in : LeadIds];
    for(Lead lead : LeadList){
        
        
        lead.Status = 'Negotiation';
        
        
    }
    
    update LeadList;
}

 
We have a lightning component called Calls Calenar which is used to create calls to interact with customers. When we create a new call the time populates as start time as 12:43:56 format. I need to change this format to 12:30 format. Please see the attached controller.
User-added image
Hi,
Could you please explain me how to bypass a validation rule in the below trigger. The validation rule is to restrict the users not to change the Status manually. The trigger changes the status if they upload a file. I have created a checkbox called "On and OFF" but couldn't figure out how to include.
rigger FileUploadonLead on ContentVersion (after insert) {
map <id,string> lmap = new map <id,string>();
    list<lead> leadlist = new list <lead>();
    for(contentversion cv : trigger.new){
        id x = cv.FirstPublishLocationId;
        if(string.valueof(x.getsobjecttype()) == 'lead'){
            system.debug('inside test');
            lmap.put(cv.FirstPublishLocationId,'Negotiation');
            
            
        }
        
        
    }
    
    for(Lead l : [SELECT Id,Status FROM Lead Where Id IN : lmap.keySet() AND Status = 'Engagement']){
    system.debug('lmap.get() '+ lmap.get(l.id) );
        l.status = lmap.get(l.id);
        leadlist.add(l);
        
    }
    
    if(leadlist.size()>0){
        system.debug('leadlist ' + leadlist );
        update leadlist;
    }
}

 
Hi All,
I have written a Trigger to update the lead status from Engagement to Negotiation when a file is uploaded on Lead when the status is Engagement. I want to restrict the trigger to fire when the file is uploaded on Engagement status and update the status to negotiation thats it. The trigger should not fire if the lead is on another status and if a user upload the file. Could you please help me how to achieve this in the below code.
trigger FileUploadonLead on ContentVersion (after insert) {
map <id,string> lmap = new map <id,string>();
    list<lead> leadlist = new list <lead>();
    for(contentversion cv : trigger.new){
        id x = cv.FirstPublishLocationId;
        if(string.valueof(x.getsobjecttype()) == 'lead'){
            system.debug('inside test');
            lmap.put(cv.FirstPublishLocationId,'Negotiation');
            
            
        }
        
        
    }
    
    for(lead l : [select id,status from lead where id in : lmap.keySet()]){
    system.debug('lmap.get() '+ lmap.get(l.id) );
        l.status = lmap.get(l.id);
        leadlist.add(l);
        
    }
    
    if(leadlist.size()>0){
        system.debug('leadlist ' + leadlist );
        update leadlist;
    }
}

 
Hi All,
I wrote a Trigger on ContentVersion. The requirement is when I upload a file on the lead when the lead is only on the status "Engagement" then the status should change to "Negotiation". with the below trigger which ever the status is if I upload the file the lead status is changing to "Converted".
Could someone help please.
trigger FileUploadonLead on ContentVersion (after insert) {
map <id,string> lmap = new map <id,string>();
    list<lead> leadlist = new list <lead>();
    for(contentversion cv : trigger.new){
        id x = cv.FirstPublishLocationId;
        if(string.valueof(x.getsobjecttype()) == 'lead'){
            system.debug('inside test');
            lmap.put(cv.FirstPublishLocationId,'Negotiation');
            
            
        }
        
        
    }
    
    for(lead l : [select id,status from lead where id in : lmap.keySet()]){
        l.status = lmap.get(l.id);
        leadlist.add(l);
        
    }
    
    if(leadlist.size()>0){
        
        update leadlist;
    }
}

 
HI all,
Could you please help me in writing a test class for the following apex trigger. The trigger is to change the lead status to Negotiation when the user attach the file on to the lead.
Thank you for your help.
trigger UploadFileLead on Attachment (after insert, after update) {
    List <Lead> LeadList = new List<Lead>();
      List <Lead> LeadListToUpdate = new List<Lead>();
    Set <Id> LeadIds = new Set <Id>();
    if(trigger.isInsert || trigger.isUpdate)
    {
        for (Attachment attach : trigger.New) {
            //Check if added attachment is related to Lead or not
            if(attach.ParentId.getSobjectType() == Lead.SobjectType){
                if(string.valueOf(attach.Name).startswith('.xls'))
                    LeadIds.add(attach.ParentId);
                
            }
        }
    }
     
 
LeadList = [select id, status from Lead where id in : LeadIds];
    for(Lead lead : LeadList){
        
        
        lead.Status = 'Negotiation';
        
        
    }
    
    update LeadList;
}

 
I wrote a fairly simple trigger on the ContentVersion object which ultimately would allow tracking opportunities without a signed contract. 

So a document is added or changed and the picklist value 'Signed Contract' is selected. This would flip the 'HasSignedQuote__c' bollean on true on the opportunity. 

However I noticed that the LinkedEntityId from the ContentDocumentLink is not always populated and I can't get my finger behind the root cause.
 
trigger ContentVersion_TRIGGER on ContentVersion (After insert, After update) {

      
    Public static Boolean SignedContract = false;

    System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - TRIGGER ');
    

        Set<Id> contentDocumentIdSet = new Set<Id>();
        for(ContentVersion cv:trigger.new){

            if(cv.ContentDocumentId != null){
                contentDocumentIdSet.add(cv.ContentDocumentId);
                If(cv.File_Type__c == 'Signed Contract'){ //** Based on Content version picklist ...
                   System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Set SignedContract = true');   
                   SignedContract = true;
                }
            }
        }
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].contentDocumentIdSet'+contentDocumentIdSet);   
        ContentDocumentLink cdl = [SELECT ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN:contentDocumentIdSet Limit 1];
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].ContentDocumentLink  :'+cdl.LinkedEntityId);      
        List<Opportunity> OppList = [SELECT Id, HasSignedQuote__c FROM Opportunity where Id =:cdl.LinkedEntityId];  
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].OppList.size() :'+OppList.size());  
        For (Opportunity Opp:OppList){
            If (SignedContract == true){
                System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Flag opportunity HasSignedQuote to true ...');   
                Opp.HasSignedQuote__c = true;
            }
        }
        Update OppList;
   
} //** end of Class