• Liz Malman
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 17
    Replies

I have an Event object and an Opportunity object. On an Event record, there is a field to lookup an opportunity that it is related to, called Opportunity, and there is a lookup field called Client Services. I'm trying to write a trigger that when the Opportunity field is filled out and the Client Services field is blank, the event will update with the related opportunity's Client Services field. 

Here is my code:
trigger EventClientServiceTrigger on Events__c (after update, after insert) {
    list<Events__c> EventsToUpdate = new list<Events__c>();
    
    for (Events__c e:Trigger.new){
        if (e.Client_Services__c == null && e.Opportunity__c != null && !checkRecursive.SetOfIDs.contains(e.Id)){
                Opportunity opp = new Opportunity();
                opp.Id = e.Opportunity__c;
                e.Client_Services__c = opp.Engineer__c;
                EventsToUpdate.add(e);
        }
    }    
    if(EventsToUpdate.size() > 0){
        update EventsToUpdate;
    }    

I get an error saying the "Record is read-only". Does anyone know why this might be?

Thanks,

Liz

Hi all,

I have two object: Events and Opportunities. What I would like to have happen is the following:

When the field Engineer__c is filled out on an Opportunity, I would like for the related Events field Client_Services__c field to be filled out with the same content. 

I know this will most likey be done with an Apex Trigger but I need some help with the code. In the past I have successfully done something similar but they were both the same object type. It seems the two different object types make it more complicated. 

Any insight would be appreciated.

Thanks,
Liz
Hi all,

I have a visualforce email template related to one object, Events. Related to Events is an object called Teams. I'm trying to get a field from the Teams object into the template. How do I call this field?

Code:
<messaging:emailTemplate subject="PREFERRED TRAVEL NEEDED || {!relatedTo.Events__r.Name}" recipientType="User" relatedToType="Teams__c">
<messaging:htmlEmailBody >

<apex:outputLink value="http://smt.force.com/?#/details/{!relatedTo.Events__r.Id}">Submit Travel for {!relatedTo.Engineer__r.Name}</apex:outputLink> <br/> <br/>

<b>Event: </b>{!relatedTo.Events__r.Name} <br/>
<b>Account: </b>{!relatedTo.Events__r.accountLookup__c}<br/>

I'd like to call this other field right below Account.
Hello all,

I'd like some help on how to change the formatting of one of my merge fields in my visualforce email template. The field I am merging is a text field but when the email is created, the formatting from the field does not carry over. 

For example...

Text in the Field looks like this: 
This is a test.
Please ignore this.

Text in the Email looks like this:
This is a test. Please ignore this. 

Does anyone have any idea how to carry over the format from the text field?

Thanks,
Liz
Hi all,

So in my org, we have an events object and a team object. The team object is related to the events object. In a visualforce page that create an events calender displaying all of our events, we have a few filters at the top for sport and other various fields. What I would like to do is create a filter that uses a field from the team object to filter the event. 

My code looks like this when I reference an event field:
&& ['all', myEvent.type].indexOf($('#type_selector').val()) >= 0 

Is there a way for me to grab or reference a field from the team object?

Any help would be appreciated!
Liz

 
Hi Salesforce Community,

I created a test class that I believe should cover the trigger I created 100% but I'm only getting 64% coverage. I know I don't need 100% coverage to bring this trigger and class into my production but I'd like to figure this out.

Here is my code for my trigger:
trigger Renewal_PSM on Opportunity (after insert, after update) {

    Set<Id> oppIds = new Set<Id>();
    Map<Id,Id> oppIds2 = new Map<Id,Id>();
    List<Opportunity> opptoUpdate = new List<Opportunity>();
    
    for(Opportunity o : Trigger.new){
         if(o.Previous_Renewal_Opportunity__c != null)
              oppIds.add(o.Id);
              oppIds2.put(o.Previous_Renewal_Opportunity__c,o.Id);
    }
    
    for(Opportunity opp2: [Select Amount from Opportunity where Id in: oppIds2.keySet()])
    {
        if(opp2.Amount !=null && !checkRecursive.SetOfIDs.contains(opp2.Id))
        {
          Opportunity o1= new Opportunity();
          o1.id=oppIds2.get(opp2.Id);
          checkRecursive.SetofIDs.add(opp2.Id);
          o1.Previous_Renewal_Product_Sum_Amount__c =opp2.Amount;
          opptoUpdate.add(o1);
        }
    
    }

if(opptoUpdate.size()>0)
update opptoUpdate;
}

Here is the code for my test class:
@isTest
private class Test_Renewal_Product_Sum_Amount{
  
         
  static testMethod void test_OpportunityTrigger2(){
  
   Account account_Obj = new Account(Name = 'Name123');
    Insert account_Obj; 

   
    Opportunity opp = new opportunity(Name = 'Name321',Description='Testing', StageName = 'Prospecting',AccountId=account_Obj.Id, CloseDate = Date.today());
  Insert opp;
      
   
   
    Opportunity opportunity_Obj = new Opportunity(IsPrivate = false, Description='Testing', Name = 'Name198',AccountId=account_Obj.Id,StageName = 'Proposal', previous_Renewal_Opportunity__c=opp.id, CloseDate = Date.today());
    Insert opportunity_Obj;
      
      Opportunity opportunity_Obj2 = new Opportunity(IsPrivate = false, Description='Testing', Name = 'Name196',AccountId=account_Obj.Id,Amount=123456, StageName = 'Discovery', CloseDate = Date.today());
      
      Insert opportunity_Obj2;
      
      opp.previous_Renewal_Opportunity__c= opportunity_Obj2.Id;
      update opp;
  
  }
}

Thanks,
Liz
I am trying to auto populate a lookup field using an apex trigger and could use some help. My case only uses opportunity objects. On each opportunity there are 2 lookup fields. Example: Once lookup_field_A on Opp1 gets filled with Opp2, I would like to fill Opp2's lookup_field_B with Opp1. 

I've started writing this code out but I'm unsure how to grab Opp2 from lookup_field_A and then set lookup_field_B to be Opp1.

Anyone have any ideas? Any insight would be helpful.
Hi all,

I'm looking to create an "Add" Button on my opportunities related list. I understand that the button type must be "List Button" and how to add the new button to the page layout. I am lost when it comes to writing the code for this "Add" button. Has anyone created a similar button or could someone point to a good place to start? 

Thanks,
Liz 
Hi all,

I have two object: Events and Opportunities. What I would like to have happen is the following:

When the field Engineer__c is filled out on an Opportunity, I would like for the related Events field Client_Services__c field to be filled out with the same content. 

I know this will most likey be done with an Apex Trigger but I need some help with the code. In the past I have successfully done something similar but they were both the same object type. It seems the two different object types make it more complicated. 

Any insight would be appreciated.

Thanks,
Liz
Hello all,

I'd like some help on how to change the formatting of one of my merge fields in my visualforce email template. The field I am merging is a text field but when the email is created, the formatting from the field does not carry over. 

For example...

Text in the Field looks like this: 
This is a test.
Please ignore this.

Text in the Email looks like this:
This is a test. Please ignore this. 

Does anyone have any idea how to carry over the format from the text field?

Thanks,
Liz
Hi Salesforce Community,

I created a test class that I believe should cover the trigger I created 100% but I'm only getting 64% coverage. I know I don't need 100% coverage to bring this trigger and class into my production but I'd like to figure this out.

Here is my code for my trigger:
trigger Renewal_PSM on Opportunity (after insert, after update) {

    Set<Id> oppIds = new Set<Id>();
    Map<Id,Id> oppIds2 = new Map<Id,Id>();
    List<Opportunity> opptoUpdate = new List<Opportunity>();
    
    for(Opportunity o : Trigger.new){
         if(o.Previous_Renewal_Opportunity__c != null)
              oppIds.add(o.Id);
              oppIds2.put(o.Previous_Renewal_Opportunity__c,o.Id);
    }
    
    for(Opportunity opp2: [Select Amount from Opportunity where Id in: oppIds2.keySet()])
    {
        if(opp2.Amount !=null && !checkRecursive.SetOfIDs.contains(opp2.Id))
        {
          Opportunity o1= new Opportunity();
          o1.id=oppIds2.get(opp2.Id);
          checkRecursive.SetofIDs.add(opp2.Id);
          o1.Previous_Renewal_Product_Sum_Amount__c =opp2.Amount;
          opptoUpdate.add(o1);
        }
    
    }

if(opptoUpdate.size()>0)
update opptoUpdate;
}

Here is the code for my test class:
@isTest
private class Test_Renewal_Product_Sum_Amount{
  
         
  static testMethod void test_OpportunityTrigger2(){
  
   Account account_Obj = new Account(Name = 'Name123');
    Insert account_Obj; 

   
    Opportunity opp = new opportunity(Name = 'Name321',Description='Testing', StageName = 'Prospecting',AccountId=account_Obj.Id, CloseDate = Date.today());
  Insert opp;
      
   
   
    Opportunity opportunity_Obj = new Opportunity(IsPrivate = false, Description='Testing', Name = 'Name198',AccountId=account_Obj.Id,StageName = 'Proposal', previous_Renewal_Opportunity__c=opp.id, CloseDate = Date.today());
    Insert opportunity_Obj;
      
      Opportunity opportunity_Obj2 = new Opportunity(IsPrivate = false, Description='Testing', Name = 'Name196',AccountId=account_Obj.Id,Amount=123456, StageName = 'Discovery', CloseDate = Date.today());
      
      Insert opportunity_Obj2;
      
      opp.previous_Renewal_Opportunity__c= opportunity_Obj2.Id;
      update opp;
  
  }
}

Thanks,
Liz
I am trying to auto populate a lookup field using an apex trigger and could use some help. My case only uses opportunity objects. On each opportunity there are 2 lookup fields. Example: Once lookup_field_A on Opp1 gets filled with Opp2, I would like to fill Opp2's lookup_field_B with Opp1. 

I've started writing this code out but I'm unsure how to grab Opp2 from lookup_field_A and then set lookup_field_B to be Opp1.

Anyone have any ideas? Any insight would be helpful.
Hi all,

I'm looking to create an "Add" Button on my opportunities related list. I understand that the button type must be "List Button" and how to add the new button to the page layout. I am lost when it comes to writing the code for this "Add" button. Has anyone created a similar button or could someone point to a good place to start? 

Thanks,
Liz 
Hello. I have several related lists on my opportunity page. One of them is for accounts that we call "Contractors". My users want to click "New" and select all the contractors they want to add to the related list on one screen, without having to click "New" every time. What's the best way to do this? Thank you.

User-added image
I am wondering how to assign an object to be placed into a related list of an object.  I am trying to add products to the product list in an opportunity from a visualforce page but im not sure how to add this object in the controller to the opportunity related list 'Products'.  How would I add a product I have to the related list of a specific opportunity?
  • March 07, 2016
  • Like
  • 0

hi,

 I want to add a custom button in Related List.

 for example  I have a custom button named add in contact and i want that button in account  Related List.

  • March 26, 2011
  • Like
  • 0