• Benjamin Oliver
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 7
    Replies
Hi Community,

I need a trigger to check a Lead's zip code and determine if it matches a set of zip codes that my business services.  If it is a matching zip code, I would like Salesforce to update a checkbox field called 'Local Delivery'.  This way we can identify which Leads are close to our business.  I believe the pseudo code looks like:

trigger UpdateLocalDelivery on Lead (before insert) {
for (Lead lead : trigger.new){
        // if Lead.zip equals one of the following zip codes [22202, 22203, 22204, 22201]
        // then set Lead.Local_Deliver__c = true;
    }

Thank you in advance!

Also, what would the unit test for this trigger look like?

Hi Community,

I am new to Salesforce and using APEX.  I am completely self-taught too.  With that said, I am trying to learn triggers and cannot find an exact example of how to achieve what I am working on.  My problem is that when a Contact updates their information through my Visualforce page, Salesforce will overwright fields with the new data they inputted - which is great, except for the 'Description' field.  I want the new 'Description' to append to whatever they previously had written in that field.  Can anyone help me?

The pseudo code would be something like:

trigger UpdateDescription on Contact (before update) {
          Contact.Description = Contact.OldDescription + " " + Contact.NewDescription;

}

Thank you in advance for your help!

Hello Community,

I am a grad student working with Salesforce for the first time and need some assistance.  I apologize for this obviously played out error, but my situation wasn't able to be remedied quickly.  Therefore I am hoping someone can guide/direct me to a solution.  Below is my VF and Controller code.  Thank you in advance!

VF Page:


<apex:page standardController="Lead" extensions="LeadIntakeController" title="Lead Intake Form" showHeader="false">

<apex:form >

<apex:pageBlock title="Critical Needs Form ">

<apex:pageBlockSection title="Lead" columns="1">

<apex:pageBlockSection columns="2">

<apex:outputText escape="false" value="<b>Lead Details</b>" style="sample"/>

<apex:outputText escape="false" style="sample"/> <apex:inputField value="{!lead.FirstName}"/>

....

</apex:pageBlockSection>

<apex:pageBlockSection columns="2">

<apex:outputText escape="false" value="<b>Dependent Information</b>" style="sample"/>

<apex:outputText escape="false" style="sample"/>

<apex:inputField value="{!dependent.Name}" />

<apex:inputField value="{!dependent.Gender__c}" />

.....

</apex:pageBlockSection>

</apex:pageBlockSection>

<apex:pageBlockButtons >

<apex:commandButton value="Save" action="{!save}" />

</apex:pageBlockButtons>

</apex:pageBlock>

</apex:form>

</apex:page>
 

 

Controller: 

public class Lead_Intake_Controller {

   public Lead lead {get;set;}

   public Lead_Intake_Controller(ApexPages.StandardController controller) 
   {
       lead = (Lead)controller.getRecord();
   }
   
   public PageReference save()
   {

        if(lead!=null)
        {
            Datetime bday = lead.Birthdate__c;
            if(bday.Date().daysBetween(System.now().Date()) > 23709)
            {
                lead.Over_65__c = true;
            }
        
        lead.Recipient__c = true;
        lead.Company = 'Self';

        insert lead;
        
        Dependent__c newDependent = new Dependent__c();
        newDependent.Name = 'value';
        newDependent.Parent_Lead__c = lead.Id;
        newDependent.Contact__c = 'someValue';
        newDependent.Birth_Year__c = 'anotherValue';
        
        insert newDependent;
        }
        
        PageReference pageRef = new PageReference('/apex/Lead_Registration_Complete');
        pageRef.setRedirect(true);
        return pageRef;
   }
   }

 

Hi Community,

I am new to Salesforce and using APEX.  I am completely self-taught too.  With that said, I am trying to learn triggers and cannot find an exact example of how to achieve what I am working on.  My problem is that when a Contact updates their information through my Visualforce page, Salesforce will overwright fields with the new data they inputted - which is great, except for the 'Description' field.  I want the new 'Description' to append to whatever they previously had written in that field.  Can anyone help me?

The pseudo code would be something like:

trigger UpdateDescription on Contact (before update) {
          Contact.Description = Contact.OldDescription + " " + Contact.NewDescription;

}

Thank you in advance for your help!