• Nathan Wylder
  • NEWBIE
  • 20 Points
  • Member since 2015
  • Salesforce Administrator
  • Int

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 7
    Replies
I have a process whereby whenever a specific campaign member object is created or a specific case is closed, I'd like the class to run and update 2 fields on the related contact object. But I'm stumped. How do I write the trigger to call this class? It seems like all examples I can can find online are very simple (only involve 1 object), but I have 3.
A. How can I make sure this code runs appropriately?
B. Do I need a trigger on the Campaign Member object, Case Member object or the Contact? Or all 3? 

Here's the class:
 
public class MobilizationCredit {
	//Start when Qualifying Case is edited, closed,        deleted OR
    //Start when Qualifying Campaign Member record is created, edited, deleted
      
    private date MaxDate(Contact c){
    	//Get max Date Begins value related to the Volunteer__c.contactId__r record
        Date casemaxdate2;
        Date campmaxdate2;
        string VolunteerId = c.Id;
        
 	  	List<AggregateResult> CaseMaxDate = [SELECT MAX(Date_Begins__c) FROM Case WHERE Volunteer__c = :VolunteerId AND Qualifies_for_Mobilization__c = TRUE];
		for (AggregateResult ar: CaseMaxDate) {
			system.debug('Max case date found was: '+ ar.get('expr0') + '.');
        	casemaxdate2 = Date.valueOf(ar.get('expr0'));
        }
    
     	//Get max Start Date value of all qualifying campaign member records related to the Contact.Id record
	  	List<AggregateResult> CampMemMaxDate = [SELECT MAX(Start_Date__c) FROM CampaignMember WHERE ContactId = :VolunteerId AND Campaign_Type__c = 'Weekly Attendance'];
		for (AggregateResult ar : CampMemMaxDate) {
 			system.debug('Max campaign member max date found was: '+ ar.get('expr0') + '.');
 			campmaxdate2 = Date.valueOf(ar.get('expr0'));
		}
 		system.debug('Campmaxdate: ' + campmaxdate2);
 		system.debug('Casemaxdate: ' + casemaxdate2);

		if (campmaxdate2 > casemaxdate2) {
    		system.debug('camp is bigger');
        	return campmaxdate2;
		}
		else {
    		system.debug('camp is not bigger');
			return casemaxdate2;
    	}
	}
        
    private string MobilizationStatus (Contact c){
             
         if((c.Last_Served_Date__c<>null) && (Date.TODAY().daysBetween(c.Last_Served_Date__c) < 180) && (c.Volunteer_Status_Current__c =='Activated')) {
            system.debug('Let\'s fix this. The VSC is now Mobilized.');
            Return 'Mobilized'; //if LSD is not NULL and the LSD is less then 180 days old, and the VSC is 'Activated', bumps VSC up to 'Mobilized'
        } else if((c.Last_Served_Date__c<>null) && (Date.TODAY().daysBetween(c.Last_Served_Date__c) > 180) && (c.Volunteer_Status_Current__c=='Mobilized')){
            system.debug('Let\'s fix this. The VSC is now Activated.');
            Return 'Activated'; //if LSD is not NULL and the LSD is older than 180 days, returns VSC to 'Activated'
        } else if ((c.Last_Served_Date__c==null) && (Date.TODAY().daysBetween(MaxDate(c))<180) && (c.Volunteer_Status_Current__c=='Activated')){
            system.debug('The LSD was blank, but because the MaxDate was less than 180 days old and the volunteer was already Activated, VSC changed to: Mobilized.'); //bumps VSC up to Mobilized if LSD is within 180 days
            Return 'Mobilized'; //if LSD is  NULL and the MaxDate is less than 180 days old, bumps VSC up to 'Mobilized'
        } else if ((c.Last_Served_date__c==null) && (Date.TODAY().daysBetween(MaxDate(c))>180) && (c.Volunteer_Status_Current__c=='Mobilized')) {
			system.debug('Mobilization status was changed to Activated because MaxDate was more than 180 days old.');
            Return 'Activated'; //if LSD is NULL and the MaxDate is more than 180 days old and VSC is mobilized, returns VSC to 'Activated'
        } else {
            system.debug('No Change was made.');
            Return c.Volunteer_Status_Current__c; //if it is one of the other 8 possibilities, this returns the current VSC value and makes no changes           
        }         
    }    
    public void UpdateContactRecord (string VolunteerId){
        Contact c=[SELECT ID,Last_Served_Date__c,Volunteer_Status_Current__c from Contact Where ID=:VolunteerId];

        date foundDate = MaxDate(c);
        string foundMobStatus = MobilizationStatus(c);
        c.Volunteer_Status_Current__c = foundMobStatus;
        c.Last_Served_Date__c = foundDate;
        update c;
    }
}

 
I have a webform (not web-to-lead) where people may submit an application and recommend others for us to follow up (they provide name and email address). What I want to do is automatically create leads for these recommended folks when the applicant submits the application online. How do I do this? Via a trigger? Or do I do this via trying to direct the applicant to a form linked to the application form?
Here is my code. I can not even save this because the related object is not being located. 
I'm trying to generate a list of related payments for an Opportunity. (not sure if it matters, but our org renamed Opportunities to Income)...what's going on? I keep getting this message: "Error: Invalid field OppPayments for SObject Opportunity"
 
<messaging:emailTemplate 
recipientType="Contact" 
relatedToType="Opportunity"
subject="Payment report for Opportunity: {!relatedTo.name}"
replyTo="n.wylder@ifiusa.org">
    <messaging:htmlEmailBody>
        <html>
            <body>

            <p>Dear {!recipient.name},</p>
            <p>Below is a list of payments related to {!relatedTo.name}.</p>
            <table border="0" >
                <tr>
                    <th>Case Number</th><th>Origin</th>
                    <th>Creator Email</th>
                </tr>
                <apex:repeat var="cx" value="{!relatedTo.OppPayments}">
                <tr>
                    <td><a href = 
                        "https://na77.salesforce.com/{!cx.id}">{!cx.Name}
                    </a></td>
                    <td>{!cx.Designation__c}</td>
                    <td>{!cx.npe01__Payment_Amount__c}</td>
                </tr>
                </apex:repeat> 
            </table>
            <p/>
            <center>
                <apex:outputLink value="http://www.salesforce.com">
                    For more detailed information login to Salesforce.com
                </apex:outputLink>
            </center>
            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

 
I'm trying to complete the Map Your Workflow Criteria to Process Criteria challenge (available here: ) but I keep getting the error below. I have tried this in a couple different DEs (including a new one) and am still getting this error. I have also logged out and logged in a few times to make sure I had a good connection.

Help is greatly appreciated. I'd like to get through this material and get my badge for the module asap. 

trailhead error
My org uses cases to keep track of volunteer participation. I want a field on the contact object that will tell me the last case each volunteer is associated with. This seems simple in my mind, but looks like I'll need to code this in Apex or Soql...but I don't know how to do this. How can this be done? Cases are related to Contacts via look-up fields and while they display neatly in the related lists on the contact object, I need this roll up field for reporting and statistics. 

I have the free version of roll up helper but am already maxed out. I need to be able to code this. Thanks in advance.
I have a process whereby whenever a specific campaign member object is created or a specific case is closed, I'd like the class to run and update 2 fields on the related contact object. But I'm stumped. How do I write the trigger to call this class? It seems like all examples I can can find online are very simple (only involve 1 object), but I have 3.
A. How can I make sure this code runs appropriately?
B. Do I need a trigger on the Campaign Member object, Case Member object or the Contact? Or all 3? 

Here's the class:
 
public class MobilizationCredit {
	//Start when Qualifying Case is edited, closed,        deleted OR
    //Start when Qualifying Campaign Member record is created, edited, deleted
      
    private date MaxDate(Contact c){
    	//Get max Date Begins value related to the Volunteer__c.contactId__r record
        Date casemaxdate2;
        Date campmaxdate2;
        string VolunteerId = c.Id;
        
 	  	List<AggregateResult> CaseMaxDate = [SELECT MAX(Date_Begins__c) FROM Case WHERE Volunteer__c = :VolunteerId AND Qualifies_for_Mobilization__c = TRUE];
		for (AggregateResult ar: CaseMaxDate) {
			system.debug('Max case date found was: '+ ar.get('expr0') + '.');
        	casemaxdate2 = Date.valueOf(ar.get('expr0'));
        }
    
     	//Get max Start Date value of all qualifying campaign member records related to the Contact.Id record
	  	List<AggregateResult> CampMemMaxDate = [SELECT MAX(Start_Date__c) FROM CampaignMember WHERE ContactId = :VolunteerId AND Campaign_Type__c = 'Weekly Attendance'];
		for (AggregateResult ar : CampMemMaxDate) {
 			system.debug('Max campaign member max date found was: '+ ar.get('expr0') + '.');
 			campmaxdate2 = Date.valueOf(ar.get('expr0'));
		}
 		system.debug('Campmaxdate: ' + campmaxdate2);
 		system.debug('Casemaxdate: ' + casemaxdate2);

		if (campmaxdate2 > casemaxdate2) {
    		system.debug('camp is bigger');
        	return campmaxdate2;
		}
		else {
    		system.debug('camp is not bigger');
			return casemaxdate2;
    	}
	}
        
    private string MobilizationStatus (Contact c){
             
         if((c.Last_Served_Date__c<>null) && (Date.TODAY().daysBetween(c.Last_Served_Date__c) < 180) && (c.Volunteer_Status_Current__c =='Activated')) {
            system.debug('Let\'s fix this. The VSC is now Mobilized.');
            Return 'Mobilized'; //if LSD is not NULL and the LSD is less then 180 days old, and the VSC is 'Activated', bumps VSC up to 'Mobilized'
        } else if((c.Last_Served_Date__c<>null) && (Date.TODAY().daysBetween(c.Last_Served_Date__c) > 180) && (c.Volunteer_Status_Current__c=='Mobilized')){
            system.debug('Let\'s fix this. The VSC is now Activated.');
            Return 'Activated'; //if LSD is not NULL and the LSD is older than 180 days, returns VSC to 'Activated'
        } else if ((c.Last_Served_Date__c==null) && (Date.TODAY().daysBetween(MaxDate(c))<180) && (c.Volunteer_Status_Current__c=='Activated')){
            system.debug('The LSD was blank, but because the MaxDate was less than 180 days old and the volunteer was already Activated, VSC changed to: Mobilized.'); //bumps VSC up to Mobilized if LSD is within 180 days
            Return 'Mobilized'; //if LSD is  NULL and the MaxDate is less than 180 days old, bumps VSC up to 'Mobilized'
        } else if ((c.Last_Served_date__c==null) && (Date.TODAY().daysBetween(MaxDate(c))>180) && (c.Volunteer_Status_Current__c=='Mobilized')) {
			system.debug('Mobilization status was changed to Activated because MaxDate was more than 180 days old.');
            Return 'Activated'; //if LSD is NULL and the MaxDate is more than 180 days old and VSC is mobilized, returns VSC to 'Activated'
        } else {
            system.debug('No Change was made.');
            Return c.Volunteer_Status_Current__c; //if it is one of the other 8 possibilities, this returns the current VSC value and makes no changes           
        }         
    }    
    public void UpdateContactRecord (string VolunteerId){
        Contact c=[SELECT ID,Last_Served_Date__c,Volunteer_Status_Current__c from Contact Where ID=:VolunteerId];

        date foundDate = MaxDate(c);
        string foundMobStatus = MobilizationStatus(c);
        c.Volunteer_Status_Current__c = foundMobStatus;
        c.Last_Served_Date__c = foundDate;
        update c;
    }
}

 
I have a webform (not web-to-lead) where people may submit an application and recommend others for us to follow up (they provide name and email address). What I want to do is automatically create leads for these recommended folks when the applicant submits the application online. How do I do this? Via a trigger? Or do I do this via trying to direct the applicant to a form linked to the application form?
Hello,
I tried many times... but receive the same error message : "Challenge Not yet complete... here's what's wrong: 
Formula in custom field 'Account Annual Revenue' is not correct. Check the instructions."
I followed all instructions & get the right results. It's a basic & very simple formula.
Do someone else encounter the same issue ? Any solution ?
I've tried a second time using a brand new Trailhead Playground, and still get the error when checking the challenge:
"Challenge Not yet complete... here's what's wrong: 
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: VRHJDGJD "
I and some other colleagues received this notification via email to all our System Administrators:

"You have one or more certificates in your Salesforce org California College Guidance Initiative [org ID here] that will expire soon. Please review the list below and visit Certificate and Key Management from Setup to make an update.
 
   - SelfSignedCert_20Nov2013_203932, Self-Signed, expires on 11/20/2015. Warning: This certificate will expire in 30 day(s)"

Does anyone have any tips as to how I can check if letting this expire impacts us or not? Has anyone else seen this?
When prompted by the apex data loader I enter my salesforce.com username and password, but this message keeps appearing:

Error logging in to Salesforce. Please check your username and password.

When I login to salesforce.com with the same username and password it works.

Does anyone know why I can't login to the data loader?


Message Edited by Lkc037 on 12-11-2007 11:49 AM
  • December 11, 2007
  • Like
  • 0