• jpb@uhc
  • NEWBIE
  • 50 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 9
    Questions
  • 10
    Replies

We have created a flow that creates an Opportunity and we want the "finishlocation" of the flow, where they end up when they click "Finish", to be the newly created Opportunity. I know that we will have to create a VF page and controller to pass the OpptyID (once created) back to the VF page and set as the finishlocation, but can't figure out how to do it. Any ideas?

Love this app from Force.com labs, but some of our campaigns are quite large and we exceed our view state limit. I can't figure out how to get pagination working and it would be great if this could be added!
Wondered if anyone was usi g the Campaign Call Down Manager from the AppExchange and has implemented pagination with it? The problem is that some of our campaigns are quite large and when we pull them up we get the "view limit size exceeded" error. I was told that pagination would help solve the problem but have no idea how to implement. I have sample code for pagination, but since I'm not a developer I don't know how to implement in to the current Class/VF page.

We currently have a trigger (see below) that creates a record in a custom object called LocationCampaignAssociations for every Campaign Member record created. Essentially the custom object is a junction object to create a relationship between the Campaign and the Account for the Contact that is being added to the Campaign.

 

A new request is that we remove the record from the custom object, in other words the Account to Campaign association, if the there are NO longer any CampaignMembers (Contacts) tied to that Location.

 

Examples:

 

3 Contacts all at the same Account, 1 Contact removed from the Campaign, do not remove the record from the custom object...keeping the Account to Campaign association.

 

3 Contacts all at the same Account, all 3 Contacts removed from the Campaign, remove the record from the custom object since the Account should no longer be associated with the campaign either.

 

Any ideas on how to modify our trigger to do so?

 

trigger CreateLocCampMembers on CampaignMember (after insert) {

List<LocationCampaignAssociations__c> createLoc = new List <LocationCampaignAssociations__c> {};

for (CampaignMember cm : trigger.new) {
createLoc.add(new LocationCampaignAssociations__c (Campaign__c = cm.CampaignId, Location__c = cm.Location_ID__c));
}
try {
insert createLoc;
}
catch (Exception Ex)
{
system.debug(Ex);
}
}

We'd like to be able to replace the standard screen that pops up when adding campaigns to contact records with a custom screen that will allow our users to add mutliple campaigns to a contact record at a time. Basically we'd like a list of all Active Campaigns with a checkbox next to the Campaign Name and then have a Campaign Member record created for the Contact for each campaign selected. Any ideas?

 

We have matching picklist fields on both the Opportunity and OpportunityLineItem. I need to come up with a trigger that updates the Opportunity everytime the field is changed on the OpportunityLineItem. I have written basic triggers in the past, but the cross object stuff has me perplexed. Any help with some code to get me started would be much appreciated. Here are some details:

 

Field Name: Fee_Schedule__c (same on both objects)

 

I know that there could be multiple line items, but all line MUST have the same value in the Fee_Schedule__c field, so can we just use a select with the "limit 1" approach to get the value from the OpportunityLineItem records associated with the Opportunity?

  • September 22, 2011
  • Like
  • 0

We have created a trigger (or attempted to) on Opportunity that will in effect go out and look at the Account associated with the Oppty and then look at the Partners associated with that Account. We are then attempting to populate a custom text field  (special_instructions__c) on the Opportunity with the addresses of ALL Partners (currently only pulling BillingStreet). However, what we are currently getting is just the BillingStreet of just one of the Partners. I am new to Apex so wonder if I am missing some sort of loop method, any help is greatly appreciated. Here is the trigger:

 

trigger SpecialInstructions on Opportunity (before insert, before update) {
    
    //Create Map references. Trigger maps to Opportunity, Opportunity maps to Account, Account maps to Partner.
    Map<Id, Id> OpportunityToAccountMap = new Map<Id, Id>();
    Map<Id, Id> AcctToPartnerMap = new Map<Id, Id>();
    Map<Id, Account> PartnerResponseMap = new Map<Id, Account>();

    
    //Map the Account Ids by querying the AccountID to OpportunityId (Trigger.New)
    for(Opportunity oppty : [SELECT Id, AccountID FROM Opportunity WHERE ID in: trigger.new]){
        OpportunityToAccountMap.put(oppty.id, oppty.AccountId);
    }
    
    //Map the Partner Ids by querying the AccountFromId to the AccountToID from the map above
    for(Partner partner : [SELECT Id, AccountToId, AccountFromId FROM Partner WHERE AccountFromId in: OpportunityToAccountMap.values()]){
        AcctToPartnerMap.put(partner.AccountFromId, partner.AccountToId);
    } 
    
    //Map the needed fields from AccountToID by querying the Account from the map above
    for(Account part : [SELECT Id, BillingStreet FROM Account WHERE ID in: AcctToPartnerMap.values()]){
        PartnerResponseMap.put(part.ID, part);
    }
    
    for(Opportunity o : trigger.new){
        
        //Retreived mapped records specific to the current Opportunity record
        
        //Get account id from OppportunityToAccountMap using current opportunity id
        Id acctid = OpportunityToAccountMap.get(o.Id);
        //Get accountid for partners from AcctToPartnerMap using acctid reference above
        Id partnerid = AcctToPartnerMap.get(acctid);
        
        //Avoid "System.NullPointerException: Attempt to de-reference a null object" error by
        //first verifying that your query produced results
        if(PartnerResponseMap.containsKey(partnerid)) {
            
            //If query produced results, then proceed to mapping the PartnerResponse using the AccountToID
            //refrence above
            Account PartnerResponse = PartnerResponseMap.get(partnerid);
        
            //Update Opportunity using values from PartnerResponse (Opportunity-->Account-->Partner-->PartnerResponse-->Opportunity)
            if(o.Special_Instructions__c == null){
                o.Special_Instructions__c = o.Special_Instructions__c + PartnerResponse.BillingStreet;  
            }
        }
    } 
}

 

  • September 13, 2011
  • Like
  • 0

I have a VF page that we created that looks like this:

 

<apex:page standardController="Lead" extensions="TeamTrackFlag" sidebar="true">
  <apex:sectionHeader title="Edit Lead Record:"
                      subtitle="{!lead.name}"/>
  <apex:form >
    <apex:pageBlock title="Create TeamTrack Flag" id="thePageBlock"
                    mode="edit">
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>
      <FONT COLOR="RED"><b>IMPORTANT: </b> Should a TeamTrack be created for this Opportunity?</FONT>
              <br /><br />
        <table>
        <td width="200" align="center"><b>Create TeamTrack?</b></td>
        <td width="100" align="left"><apex:inputField value="{!Lead.Create_TeamTrack__c}" id="TTFlag"/></td>
        <td width="200" align="left"> Checked = YES<br />Unchecked = NO<br /></td>
        </table>
        <br />
        <br />
        <B>PLEASE NOTE:</B>
        <BR />
        The system default is 'YES'. Your answer should only be 'NO' if you were notified by Recruitment Support about a TeamTrack that was manually created on your behalf.
        <apex:inputField value="{!Lead.ID}" rendered="false" />
        <apex:inputField value="{!Lead.Name}" rendered="false" />
        <apex:inputField value="{!Lead.Company}" rendered="false" />
    </apex:pageBlock>
  </apex:form> 
</apex:page>

The class is:

 

public class TeamTrackFlag{
    ApexPages.StandardController controller;
    Lead cntr;
        public TeamTrackFlag(ApexPages.StandardController con){
                controller = con;
                cntr= (Lead)controller.getRecord();
                     }
                                      
public PageReference save()
 {        controller.save();
         PageReference redirecturl = new PageReference('/lead/leadconvert.jsp?retURL=/' + cntr.Id + '&id=' + cntr.Id + '&noopptt=' + cntr.Company + '-' + cntr.Name);
         redirecturl.setRedirect(true);
         return redirecturl;
             }}

 

I do I get test coverage for this page so that we can deploy it production from our sandbox?

Ok, here is the scenario...we want to replace our standard Convert button with a custom button that will first call a VF page that has a single field that will be modified on the Lead. The VF page uses the standard Lead Controller and standard Save() method. We want to be able to then direct the user to the Leadconvert.jsp page after save. We created a custom Save() method using an extension class and the redirect works but the problem is I don't know how to pass parameters to populate the URL correctly. Here is the VF page:

<apex:page standardController="Lead" extensions="TeamTrackFlag" sidebar="false">
  <apex:sectionHeader title="Edit Create Team Track Flag"
                      subtitle="{!lead.name}"/>
  <apex:form >
    <apex:pageBlock title="Edit Lead" id="thePageBlock"
                    mode="edit">
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>
        <apex:inputField value="{!Lead.Create_TeamTrack__c}" 
              required="true"/>
        <apex:inputField value="{!Lead.ID}" rendered="false" />
    </apex:pageBlock>
  </apex:form> 
</apex:page>

Here is the class:

public class TeamTrackFlag{
    ApexPages.StandardController controller;
        public TeamTrackFlag(ApexPages.StandardController con){
                controller = con;
                     }
                                     
public PageReference save()
 {        controller.save();
         PageReference redirecturl = new PageReference('/lead/leadconvert.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}&noopptt={!Lead.Company}-{!Lead.Name}')
         return redirecturl;
             }}

This is the error I get:

Unable to Access Page
Invalid parameter value "{!Lead.Id}" for parameter "id".

Error: The value of the parameter specified above contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and re-submit. If the error still persists, please report it to our Customer Support team and provide the URL of the page you were requesting as well as any other related information.

 
And the URL looks like this:

https://cs3.salesforce.com/lead/leadconvert.jsp?id=%7B%21Lead.Id%7D&noopptt=%7B%21Lead.Company%7D-%7B%21Lead.Name%7D&retURL=%2F%7B%21Lead.Id%7D

Help! I'm an analyst who doesn't do much coding, i'm hoping its a simple fix.

We have created a flow that creates an Opportunity and we want the "finishlocation" of the flow, where they end up when they click "Finish", to be the newly created Opportunity. I know that we will have to create a VF page and controller to pass the OpptyID (once created) back to the VF page and set as the finishlocation, but can't figure out how to do it. Any ideas?

We have created a flow that creates an Opportunity and we want the "finishlocation" of the flow, where they end up when they click "Finish", to be the newly created Opportunity. I know that we will have to create a VF page and controller to pass the OpptyID (once created) back to the VF page and set as the finishlocation, but can't figure out how to do it. Any ideas?

We currently have a trigger (see below) that creates a record in a custom object called LocationCampaignAssociations for every Campaign Member record created. Essentially the custom object is a junction object to create a relationship between the Campaign and the Account for the Contact that is being added to the Campaign.

 

A new request is that we remove the record from the custom object, in other words the Account to Campaign association, if the there are NO longer any CampaignMembers (Contacts) tied to that Location.

 

Examples:

 

3 Contacts all at the same Account, 1 Contact removed from the Campaign, do not remove the record from the custom object...keeping the Account to Campaign association.

 

3 Contacts all at the same Account, all 3 Contacts removed from the Campaign, remove the record from the custom object since the Account should no longer be associated with the campaign either.

 

Any ideas on how to modify our trigger to do so?

 

trigger CreateLocCampMembers on CampaignMember (after insert) {

List<LocationCampaignAssociations__c> createLoc = new List <LocationCampaignAssociations__c> {};

for (CampaignMember cm : trigger.new) {
createLoc.add(new LocationCampaignAssociations__c (Campaign__c = cm.CampaignId, Location__c = cm.Location_ID__c));
}
try {
insert createLoc;
}
catch (Exception Ex)
{
system.debug(Ex);
}
}

We'd like to be able to replace the standard screen that pops up when adding campaigns to contact records with a custom screen that will allow our users to add mutliple campaigns to a contact record at a time. Basically we'd like a list of all Active Campaigns with a checkbox next to the Campaign Name and then have a Campaign Member record created for the Contact for each campaign selected. Any ideas?

 

Hey all,

 

Taking my first plunge into VisualFlow. I've bashed together a lil proof of concept and it's all working fine bar one thing.

 

What I'd like is that when the flow finishes, the user is taken to another VisualForce page. This Visualforce page is passed a parameter that has the value of a variable in the flow. This is how I'm currently trying to do it:

 

In the VF page:

<flow:interview name="Test_1" interview="{!myflow}" finishLocation="{!EndPage}"/>

 

In the controller for this page:

    public PageReference getEndPage() {
        PageReference pageRef = Page.EndOrder;
         String oid =myflow.vOrder;
         pageRef.getParameters().put('order', oid);   
            return pageRef;
    }

 

where vOrder is a variable set in the flow.

 

But when I try and load the VF page I get the following error:

System.FlowException: Interview not started

 

How can I get the variable value that I can pass as a parameter to the follow page?

 

Thanks

 

 

I'm trying to modify the code in the awesome Campaign Membership Manager app in order to add a button that updates the status of all selected members to a specific option (which I want to hard code).

 

The existing button allows the user to remove the selected members.

 

I, uh, added the button. But as far as developing the functionality, I'm a dum dum.

 

 

This is my button: 

<apex:commandButton value="Update to Hand Deliver" action="{!updateSelectedStatusMail}" rendered="{!NOT(ISNULL(CampaignMembers))}" />

 

And here's the code:

 

/**
*  CMM Campaign Membership Manager
*  Copyright (c) 2009, Marcel Will, Sales Engineering, Salesforce.com Inc.
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
*  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*  Neither the name of the salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
*  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
*  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
*  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public with sharing class cmmCampaignMembershipManagerController{
    
    private List<myCampaignMember>  campaignMemberList { get; set; }   
    private List<myCampaignMember>  CampaignMembers;            
    private List<myCampaignMember>  pageCampaignMemberList;          
    private List<CampaignMember>    deleteCampaignMembers;      
    private Map<Id, CampaignMember> selectedCampaignMembersMap;
    
    private String  selectedCampaign;
    private String  CampaignDescription;
    private String  userName;
    private String  userLanguage;
    private Integer pageNumber;
    private Integer pageSize;
    private integer totalPageNumber;
    private Integer selectedRows; 
    
    public Boolean selectAllCheckbox        { get; set; }
    public String  messageTitle             { get; set; }
    public String  messageDetail            { get; set; }
    public String  messageSeverity          { get; set; }
    transient public Boolean messageShow    { get; set; }
    
    /**
    * constructor
    */
    public cmmCampaignMembershipManagerController(){
        
        this.CampaignMembers            = new List<myCampaignMember>{};
        this.pageCampaignMemberList     = new List<myCampaignMember>{}; 
        this.deleteCampaignMembers      = new List<CampaignMember>();
        this.selectedCampaignMembersMap = new Map<Id, CampaignMember>();
        
        this.userName       = UserInfo.getUserId();
        this.userLanguage   = UserInfo.getLanguage();
        
        this.pageNumber         = 0;
        this.totalPageNumber    = 0;
        this.selectedRows       = 0;
        this.pageSize           = 10;
    }
    
    /**
    * Getter method to retrieve the user language
    * @return userLanguage
    */
    public String getUserLanguage(){
        return userLanguage.Substring( 0, 2 );
    }
    
    /**
    * Getter Method to retrieve the current page number
    * @return pageNumber
    */
    public Integer getPageNumber(){
        return pageNumber;
    }
    
    /**
    * Getter method to retrieve the page size
    * @return pageSize
    */
    public Integer getPageSize(){
        return pageSize;
    }
    
    /**
    * Getter method to enable previous button
    * @return Boolean
    */
    public Boolean getPreviousButtonEnabled(){
        return !( pageNumber > 1 );
    }
    
    /**
    * Getter method to enable Next button
    * @return Boolean
    */
    public Boolean getNextButtonEnabled(){
        if( campaignMemberList == null ){
            return true;
        }else{
            return ( ( pageNumber * pageSize ) >= campaignMemberList.size() );
        }
    }
    
    /**
    * Getter method to retrieve total page number
    * @return totalPageNumber
    */
    public Integer getTotalPageNumber(){
        
        totalPageNumber = campaignMemberList.size() / pageSize;
        Integer mod     = campaignMemberList.size() - ( totalPageNumber * pageSize );
        
        if( mod > 0 ){
            totalPageNumber++;
        }
        
        return totalPageNumber;
    }
    
    /**
    * Getter method to retrieve Campaign member list
    * @return List<myCampaignMember>
    */
    public List<myCampaignMember> getCampaignMembers(){
        
        if( pageCampaignMemberList.Size() > 0 ){
            return pageCampaignMemberList;
        }else{
            return null;
        }
    }   
    
    /**
    * Getter to retrieve the number of selected rows
    * @return selectedRows
    */
    public Integer getSelectedRows(){
        return this.selectedRows;
    }
    
    /**
    * Recalculate Number of selected items in Grid
    * @return null
    */
    public Integer recalculateSelected(){
        selectedRows = selectedCampaignMembersMap.size();
        return null;
    }
    
    /**
    * Bind data to paged list for displaying on VF page
    * @param newPageIndex
    */
    private void BindData( Integer newPageIndex ){
        
        try{

            Transient Integer counter   = 0;
            Transient Integer min       = 0;
            Transient Integer max       = 0;
            
            if( newPageIndex > PageNumber ){
                min = pageNumber * pageSize;
                max = newPageIndex * pageSize;
            }else{
                max = newPageIndex * pageSize;
                min = max - pageSize;
            }
            
            CampaignMembers.clear();
            pageCampaignMemberList.clear();
            
            for( myCampaignMember cm: CampaignMemberList ){
                counter++;
                if( counter > min && counter <= max ){
                    pageCampaignMemberList.add( cm );
                }
            }
            pageNumber = newPageIndex;
            if( pageCampaignMemberList == null || pageCampaignMemberList.size() <= 0 ){
                messageTitle        = 'CMM_No_data';
                messageDetail       = 'CMM_No_data_available';
                messageSeverity     = 'info';
                messageShow         = true;
            }
        }catch( Exception ex ){
            messageTitle    = ex.getMessage();
            messageDetail   = ex.getMessage();
            messageSeverity = 'fatal';
            messageShow     = true;
        }
    }
    
    /**
    * Search for all Campaign Members of a selected campaign and put them into a list of <myCamapaignMember>
    * @return PageReference
    */
    public PageReference DoSearch(){
        
        this.campaignMemberList = new List<myCampaignMember>();
        this.pageCampaignMemberList.clear();
        
        for( CampaignMember cm: [ Select Id, LeadId, Lead.Company, Lead.Email, Lead.FirstName, Lead.LastName, Lead.OwnerId, Lead.City, ContactId, 
                                    Contact.Account.Name, Contact.Email, Contact.FirstName, Contact.LastName, Contact.OwnerId, Contact.MailingCity, Status 
                                    from CampaignMember 
                                    WHERE CampaignId =: selectedCampaign AND ( Contact.OwnerID =: userName OR Lead.OwnerID =: userName ) 
                                    ORDER BY Lead.LastName, Contact.LastName ] ){
                                        
            this.campaignMemberList.add( new MyCampaignMember( cm ) );
        }
        
        this.BindData( 1 );
        this.selectedRows = 0;
        
        return null;
    }   
    
    /**
    * Action method on next button
    * @return PageReference
    */
    public PageReference nextBtnClick(){
        
        clearMessage();
        updateSelectedList();       
        BindData( pageNumber + 1 );
        
        return null;
    }
    
    /**
    * Action method on previous button
    * @return PageReference
    */
    public PageReference previousBtnClick(){
        
        clearMessage();
        updateSelectedList();       
        BindData( pageNumber -1 );
        
        return null;
    }
    
    /**
    * This method clears the message on the visual force page.
    * @return PageReference
    */
    public pageReference clearMessage(){
        this.messageShow = false;
        return null;
    }
    
    /**
    * Get Campaign Description for selected Campaign to show on VF page     
    * @return CampaignDescription
    */                
    public String getCampaignDescription(){
        
        CampaignDescription = 'CMM_Select_Campaign';
        
        if( selectedCampaign != null ){
            Campaign myCampaign = [ select id, description from Campaign where id =: selectedCampaign ];
            CampaignDescription = myCampaign.Description;
        }
        
        return CampaignDescription;
    }

    /**
    * Update list of selected records for processing 
    */ 
    public void updateSelectedList(){
        List<myCampaignMember> members = this.getCampaignMembers();
        if( members != null ){
            for( myCampaignMember mcMember : getCampaignMembers() ){
                if( mcMember.selected == true ){
                    selectedCampaignMembersMap.put( mcMember.campmem.id, mcMember.campmem );
                }else{
                    selectedCampaignMembersMap.remove( mcMember.campmem.id );
                }
            }
            
            selectedRows = selectedCampaignMembersMap.size();
        }
    }

    /**
    * Delete selected campaign members
    * @return PageReference
    */
    public PageReference updateSelectedStatusMail(){
        
        updateSelectedList();
        deleteCampaignMembers.clear();
        deleteCampaignMembers = selectedCampaignMembersMap.values();
        
        try{
            if( deleteCampaignMembers.size() > 0 ){
                delete deleteCampaignMembers;
                messageTitle    = 'CMM_Successful';
                messageDetail   = deleteCampaignMembers.size() + ' ' + 'CMM_Successfully_removed';
                messageSeverity = 'confirm';
                messageShow = true;
            }
            else{
                messageTitle    = 'CMM_Error';
                messageDetail   = 'Please select at least one member';
                messageSeverity = 'fatal';
                messageShow = true;
            }
        }catch( DmlException e ){
            messageTitle    = 'CMM_Error';
            messageDetail   = e.getMessage();
            messageSeverity = 'fatal';
        }finally{
            messageShow = true;
        }
        
        campaignMemberList.clear();
        selectedCampaignMembersMap.clear();
        selectedRows = 0;
        DoSearch(); 
        
        return null;
    }
    
    
        /**
    * Update Status of Campaign Members to 'Hand Deliver'
    * Customization added October 18, 2011
    * @return PageReference
    */
    public PageReference processSelected(){
        
        updateSelectedList();

        
        campaignMemberList.clear();
        selectedCampaignMembersMap.clear();
        selectedRows = 0;
        DoSearch(); 
        
        return null;
    }

    /**
    * Get list of all Campaigns with Status equals to "Planned" and with Active equals to "true"
    * @return List<SelectOption>
    */
    public List<SelectOption> getCampaigns(){
        
        List<SelectOption> options  = new List<SelectOption>();
        List<Campaign> cList        = new List<Campaign>();
        
        try {
            cList = [ SELECT Id, Name, Description FROM Campaign WHERE Status = 'Planned' AND IsActive = true ORDER BY Name ];
            for( Campaign c: cList ){
                options.add( new SelectOption( c.Id, c.Name ) );
            }
            
            if( cList == null || cList.size() <= 0 ){
                // Show Info Message that no records have been found
                messageTitle    = 'CMM_No_data';
                messageDetail   = 'CMM_No_Campaign';
                messageSeverity = 'info';
                messageShow     = true;
                
                return null;    
            }else{
                return options;
            }        
        }catch( Exception ex ){
           // Show error Message with severity FATAL
           // messageTitle  = 'CMM_Error';
           // messageDetail     = ex.getMessage();
           //messageSeverity = 'fatal';
           //messageShow    = true;
           return null;
        } 
    }
    
    /**
    * Getter method to retreieve the selected campaing
    * @return selectedCampaign
    */
    public String getSelectedCampaign(){
        return this.selectedCampaign;
    }
    
    /**
    * Setter method to set te selected Campaign
    * @param selectedCampaign
    */
    public void setSelectedCampaign( String selectedCampaign ){
        this.selectedCampaign = selectedCampaign;
    }     
    
    /**
    * Inner Class 
    * myCampaignMember to extend CampaignMember object with selected field (checkbox, boolean)
    */
    public class myCampaignMember{
        
        public CampaignMember campmem   { get; set; }
        public Boolean selected         { get; set; }
        
        /**
        * Constructor
        */
        public myCampaignMember( CampaignMember cm ){
            this.campmem    = cm;
            this.selected   = false;
        }
    } 
}

 

We have matching picklist fields on both the Opportunity and OpportunityLineItem. I need to come up with a trigger that updates the Opportunity everytime the field is changed on the OpportunityLineItem. I have written basic triggers in the past, but the cross object stuff has me perplexed. Any help with some code to get me started would be much appreciated. Here are some details:

 

Field Name: Fee_Schedule__c (same on both objects)

 

I know that there could be multiple line items, but all line MUST have the same value in the Fee_Schedule__c field, so can we just use a select with the "limit 1" approach to get the value from the OpportunityLineItem records associated with the Opportunity?

  • September 22, 2011
  • Like
  • 0

We have created a trigger (or attempted to) on Opportunity that will in effect go out and look at the Account associated with the Oppty and then look at the Partners associated with that Account. We are then attempting to populate a custom text field  (special_instructions__c) on the Opportunity with the addresses of ALL Partners (currently only pulling BillingStreet). However, what we are currently getting is just the BillingStreet of just one of the Partners. I am new to Apex so wonder if I am missing some sort of loop method, any help is greatly appreciated. Here is the trigger:

 

trigger SpecialInstructions on Opportunity (before insert, before update) {
    
    //Create Map references. Trigger maps to Opportunity, Opportunity maps to Account, Account maps to Partner.
    Map<Id, Id> OpportunityToAccountMap = new Map<Id, Id>();
    Map<Id, Id> AcctToPartnerMap = new Map<Id, Id>();
    Map<Id, Account> PartnerResponseMap = new Map<Id, Account>();

    
    //Map the Account Ids by querying the AccountID to OpportunityId (Trigger.New)
    for(Opportunity oppty : [SELECT Id, AccountID FROM Opportunity WHERE ID in: trigger.new]){
        OpportunityToAccountMap.put(oppty.id, oppty.AccountId);
    }
    
    //Map the Partner Ids by querying the AccountFromId to the AccountToID from the map above
    for(Partner partner : [SELECT Id, AccountToId, AccountFromId FROM Partner WHERE AccountFromId in: OpportunityToAccountMap.values()]){
        AcctToPartnerMap.put(partner.AccountFromId, partner.AccountToId);
    } 
    
    //Map the needed fields from AccountToID by querying the Account from the map above
    for(Account part : [SELECT Id, BillingStreet FROM Account WHERE ID in: AcctToPartnerMap.values()]){
        PartnerResponseMap.put(part.ID, part);
    }
    
    for(Opportunity o : trigger.new){
        
        //Retreived mapped records specific to the current Opportunity record
        
        //Get account id from OppportunityToAccountMap using current opportunity id
        Id acctid = OpportunityToAccountMap.get(o.Id);
        //Get accountid for partners from AcctToPartnerMap using acctid reference above
        Id partnerid = AcctToPartnerMap.get(acctid);
        
        //Avoid "System.NullPointerException: Attempt to de-reference a null object" error by
        //first verifying that your query produced results
        if(PartnerResponseMap.containsKey(partnerid)) {
            
            //If query produced results, then proceed to mapping the PartnerResponse using the AccountToID
            //refrence above
            Account PartnerResponse = PartnerResponseMap.get(partnerid);
        
            //Update Opportunity using values from PartnerResponse (Opportunity-->Account-->Partner-->PartnerResponse-->Opportunity)
            if(o.Special_Instructions__c == null){
                o.Special_Instructions__c = o.Special_Instructions__c + PartnerResponse.BillingStreet;  
            }
        }
    } 
}

 

  • September 13, 2011
  • Like
  • 0

Campaign Member from Checkbox Trigger


Use case:

We have situations where we manage what communications someone gets based on a checkbox on their record in salesforce. Each checkbox will correspond to a campaign in Salesforce. When the value of that checkbox on the record is edited, we would like the status of that checkbox to create/delete a corresponding Campaign Member. As this is something we have multiple uses for, we would like it to be done in a way that we can tweak to re-purpose as needed.

Desired design:

- The trigger should be set up to allow us to specify one or more custom checkbox fields that trigger campaign member creation. For each checkbox we will be able to specify the corresponding campaign.
- The campaign that the campaign member will be created on should be easily specifiable in the trigger code (for example, by UID).
- The campaign member should be created with the default status
- The code delivered should include (a) a version for contacts and (b) a version that will work for leads.

Acceptance criteria:


- The trigger will add one (and only one) campaign member per contact record that is edited to check a checkbox field
- The trigger will remove only the corresponding campaign member for a contact record where the checkbox is unchecked and saved
- Needs to have test coverage required by salesforce for deploying to production
- The code should have comments where reasonable to help in understanding and reusing
- The trigger needs to be able to be extended to manage multiple checkbox-to-campaign pairings in one trigger (ie 3 checkboxes that correspond to 3 different campaigns)

Hi,

If I am running a campaign to target a number of Accounts and I would like to show on those accounts that they have been targeted by the campaign, is there an easy way to do this?

I have ran a report to obtain the accounts that are going to be targeted and exported it to Excel , but when I create a new campaign I cannot find a way to select which accounts it is going to be linked with.

Thanks in advance for any help provided.

I'm kinda new to apex, and im fairly stranded. Trying to basically create a trigger that on the completion of a log a call task, reads a particular field, and updates status based on it. More specifically, I'm not sure if what i want to do is possible.

 

To update  the lead shouldn't be too difficult. I would just run a SOQL on the lead Id and update the status field. I do this all day long from the API. The problem I'm really having is how to get information out of the current task. That is, how do i know what lead and what the contents of the tasks field are. 

 

Any help or direction would be much appreciated!

  • November 30, 2009
  • Like
  • 0
After setting up Duplicate Management, did a test from a standard edit page which worked perfectly displaying error message as well as duplicate records but when tested from Visualforce page only error message "You're creating a duplicate record. We recommend you use an existing record instead." was displayed but no duplicate records. Did anyone face the same issue or is it a limitation ?