• ron_reed
  • NEWBIE
  • 80 Points
  • Member since 2009

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

Hi, All-

 

I've actually posed this question to Salesforce Help Desk before, but they didn't quite give me the solution I was looking for.  I'm hoping one of you has a creative solution:

 

 

I'm looking for a way to make certain fields required before converting a lead but not required before saving that lead record.  Does anyone know a way to do this?

 

 

I'm thinking something can be done with a lead validation rule, but I haven't found a solution yet.

 

Thank you so much!

When a user logs in, in his home tab, 'Items to be Approved' contains all the records that need approval from this user. Where is this information stored?I looked in user and Approval objects and didn't seem to find any field that stores the relation---this user has these records to be approved

 

The use case is this:

 

I have an approval on opportunity, where in the manager has to approve the salesprice of opportunity line items.

 

When the manager logs in, I provide a custom button from the opportunity detail page, which opens up a visualforce page from where he can see only those products that need approval. He then approves or rejects the pricing using this page. After that he has to come to the home page and click the link for the opportunity record under 'Items to be Approved' and click Approve or Reject button.

 

This works fine if he has only one record to be approved. But if there are multiple opportunity records to be approved, the manager would have a hard time going back and forth between the opportunity detail pages and the home page.

 

So I was trying to access the approval process from the visualforce controller itself, so that I could write code to Approve/Reject the request from teh visualforce page itself, instead of coming back to the home page. To do that, I need to access the approval requests associated with a user.

 

 

Can anyone help me this please?

 

Thanks in advance,

kpr

  • September 15, 2009
  • Like
  • 0

I have a problem: we should fire a trigger after a file was attached to a custom object. Unfortunately the “after insert” and the “before insert” event on the Attachment object doesn’t get fired (but the after delete event does but we don't need that).

Does anybody has an  idea why? It can't be the code, it's just debugoutput. Or any workaroung?


  • April 17, 2008
  • Like
  • 0

I'm trying to show a filtered list of related opportunities on the product page and I've almost got it to work, except I dont know how to get row headers to appear when I use apex:outputlink.  I want to be able to link to the associated Opportunity and Account from this list.  Here is my code:

 

 

 

<apex:pageblock id="CustomList" title="High/Won Opportunities This Year"> <apex:pageBlockTable value="{!opps}" var="o" rendered="{!NOT(ISNULL(opps))}"> <apex:column ><apex:outputLink value="/{!o.Id}">{!o.name}</apex:outputLink></apex:column> <apex:column ><apex:outputLink value="/{!o.Account.Id}">{!o.Account.name}</apex:outputLink></apex:column> <apex:column value="{!o.StageName}"/> <apex:column value="{!o.Amount}"/> <apex:column value="{!o.CloseDate}"/> </apex:pageBlockTable> <apex:outputLabel value="No records to display" rendered="{!(ISNULL(opps))}" styleClass="noRowsHeader"></apex:outputLabel> </apex:pageblock>

 

 

 I've tried using Title and HeaderTitle with no luck.  Any ideas?

  

Message Edited by ron_reed on 02-04-2009 06:22 AM

I'm fairly new to apex development and trying to write my first trigger.  I would like to count the number of products that fit a certain criteria and enter that into an Opportunity field.  I have a formula field called Proprietary_Count on the OpportunityLineItem object that returns either a 1 or 0 if the attached Product meets a criteria (Product_Type = "Proprietary") and I'm trying to count those up and insert that in the Opportunity field also called Proprietary_Count.  I can get it to work on a single update, but I know the way I'm doing it won't work on a bulk update.  Any ideas would be much appreciated!

 

 

trigger countProprietaryProjectsTrigger on OpportunityLineItem (after insert) { If (trigger.isinsert) { List<Id> opptyIds = new List<Id>{}; integer prodProps = 0; for(OpportunityLineItem oli: Trigger.new){ String OpportunityId = (String)oli.OpportunityId; if(oli.Approval_Proprietary_Count__C==1){ opptyIds.add(OpportunityId); prodProps = prodProps + 1; } } Opportunity[] opptysToUpdate = [select id, name, Approval_Proprietary_Count__C from Opportunity where Id IN :opptyIds]; for(Opportunity o: opptysToUpdate){ if (o.Approval_Proprietary_Count__C == null) { o.Approval_Proprietary_Count__C = 0; } o.Approval_Proprietary_Count__C = o.Approval_Proprietary_Count__C + prodProps;//just as an example } //Perform the update in a batch for al records update opptysToUpdate; } }

 

 

 

 

Message Edited by ron_reed on 02-02-2009 12:25 PM

Is it possible to right Validation Rules based on Contact Roles or lack thereof? Specifically we want to prevent Opportunities from being marked Closed Won without at least one Contact associated with the Opportunity as a Contact Role with the Role of Decision Maker.

 

Any guidance is appreciated.

 

Thanks!

Hi,

  I have an Approval process, and I want to auto approve if 36 hours after submit for Approval, approver does not approve.

As record get locked after submit, my time dependent work not working, any other option available in SFDC.

 

Thanks,

Raj

Hi, All-

 

I've actually posed this question to Salesforce Help Desk before, but they didn't quite give me the solution I was looking for.  I'm hoping one of you has a creative solution:

 

 

I'm looking for a way to make certain fields required before converting a lead but not required before saving that lead record.  Does anyone know a way to do this?

 

 

I'm thinking something can be done with a lead validation rule, but I haven't found a solution yet.

 

Thank you so much!

Hi,

 

I want to make Product mandatory while creating an Opportunity.

Any idea ??

 

Deepak 

Message Edited by Deepak Pansari on 12-09-2009 10:15 PM

Could use some help . . . I created some validation rules to impose certain restrictions on a discount request functionality we have.  Works great, when someone plugs in an amount of $10k or more, the validation rule triggers and stops the save. 

 

The problem is that we have multicurrency enabled--I was expecting the validation rule to catch the conversion rate and to prevent someone from entering what would be over the $10k USD amount . . . that doesn't happen!!!  If I switch the currency on the record to GBP and put in $9000, the record saves.  It only errors when I hit the 10000 value regardless of the currency (and 9999 GBP is way more than $9999 USD).  The formula I am using is below.

 

AND(ISPICKVAL( Is_this_a_10k_10percent_NST__c , "Yes"),Hardware_Incremental_DiscountUSD__c >=10000)

 

This is a HUGE problem . . . I need to have this rolled out by Monday and if the system is letting larger GBP/EUR discounts run through without stopping them it will be a disaster.  How do you get a validation rule to take multicurrency into account???  Or can it?

 

 

When developing a Visualforce page for overiding view page for any object, one problem that creeps up is to display the History details of a record. The standard related list Component doesn't works for History.

 

With the help of some code from Community ( I now can't find the link to it :( ), I wrote my own code  then to display the history of an object. It mimics the standard list as far as possible.  

 

Heres the code. It is for the Case object but it can be used for any other object.

 1.Component Code

 

<apex:component controller="CaseHistoriesComponentController">
<!-- Attribute Definition -->
<apex:attribute name="CaseId" description="Salesforce Id of the Case whose Case History needs to be rendered" type="Id" required="true" assignTo="{!caseId}" />

<!-- Case History Related List -->
<apex:pageBlock title="Case History">
<apex:pageBlockTable value="{!histories}" var="History" >
<apex:column headerValue="Date" value="{!History.thedate}"/>
<apex:column headerValue="User"> <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink></apex:column>
<apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:component>

 

 

 

 

2. Apex Code

 

public class CaseHistoriesComponentController {

public Id caseId {get; set;}
public cHistories[] histories;

// Variables
public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();

public List<cHistories> getHistories()
{
list<cHistories> histories = new list<cHistories>();
String prevDate = '';
for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
{
if((cHistory.newValue == null && cHistory.oldValue == null)
|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
{
cHistories tempHistory = new cHistories();
// Set the Date and who performed the action
if(String.valueOf(cHistory.CreatedDate) != prevDate)
{
tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
tempHistory.who = cHistory.CreatedBy.Name;
tempHistory.userId = cHistory.CreatedBy.Id;
}
else
{
tempHistory.theDate = '';
tempHistory.who = '';
tempHistory.userId = cHistory.CreatedBy.Id;
}
prevDate = String.valueOf(cHistory.CreatedDate);

// Get the field label
String fieldLabel = CaseHistoriesComponentController.returnFieldLabel(String.valueOf(cHistory.Field));

// Set the Action value
if (String.valueOf(cHistory.Field) == 'created') { // on Creation
tempHistory.action = 'Created.';
}
else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
// Format the Date and if there's an error, catch it and re
try {
tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
} catch (Exception e){
tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
}
}
else{ // all other scenarios
String fromText = '';
if (cHistory.OldValue != null) {
try {
fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
} catch (Exception e) {
fromText = ' from ' + String.valueOf(cHistory.OldValue);
}
}

String toText = '';
if (cHistory.OldValue != null) {
try {
toText = Date.valueOf(cHistory.NewValue).format();
} catch (Exception e) {
toText = String.valueOf(cHistory.NewValue);
}
}
if(toText != '')
tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
else
tempHistory.action = 'Changed <b>' + fieldLabel;
}

// Add to the list
histories.add(tempHistory);
}
}

return histories;
}

// Function to return Field Label of a Case field given a Field API name
public Static String returnFieldLabel(String fieldName)
{
if(CaseHistoriesComponentController.CaseFieldmap.containsKey(fieldName))
return CaseHistoriesComponentController.CaseFieldmap.get(fieldName).getDescribe().getLabel();
else
{
for(Schema.PicklistEntry pickList : fieldPicklistValues)
{
if(pickList.getValue() == fieldName)
{
if(pickList.getLabel() != null)
return pickList.getLabel();
else
return pickList.getValue();
}
}
}
return '';
}
// Inner Class to store the detail of the case histories
public class cHistories {

public String theDate {get; set;}
public String who {get; set;}
public Id userId {get; set;}
public String action {get; set;}
}
}

  Let me know your views on the code or if you have any questions

 

Can a work flow be created where it will call for a specific action no matter what field is updated and then attempted to be saved?

 

I need to make the user assign a case out of our support queand assigned to a specific user if any field in the case is updated. Can this be done, and if so, my friends, how?

 

 

Hi:

 

When we convert Prospects into Opportunities in Salesforce, the Opportunity record is automatically assigned a close date of the end of the current fiscal quarter.  I found this is true by reading the Help section in Salesforce on opps created from converted leads.

 

I can see no way of changing this close date for opps created from converted prospects.  What I want is for the opportunity created from a converted prospect to have a Close Date of Today + 30 days AND NOT the date of the end of the current fiscal quarter.  How can I change the Close Date on Opportunity records that are created when a Prospect is converted into an opportunity? 

 

This seems like it should be a really easy thing to do but I can find no way of doing it.

 

Thanks!

Hello, I hope someone can help me, I have the following function:

 

public static void CreateNote(Id parentId, string subject, string msg){ Note n = new Note(); n.Body = msg; n.ParentId = parentId; n.Title = subject; insert n; }

 

 Now, I need to update the parent records last modified timestamp, but in order to query the parent I need to determine the parents sObjectType from the parentId.

 

I have no idea how to do this.

 

 

When a user logs in, in his home tab, 'Items to be Approved' contains all the records that need approval from this user. Where is this information stored?I looked in user and Approval objects and didn't seem to find any field that stores the relation---this user has these records to be approved

 

The use case is this:

 

I have an approval on opportunity, where in the manager has to approve the salesprice of opportunity line items.

 

When the manager logs in, I provide a custom button from the opportunity detail page, which opens up a visualforce page from where he can see only those products that need approval. He then approves or rejects the pricing using this page. After that he has to come to the home page and click the link for the opportunity record under 'Items to be Approved' and click Approve or Reject button.

 

This works fine if he has only one record to be approved. But if there are multiple opportunity records to be approved, the manager would have a hard time going back and forth between the opportunity detail pages and the home page.

 

So I was trying to access the approval process from the visualforce controller itself, so that I could write code to Approve/Reject the request from teh visualforce page itself, instead of coming back to the home page. To do that, I need to access the approval requests associated with a user.

 

 

Can anyone help me this please?

 

Thanks in advance,

kpr

  • September 15, 2009
  • Like
  • 0

I have a work flow rule that sets the Close Date on Opportunities that are created by a specific person to 6 months from the Opportunity Created Date. Here is the formula I am using

 

DATE( YEAR(TODAY()) , (MONTH(TODAY()) + 6), DAY(TODAY()))

 

Up until today it has been working just fine, however now that it is July 1st and the new close date would be January 1, 2010 it is causing an error when the specific person noted above tries to create an opportunity. Below is the message they receive.

 

A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it.: Close Date: value not of required type: common.formula.FormulaEvaluationException: Month or Day out of range in DATE() function

Can anyone give me an idea of why it is no longer working correctly?

Thanks!

Can anyone confirm whether this is a bug or a misunderstanding.

 

I cannot create workflow rules on the Attachment or Note objects to notify that they have been added/changed. Therefore I have created a trigger to update a field on the parent custom object, so that the field can be used for the workflow rule. My trigger for notes works fine, but the trigger for attachments (almost identical to the Notes trigger) only fires for undates, not for inserts, whether these are before or after insert. I've looked in the debug log and the trigger is not called at all if an attachment is inserted.


I think this must be a bug. Can't think of any logical reason why Attachments would behave differently to Notes. 

 

My code looks like this:

 

trigger Attachment_BeforeInsertUpdate on Attachment (before insert, before update) {	Attachment[] att = Trigger.new;	for (Attachment item : att ){				//Ignore if no PCR linked to CSR			PCR__c[] pcrs = [select Id, attachment_change__c from PCR__c where Id = :item.parentid];		System.assert(pcrs.size() > 0);		for (PCR__c pcr : pcrs) {				pcr.attachment_change__c = System.now();			update pcr;		}	}}

 Any thoughts anyone?

 

Roger England 

Hi. I tried to 'disable' the default Attachment function of SFDC with the following trigger:
 
Code:
trigger AttachmentDisabler on Attachment (before insert) {
 List<Attachment> atts = Trigger.new;
 for(Attachment a:atts) {
  a.addError('Please use the "Attach(FTP)" button on top of the detail page to attach a file.'); 
 }
}

 
But this does not seem to work. Did I do something wrong or is it impossible this way? Even the debug did not show anything, the trigger does not seem to do anything. Any other ways to disable the normal Attach function of SFDC without removing the entire related list? (want to keep notes function)

I have a problem: we should fire a trigger after a file was attached to a custom object. Unfortunately the “after insert” and the “before insert” event on the Attachment object doesn’t get fired (but the after delete event does but we don't need that).

Does anybody has an  idea why? It can't be the code, it's just debugoutput. Or any workaroung?


  • April 17, 2008
  • Like
  • 0