• David Kerr 5
  • NEWBIE
  • 35 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 11
    Replies
Hi, I'm looking to require users to upload a file to an open opportunity on the Opportunity object before marking the stage as Closed/Won.  

I have the following code so far (src - https://developer.salesforce.com/forums/?id=906F00000008wHEIAY): 

trigger OpptyTest on Opportunity (before insert, before update) {
Opportunity[] opp=trigger.new;
    for(Opportunity oppy : [SELECT Id, 
                            (SELECT Id, Name, ContentType FROM Attachments) 
                            FROM Opportunity where id=:opp[0].Id]){
        Attachment[] attc = oppy.Attachments;
            if(!attc.isEmpty()){
                opp[0].Attachment__c = true;
                }
            if(attc.isEmpty()){
                opp[0].Attachment__c = false;
                }                  
}}

The issue as stated in the source post is that you need to edit the opportunity before the checkbox field 'Attachment' is marked True.  What would be the best solution to having the 'Attachment' field automatically check TRUE once the file is attached?

Once this is solved, the user will be able to mark the opportunity as Closed/Won through a validation rule that has been added.
I have set my Attachment field check box on the opportunity object to be 'read-only' in the page layout: User-added image


However, when I go to one of my opportunities, the field can still be edited: User-added image


Any idea why this might be happening / a quick fix?
Hi,

I'm having trouble removing some Apex classes from production through Eclipse.  I've changed the status to 'deleted', but when I validate the deploy to server, I'm receiving an error: Problem: The page you have tried to delete is currently being referenced by a page, custom link, button, web tab, dashboard, SoftPhone layout or custom sidebar component. Please delete the reference before deleting the page.

I checked the page in Production and it looks like it is being referenced by these 2 apex classes that I deleted in Eclipse.  Not sure where to go from here.

Thanks!
Hi,

I'm trying to deploy an apex class/trigger from sandbox to production.  Once in production, I'm trying to validate the deployment and I received 6 errors, putting my percentage coverage below the 75% threshold.  I'm looking for an easy way to remove these old apex classes from production so that the validation can remain over the 75% minimum.
Hi,

I'm new to Apex coding and need some assistance creating the test class code in the developer console.  Here is my Apex Trigger code:

trigger LeadExist on Lead (before insert, after update) 
{
    Set<String> EmailId = new Set<String>();
    Map<String,String> MapuserId = new Map<String,String>();
    List<Child__c> usrlist = new List<Child__c>(); 
    for(Lead ld : trigger.new)
    {
        If(ld.Email != null)
        {
            EmailId.add(ld.Email);
        }
    }
    
    If(EmailId.size() > 0)
    {
        usrlist = [Select Id,Parent_Customer_ID__c, Email__c from Child__c Where Email__c IN: EmailId];     
    }    
    if(usrlist.size() > 0)
    {
         for(Child__c c : usrlist)
        {
            if(!MapuserId.containsKey(c.Email__c))
            {
                MapuserId.put(c.Email__c, c.Id);  
            }
        }
    }
    
    for(Lead ld : trigger.new)
    {
        if(MapuserId.containsKey(ld.Email))
        {
            ld.Child_Exist__c = MapuserId.get(ld.Email);
        }
    }
}


Thanks for the help in advance!
I have the following code that I want to trigger when a new Lead comes into the system.  The trigger will auto populate the "Child Exist" Lookup field on the Lead object if its email matches with a user in the Child object.  If the two emails match, I want to have the Parent_Customer_ID__c of the Child user to auto-populate into the Child Exist field on the Lead.  If there is no match, it can be left blank.

trigger LeadExist on Lead (before insert) {

    Set<String> EmailId = new Set<String>();
    Map<String,String> MapuserId = new Map<String,String>();
    List<Child__c> usrlist = new List<Child__c>(); 
    for(Lead ld : trigger.new)
    {
        If(ld.Email != null)
        {
            EmailId.add(ld.Email);
        }
    }
    
    If(EmailId.size() > 0)
    {
        usrlist = [Select Parent_Customer_ID__c, Email__c from Child__c Where Email__c IN: EmailId];     
    }    
    if(usrlist.size() > 0)
    {
         for(Child__c c : usrlist)
        {
            if(!MapuserId.containsKey(c.Email__c))
            {
                MapuserId.put(c.Email__c, c.Parent_Customer_ID__c);  
            }
            
        }
    }
    
    for(Lead ld : trigger.new)
    {
        ld.Email= MapuserId.get(ld.Child_Exist__c);   
    }

}



Currently, I'm able to save the trigger and create a test lead & child.  However, when I save the test Lead, the email address is not being saved -- once I update the lead after it has been created, the email address will save.  The Parent_Customer_ID__c still won't auto populate.  Any help here will be greatly appreciated!
I'm new to Apex & trying to figure out a trigger that will match the email of a Lead & a Child user and give me the Id in one object.  If a lead already exists as a child, I want the child Id.  Otherwise, the field in the Lead object should be left blank.  Any idea how to approach this?
Hi, I'm looking to require users to upload a file to an open opportunity on the Opportunity object before marking the stage as Closed/Won.  

I have the following code so far (src - https://developer.salesforce.com/forums/?id=906F00000008wHEIAY): 

trigger OpptyTest on Opportunity (before insert, before update) {
Opportunity[] opp=trigger.new;
    for(Opportunity oppy : [SELECT Id, 
                            (SELECT Id, Name, ContentType FROM Attachments) 
                            FROM Opportunity where id=:opp[0].Id]){
        Attachment[] attc = oppy.Attachments;
            if(!attc.isEmpty()){
                opp[0].Attachment__c = true;
                }
            if(attc.isEmpty()){
                opp[0].Attachment__c = false;
                }                  
}}

The issue as stated in the source post is that you need to edit the opportunity before the checkbox field 'Attachment' is marked True.  What would be the best solution to having the 'Attachment' field automatically check TRUE once the file is attached?

Once this is solved, the user will be able to mark the opportunity as Closed/Won through a validation rule that has been added.
I have set my Attachment field check box on the opportunity object to be 'read-only' in the page layout: User-added image


However, when I go to one of my opportunities, the field can still be edited: User-added image


Any idea why this might be happening / a quick fix?
I have the following code that I want to trigger when a new Lead comes into the system.  The trigger will auto populate the "Child Exist" Lookup field on the Lead object if its email matches with a user in the Child object.  If the two emails match, I want to have the Parent_Customer_ID__c of the Child user to auto-populate into the Child Exist field on the Lead.  If there is no match, it can be left blank.

trigger LeadExist on Lead (before insert) {

    Set<String> EmailId = new Set<String>();
    Map<String,String> MapuserId = new Map<String,String>();
    List<Child__c> usrlist = new List<Child__c>(); 
    for(Lead ld : trigger.new)
    {
        If(ld.Email != null)
        {
            EmailId.add(ld.Email);
        }
    }
    
    If(EmailId.size() > 0)
    {
        usrlist = [Select Parent_Customer_ID__c, Email__c from Child__c Where Email__c IN: EmailId];     
    }    
    if(usrlist.size() > 0)
    {
         for(Child__c c : usrlist)
        {
            if(!MapuserId.containsKey(c.Email__c))
            {
                MapuserId.put(c.Email__c, c.Parent_Customer_ID__c);  
            }
            
        }
    }
    
    for(Lead ld : trigger.new)
    {
        ld.Email= MapuserId.get(ld.Child_Exist__c);   
    }

}



Currently, I'm able to save the trigger and create a test lead & child.  However, when I save the test Lead, the email address is not being saved -- once I update the lead after it has been created, the email address will save.  The Parent_Customer_ID__c still won't auto populate.  Any help here will be greatly appreciated!
I'm new to Apex & trying to figure out a trigger that will match the email of a Lead & a Child user and give me the Id in one object.  If a lead already exists as a child, I want the child Id.  Otherwise, the field in the Lead object should be left blank.  Any idea how to approach this?