• MSSBMeghan
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 18
    Replies

***TRIGGER NEWBIE ALERT***

 

 

I have a custom Object "Goal" which houses a monthly quota for each rep.  Quota is based on several custom factors so using the standard RevenueForecast is not an option here.

 

I have a lookup from Opportunity to Goal and am trying to tally up the value of the New_Sales_Actual__c from the opportunity onto the ClosedBusiness__c field on the Goal record.

 

I found the example of how to do this 

 

I've tried this a number of ways and this one is the closest, except instead of totalling the value of New_Sales_Actual__c from all of the opportunities related to the goal, it counts the number of opportunities - so if I have 5 opportunities related to a goal valued at $1, $2, $2, $1, $1 instead of getting $7 in the ClosedBusiness__c field I get 5.

 

trigger OpportunityRollup on Opportunity (after delete, after insert,
after update) {
double sumNewSales = 0.00;

Set<id> goalIds = new Set<id>();
List<goal__c> goalsToUpdate = new List<goal__c>();

for (Opportunity item : Trigger.new)
goalIds.add(item.Goal__c);

if (Trigger.isUpdate || Trigger.isDelete) {
for (Opportunity item : Trigger.old)


goalIds.add(item.Goal__c);
}

Map<id,Goal__c> goalMap = new Map<id,Goal__c>([select id, ClosedBusiness__c
from Goal__c
where id IN :goalIds]);


for (Goal__c goal : [select Id, ClosedBusiness__c, (select id,
New_Sales_Actual__c from Opportunities__r) from Goal__c where Id IN
:goalIds]) {
goalMap.get(goal.Id).ClosedBusiness__c = goal.Opportunities__r.New_Sales_Actual__c.size();

goalsToUpdate.add(goalMap.get(goal.Id));
}

for (Goal__c goal : [select Id, ClosedBusiness__c, (select id,
New_Sales_Actual__c from Opportunities__r) from Goal__c where Id IN
:goalIds])

 

//**my playing around that didn't work


// {
// sumNewSales += goal.New_Sales_Actual__c;
// }

// goal.ClosedBusiness__c = sumNewSales;



update goalsToUpdate;

}

 

 

 

Apologies in advance - I know this is a small syntax error, but I can't seem to solve this on my own.  I get a comple error with the following trigger (designed to create new Contract on closed opportunity if a contract does not already exist)

 

Unfortunately I just accidentally closed my browser window where I was writing this, so I don't know the exact error - I just remember it was a compile error on line 3.

 

Any help would be most appreciated!!

 

trigger checkOppty on Opportunity(after update) { private List<Contract> contracts = new List<Contact>(); for (Opportunity o in Trigger.new) { if (o.isClosed && !Trigger.oldMap.get(o.Id).isClosed) { Contract c = new Contract(Name = o.Name); contracts.add(c); } } if (contracts.size() > 0) { insert contracts; } }

 

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!

 

 

***TRIGGER NEWBIE ALERT***

 

 

I have a custom Object "Goal" which houses a monthly quota for each rep.  Quota is based on several custom factors so using the standard RevenueForecast is not an option here.

 

I have a lookup from Opportunity to Goal and am trying to tally up the value of the New_Sales_Actual__c from the opportunity onto the ClosedBusiness__c field on the Goal record.

 

I found the example of how to do this 

 

I've tried this a number of ways and this one is the closest, except instead of totalling the value of New_Sales_Actual__c from all of the opportunities related to the goal, it counts the number of opportunities - so if I have 5 opportunities related to a goal valued at $1, $2, $2, $1, $1 instead of getting $7 in the ClosedBusiness__c field I get 5.

 

trigger OpportunityRollup on Opportunity (after delete, after insert,
after update) {
double sumNewSales = 0.00;

Set<id> goalIds = new Set<id>();
List<goal__c> goalsToUpdate = new List<goal__c>();

for (Opportunity item : Trigger.new)
goalIds.add(item.Goal__c);

if (Trigger.isUpdate || Trigger.isDelete) {
for (Opportunity item : Trigger.old)


goalIds.add(item.Goal__c);
}

Map<id,Goal__c> goalMap = new Map<id,Goal__c>([select id, ClosedBusiness__c
from Goal__c
where id IN :goalIds]);


for (Goal__c goal : [select Id, ClosedBusiness__c, (select id,
New_Sales_Actual__c from Opportunities__r) from Goal__c where Id IN
:goalIds]) {
goalMap.get(goal.Id).ClosedBusiness__c = goal.Opportunities__r.New_Sales_Actual__c.size();

goalsToUpdate.add(goalMap.get(goal.Id));
}

for (Goal__c goal : [select Id, ClosedBusiness__c, (select id,
New_Sales_Actual__c from Opportunities__r) from Goal__c where Id IN
:goalIds])

 

//**my playing around that didn't work


// {
// sumNewSales += goal.New_Sales_Actual__c;
// }

// goal.ClosedBusiness__c = sumNewSales;



update goalsToUpdate;

}

 

 

 

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!

 

 

Hi,

 

i'm new in Apex and Salesforce. My Question: Is it possible to programm in Apex a button, which is shown on the Opportunity site? The code have to be written in SETUP | CREATE |  APPS an not in a programming environment.

  • September 10, 2009
  • Like
  • 0

Hi all,

 

    I have a trigger to do a field update on another object(salesforecast) when opportunity owner is changed. It turns out it works only when the opportunity owner is changed manually. When the owner is changed due to the account transfer,  the trigger won't be triggered.

 

    Although the owner change will always show up in the I couldn't create trigger upon the OpportunityFieldHistory.

 

    Any work around for this? 

 

Thanks,

Dawn

  • September 08, 2009
  • Like
  • 0

I have three fields that 99% of the time I will want the data to be cloned/copied to three other fields.

 

What I want is to be able to click a button to do this automatically rather than having to type

the information again?

 

Is there an easy way to do this?

 

 

Michael

Message Edited by MichaelAB on 07-23-2009 09:41 AM

The ability to generate and attach a .pdf document to an e-mail generated by an Visualforce Page e-mail template is fairly straightforward using the <messaging:attachment renderAs="pdf"> capability.  However, this method generates a .pdf file from whatever is contained between the <messaging:attachment> and </messaging:attachment> tags.

 

My problem is that I already have a .pdf document stored in a Documents folder in SFDC and I want to automatically attach that document to an e-mail generated by a Visualforce Page template without the user having to go through the  the document selection and attachment process.  I don't want to have to re-generate the document, just attach it.

 

Any ideas?

I want the new stock price field to reference the ticker symbol field I have, go out to a service like google finance, retrieve the stock quote and update the stock price field each time the account record is loaded.  This has to be complicated right?

 

Steve

Hi there,

I would like to create a formula field in activity (Task) that displays value from a field in opportunity that it is related to
For example: display the opportunity name that it is related to

I am not sure how to do this (or if this is even possible)

I know you can reference Account but i wonder why it could not refer to opportunity
I found out that you can use WhatId to get the ID of account or opportunity

Now i am thinking if there is a way to reference Opportunity the easy way or maybe if we can do a look up using the opportunity ID that we can get using WhatId

I hope someone can enlighten me

Thanks
  • November 29, 2008
  • Like
  • 0
I have created a few custom components for the home page and was wondering if there is an easy way to hide the name of the component when it is displayed?  It appears that SFDC takes the name of the custom component and puts it in a h2 tag. 

I'm thinking I can write some JavaScript to locate the specific h2 tags I want to hide (clearing out the innerHTML) and embed that in the "Messages and Alerts" component, but I wanted to see if there was a better way to accomplish this.  Any suggestions?
Hello,
 
I was wondering if there's a quick and easy way to throw a stock ticker on the left side of your home tab.
 
Thanks,
Brian
  • February 14, 2008
  • Like
  • 0