• veeru
  • NEWBIE
  • 0 Points
  • Member since 2009

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

Hello,

 

I am Naidu, working as salesforce.com administrator. And have started recently on apex coding.

 

We had an object "Events__c" which is a look up filed on opportunity. Whenever i created or deleted or update any opportunity one currency field on event will be update with all the amounts of the related opportunities. and my code is working well for the creation / updation /deletion of opportunities of that event.

 

If i move any opportunity from one event to new event, the opportunity amount will be added to the new event and is working. but from the old event the amount is not getting reduced even if there is no opportunity on the event.

 

i hope i am clear in explaining.

 

Here is my code and then the trigger to call the method.

 

 public static void updateEvent(Opportunity[] opps, Boolean TriggerIsDelete)

{

System.debug('updateEvent:start');

 

Map<Id, Opportunity> OriginalOpps = new Map<Id, Opportunity>();

 

for(Integer i=0;i<opps.size();i++)

{

OriginalOpps.put(opps[i].Id, opps[i]);

}

 

Set<Id> eventIds = new Set<Id>();

 

for(Integer i=0; i<opps.size(); i++)

{

if(opps[i].Event__c != null && !eventIds.contains(opps[i].Event__c))

{

eventIds.add(opps[i].Event__c);

}

}

 

System.debug('eventIds.size()' + eventIds.size());

 

if(eventIds.size() > 0)

{

Events__c[] events = [select Id,Delegate_Attendees__c,Vendors_Revenue__c from Events__c where Id IN:eventIds];

 

System.debug('events.size()=' + events.size());

 

Opportunity[] VendOpps = [select Id, Amount, Number_of_Attendees__c, Event__c from Opportunity where

Event__c IN :eventIds AND (StageName = 'Verbal Agreement' OR StageName = 'Compliment Deal' OR StageName = 'Contract Received' OR

StageName = 'Pro - Forma Raised' OR StageName = 'Invoiced' OR StageName = 'Partial Payment' OR StageName = 'Payment Received') AND (Type = 'Vendor' OR Type = 'Vendor (Re-booking)')];

 

Map<Id, Events__c>eventIdEventMap = new Map<Id, Events__c>();

 

for(Integer i=0; i< events.size(); i++)

{

eventIdEventMap.put(events[i].Id,events[i]);

}

 

Map<Id, Opportunity[]> eventIdsOppsMap = new Map<Id, Opportunity[]>();

 

for(integer i=0; i< events.size(); i++)

{

System.Debug('events[i].Id= ' + events[i].Id);

 

List<Opportunity> eventRelatedOpps = new List<Opportunity>();

 

for(Integer j=0; j< VendOpps.size(); j++)

{

if(VendOpps[j].Event__c == events[i].Id)

{

if(!TriggerIsDelete)

{

eventRelatedOpps.add(VendOpps[j]);

}

else

{

if(!OriginalOpps.containsKey(VendOpps[j].Id))

{

eventRelatedOpps.add(VendOpps[j]);

}

}

 

}

}

 

System.Debug('eventRelatedOpps.size()= ' + eventRelatedOpps.size());

 

if(eventRelatedOpps.size() > 0)

{

eventIdsOppsMap.put(events[i].Id,eventRelatedOpps);

}

 

else

{

eventIdsOppsMap.put(events[i].Id, null);

}

 

}

 

List<Opportunity> eventRelatedOpps =new List<Opportunity>();List<Events__c> updatedEvents = new List<Events__c>();

 

System.debug('eventIds.Size()=' + eventIds.Size());

 

for(Id eventId:eventIds)

{

Events__c updatedEvent = eventIdEventMap.get(eventId);

eventRelatedOpps = eventIdsOppsMap.get(eventId);

 

Decimal VenAmnt=0;

 

if(eventRelatedOpps!=null)

{

for (Opportunity oppty: eventRelatedOpps)

{

VenAmnt = VenAmnt + oppty.Amount;

}

}

 

updatedEvent = eventIdEventMap.get(eventId);

updatedEvent.Vendors_Revenue__c = VenAmnt;

 

updatedEvents.add(updatedEvent);

 

}

 

System.debug('updatedEvents.size()=' + updatedEvents.size());

 

try

{

if(updatedEvents.size() > 0)

{

update updatedEvents;

}

}

 

catch(dmlException e)

{

System.debug(e.getMessage());

}

}

 

}

 

 

-------

 

here is the trigger to call the method from the class.

 

 

trigger tgrVendorsRevenue on Opportunity (after insert, after update, before delete) {

 

if(Trigger.isDelete)

{

Opportunity[] opps = Trigger.old;

VendorsRevenue.updateEvent(opps, true);

 

}

else

{

Opportunity[] opps = Trigger.new;

VendorsRevenue.updateEvent(opps, false);

 

}

 

}

  • September 04, 2009
  • Like
  • 0
Hi all,
 
 
It seems that VF doesn't know to render currency field with the right currency Symbol when displaying the UnitPrice field of the  PriceBookEntry sObject:
 
Here my Controller Code:
 
Code:
public class TEST {public PriceBookEntry getMyProd(){  return [select Id,UnitPrice,Product2.currencyisocode from PriceBookEntry where id =:'01uR0000000bGho'];}}

 01uR0000000bGho is  PriceBookEntry record id  which currency equals to  EUR ->  EUR 1,500.00
 
Here is my VF Page
 
Code:
<apex:outputField value="{!MyProd.UnitPrice}"/><br/>Real currency Symbol : <apex:outputField value="{!MyProd.Product2.currencyisocode}"/>

 
Here is the result:
 
List Price  USD 1,500.00
Real currency Symbol : EUR 
When the expected result should be :
 
List Price  EUR 1,500.00
Real currency Symbol : EUR
 
 
This is very strange, it seems to be a serious issue.
 
Any Idea or comment?


Message Edited by Sami Cohen on 01-15-2009 04:29 AM

Message Edited by Sami Cohen on 01-15-2009 04:30 AM

Message Edited by Sami Cohen on 01-15-2009 04:31 AM

Message Edited by Sami Cohen on 01-15-2009 04:50 AM
Message Edited by Sami Cohen on 03-17-2009 11:38 PM