• venturec
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 7
    Replies

Let me preface this by saying that I am not all that experienced with Apex - I have dabbled enough to be dangerous, but do not have a robust understanding. Tried a search related to this issue and came up with nothing, but my apologies if I overlooked a previous related post.

 

Challenge with Contract Object:

 

I need a way to pull the Primary Contact information from the Related Contact list to the Contract.  I was able to build a trigger that brings the Primary Contact ID onto the Contract from the Related Contact Object, however when trying to populate the Contact Name affiliated with the Primary Contact ID I've hit a wall. Since the ContractContactRole object does not have a built in reference to the contact name I've got a bit more digging to do other than what I have existing - can't simply replicate the trigger and substitute a name field that doesn't exist on the object.

 

Need for the Primary Contact on the Contract: We have a WIL driven button that is designed to pull the Primary Contact name into a specified email template - in place for ease of use for the end user and a check to ensure the end user does not  select the wrong contact on the contract for this email. 

 

Right now the link is pulling the Contact ID, which obviously doesn't work to personalize the salutation in our email.  I need the Primary Contact ID on the Contract for the WIL to properly populate the email recipient, but I also need another field on the Contract that can serve as the merge field on the email template.

 

I tried a formula field, but no luck.  I think I have to go trigger route, but then it gets into an area of timing, which I have no idea how to solve.

 

 

Here is my Trigger for the Primary Contact ID:

 

 

trigger ShowContactID on Contract (before update) {
for (Contract c : Trigger.new) {
ContractContactRole contactRole =
[select ContactID from ContractContactRole where IsPrimary = true and ContractId = :c.id];

if (contactRole != null) {
c.Primary_Contact_ID__c = contactRole.ContactID;
}
}
}

 

 

 

 

Here is my attempt at a formula to populate the Contact Name:

 

 

IF(
Primary_Contact_ID__c = Contact_Lookup__r.Id ,
Contact_Lookup__r.FirstName ,
"Recipient"
)

 

 

 

 Thanks in advanced for helping me figure this out!

 

 

Does salesforce Apex support iterating over a map using a for loop?

Hi there - I work in the publishing industry where we use letter territories to determine which reps can call which companies.  (A - gets to call ABC company).  I have created custom fields on the campaigns page for each letter (A, B, C, D, so on and so forth) and I would like to - as reps make closed won sales, each letter to total up the total value won opportunities automatically for that letter.

 

i.e.


Alliance Company - $2490.50

ABC Company - $1549.50

Another Company - $449.50

 

 

The custom field A would tell me that the total value won opportunity for the particular campaign your on is...

 

A - $4,489.50

 

So to pull this it would be related to the "Campaign Name" and that particular campaigns total value won opportunities.

 

Is this possible?

Thanks.

I am working on my first apex trigger. The business process of this trigger is when the Technical contact (Technical_Contact__c)is selected from contacts via a lookup and a button is clicked, the phone number is added in the appropriate field (Technical_Phone__c)

 

I am receiving the following error:

 

Error: Compile Error: Invalid foreign key relationship: Contact.Manufacturing_Design_Sheet__c at line 21 column 10

 

Code

// When a new line item is added to an opportunity, this trigger copies the value of the
// associated product's color to the new record.
trigger TechContactTrigger on Manufacturing_Design_Sheet__c (before insert) {

    // For every Manufacturing Design Sheet record, add its associated contact entry
    // to a set so there are no duplicates.
    Set<Id> ContactIds = new Set<Id>();
    for (Manufacturing_Design_Sheet__c oli : Trigger.new)
        ContactIds.add(oli.Id);

    // Query the Contacts for their associated Phone Number and place the results
    // in a map.
    Map<Id, Contact> entries = new Map<Id, Contact>(
        [select contact.phone from contact
         where id in :ContactIds]);
        
    // Now use the map to set the appropriate Phone Number on every Manufacturing Design Sheet processed
    // by the trigger.
    for (Manufacturing_Design_Sheet__c oli : Trigger.new)
        oli.Technical_Phone__c = entries.get(oli.Technical_Contact__c).Manufacturing_Design_Sheet__c.Technical_phone__c; 
}

 

 

 

 

Thank you

 

Is there a way to stop a trigger from updating or inserting a record if certain parameters are not met?
 
I have an if statement inside a For loop, and am testing values. If the conditions are not met, I don't want the record updated or inserted.
 
Here's my code if you need it:
 

public class clsAbstractRatingTeam {

public static void updtEventID(Abstract_Rating_Team__c[] abstRT) {

List<Events__c> eventID = new List<Events__c>([select Id from Events__c where Current_Event__c = true]);

Integer lstSize = eventID.size();

if(lstSize == 1) {

String eID = eventID[0].Id;

for(Abstract_Rating_Team__c ar : abstRT) {

ar.Event_ID__c = eID;

}

} else {

// ? stop execution and do not continue.

}

}

}

 

Thanks for your help.