• steve456
  • NEWBIE
  • 280 Points
  • Member since 2011

  • Chatter
    Feed
  • 11
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 77
    Questions
  • 251
    Replies

Hi all,

 

I have a workflow which creates two tasks when ever a record is created. To create a record I have 4 fields.

1)Year

2)Status

3)Project Manager

4)DIrector.

 

Now my question is when ever I create a record, My tasks which would be created should be assigned to the project manager dynamically. 

 

So we are looking at some 100 records where say may be 10 diffrent project managers are owning each 10 records.

 

So example 

 

If the project manager field is filled with the name Thomas then the work flow should trigger creating two tasks assigning them to thomas.

 

Similarly for Robin, kayla etc.

 

So I would insert 100 records with a dataloader and all records should be created with two tasks each assigned to respective PM .

 

If the task is always assigned to a single person, I'm able to do that but dynamically changing is what im faceing trouble.

 

Could some one help me in this. Can it be performed using wokflows or it needs to be coded?

Hello,

 

What is the correct method to get the month of a given date in trigger? I used the method below but it throws me an error "Method does not exist" in trigger. Please help

 

Date.now.month

 

Thanks

Paul

 

  • April 30, 2012
  • Like
  • 0

MPS 00:E0:81:C2:DA:55 [days] [r]

 

this is the string i want the first space length so that i can use in my apex code.This all iam doing in a class,i had find a function on fromula fields but it has no use in apex.

can any tell me how to find first space in a string(means position of space in string)

Thanks

Bhanu

 

Hi All,

 

I am getting an error and I cant see what in the APEX Trigger is cauing the error in the vlaidation rule.

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Contact_Opportunity_Synch caused an unexpected exception, contact your administrator: Contact_Opportunity_Synch: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0067000000NfCxeAAF; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Number of Contacts Purchased, NetProspex Product, Seats Purchased & Industry are required for any stage greater or equal to Proposal. THIS REPLACES THE CLOSED WON WIZARD!: []: Trigger.Contact_Opportunity_Synch: line 43, column1

 

here is the validation rule:

AND ( 
OR ( 
ISPICKVAL( StageName, "Proposal / TOS"), 
ISPICKVAL( StageName, "Closing Stage"), 
ISPICKVAL( StageName, "Closed Won")),OR( 
ISBLANK( of_Contacts_Purchased__c ), 
ISBLANK(TEXT( Industry__c )), 
ISBLANK(TEXT( NetProspex_Product__c)), 
ISBLANK( Seats_Purchased__c ) 
))

 

And thenthe APEX Trigger:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

trigger Contact_Opportunity_Synch on Contact (after update) {

  Map <Id, Contact> ContactMap = new Map <Id, Contact>();

  for(Contact c : Trigger.New) {
    if(c.title != Trigger.OldMap.get(c.id).title
     ||c.phone != Trigger.OldMap.get(c.id).phone
     ||c.Email != Trigger.OldMap.get(c.id).Email
     ||c.MailingCity != Trigger.OldMap.get(c.id).MailingCity
     ||c.MailingState != Trigger.OldMap.get(c.id).MailingState
     ||c.MailingStreet != Trigger.OldMap.get(c.id).MailingStreet
     ||c.MailingCountry != Trigger.OldMap.get(c.id).MailingCountry
     ||c.MailingPostalCode != Trigger.OldMap.get(c.id).MailingPostalCode
    ) {
         ContactMap.put(c.id, c);
    }
    
  }
  
  List <Opportunity> OppsToUpdate = new List <Opportunity>();
  
  for(Opportunity o : [Select id, primary_contact__c,Primary_Contact_Title__c,Primary_Contact_Email__c,Primary_Contact_Phone__c,Primary_Mailing_City__c,Primary_Mailing_Country__c,Primary_Mailing_State__c,Primary_Mailing_Street__c,Primary_Mailing_Zip__c from Opportunity where primary_contact__c in :ContactMap.keySet() and isClosed = false]) {
        
      o.Primary_Contact_Title__c = ContactMap.get(o.Primary_Contact__c).title;
          o.Primary_Contact_Email__c = ContactMap.get(o.Primary_Contact__c).email;
          o.Primary_Contact_Phone__c = ContactMap.get(o.Primary_Contact__c).phone;
          o.Primary_Mailing_City__c  = ContactMap.get(o.Primary_Contact__c).MailingCity;
          o.Primary_Mailing_Country__c = ContactMap.get(o.Primary_Contact__c).MailingCountry;
          o.Primary_Mailing_State__c = ContactMap.get(o.Primary_Contact__c).MailingState;
          o.Primary_Mailing_Street__c = ContactMap.get(o.Primary_Contact__c).MailingStreet;
          o.Primary_Mailing_Zip__c = ContactMap.get(o.Primary_Contact__c).MailingPostalCode;
    
      OppsToUpdate.add(o);
      
      if(OppsToUpdate.size() == 200) {
        update OppsToUpdate;
        OppsToUpdate.clear();
      }
    
  }

  if(OppsToUpdate.size() > 0)
    update OppsToUpdate;








}

Any help would be appreciated!!

Thanks,

Leif

 

Create a formula field that calculates the Age in hours of the case that is displayed on the case page layout. The age of the case is defined as the difference in hours between the Date/Time opened and date/time closed for the case. If the case is still open, the age should calculate the difference between case creation and the current date/time. If the case is closed, the age should calculate the difference between the case closed date/time and the case created date/time. 

For eg: 1.5 hours if the case has been opened for an hour and a half.

 

Any suggestions???

Hi,

How to use date field in SOQL query?

Here is my code:

 

string OpportunityQuery;
OpportunityQuery = 'SELECT Name, Id FROM Opportunity WHERE ';
OpportunityQuery += 'OwnerId = \''+ FromUser + '\'';
OpportunityQuery += ' AND ';

OpportunityQuery +=  'AccountId = \''+ DealerId + '\'';
system.debug('Decision_Date__c ' + ObjOpportunity.Decision_Date__c);
system.debug('Application_Date__c ' + ObjOpportunity.Application_Date__c);

date FromDate = Date.newInstance(ObjOpportunity.Decision_Date__c.year(),ObjOpportunity.Decision_Date__c.month(),ObjOpportunity.Decision_Date__c.day());
date ToDate = Date.newInstance(ObjOpportunity.Application_Date__c.year(),ObjOpportunity.Application_Date__c.month(),ObjOpportunity.Application_Date__c.day());

if(Selection == 'BookDate') {
    OpportunityQuery += ' AND ';
    OpportunityQuery += 'CloseDate >= '+ FromDate;
    OpportunityQuery += ' AND ';
    OpportunityQuery += 'CloseDate <= '+ ToDate;     
}

if(AppType == 'Booked') {
    OpportunityQuery += ' AND ';
    OpportunityQuery += ' IsWon = true ';    
}
OpportunityList = database.query(OpportunityQuery);
system.debug('OpportunityList: '+ OpportunityList);

 

 

System debug:

SELECT Name, Id FROM Opportunity WHERE OwnerId = '00530000003Ks0yAAC' AND AccountId = '001Q000000QtH1BIAV' AND CloseDate >= 2012-03-02 00:00:00 AND CloseDate <= 2012-03-23 00:00:00

The above code shows the below error.

System.QueryException: line 1:144 no viable alternative at character ' '

Thanks,
Krishna.

Hi,

 

I got this error trying to create this test class:

 

@isTest private with sharing class Opportunity
{
    static testMethod void Opportunity()
    {
        Test.startTest();
        List<Opportunity> lstOp= new List<Opportunity>();
        for(Integer iCount = 0; iCount < 20; iCount++)
        {
            Opportunity objOpp = new Opportunity();
            objOpp .Account= 'Test';
            objOpp .Name= '11111';
            objOpp .StageName= 'Visit';
            objOpp .CloseDate= Date.today();

            lstOp.Add(objOpp);
        }
        insert lstOp;
        Test.StopTest();
    }
   }

 

I have tried

 

Account

AccountName

Account__c

Account__r

Account__r.id

 

And always the same errror??

 

Thank you

 

 

  • February 15, 2012
  • Like
  • 0

Hi 

 

how fire a trigger only if a certain value is not present in map .to be clear status 'inactive' on account must be actived only if status on contract is 'expiré ' and also if no contract with status'activé' exist.

 

this is my trigger without the second condition

 

trigger workflow2 on Contract (before update) {
List<Account>accList=new List <Account>();
set<id>accIds = new Set<id>();

for(Contract c:Trigger.new){
accIds.add(c.AccountId);

}
Map<id,Account>accMap=new Map<id,Account>([Select(select id,status from contracts)from Account Where Id in :accIds]);


for(Contract c:Trigger.new){
if(c.status=='activé'){
account ac=accMap.get(c.AccountId);
ac.A_I__c='active';
accList.add(ac);
}
if(c.status=='expiré'){
account ac=accMap.get(c.AccountId);
ac.A_I__c='inactive';
accList.add(ac);
}

//this trigger must be fire only if in contract Map ,value 'activé' isn't there 
}

update accList;


}

  • February 15, 2012
  • Like
  • 0

 

Hi ,

 

I have trigger before update on opportunity.I am fetching all the opportunities related to particular account .I am retrievung highest amount value on the opporunity and then updating somefield on the acocunt object

 

I have not been able to update.How do I write Dml statement at the end of the code.When I try to write I get an error .Null pointer exceptionon the line in red

 

Can somebody please help me?

 

 

Trigger Target on Opportunity (before update)
{

set<id> sup=new set<id>();
for(opportunity opp:trigger.new)
{

sup.add(opp.accountid);

}
list<account>dry;
Account[]acc=[select id,refereed__c,(select name,amount from opportunities order by amount desc)from account where id in:sup];  
for(account lope:acc)
{

for(integer i=0; i<lope.opportunities.size();i++)
{

lope.label__c=lope.opportunities[0].name;
//update acc;

System.debug('The value in the variable of tupoe acocunt is'+lope.refereed__c);
//dry.add(lope);
}
}
//update dry;
}

 

  • February 15, 2012
  • Like
  • 0

 

Can anybody help me as how do i write a test class for this controller

 

 

public with sharing class CheckOutInventoryController {
  public Kiosk__c kiosk {get;set;}
  public boolean showMainContent {get;Set;}  
  public List<SelectOption> custodians {get;Set;}
  
  
  public CheckOutInventoryController(ApexPages.StandardController stdController)  
  {
    //initialize custodian list
    custodians = new List<SelectOption>();
        custodians.add(new SelectOption('','--None--'));
          
    try
    {
      this.kiosk=(Kiosk__c)stdController.getRecord();
      this.kiosk=[Select Id, Name, Account__c,Account__r.Name, Region__c,Supervisor__c,Market__c,Market__r.General_manager__c, 
      Market__r.Region__c,Market__r.Region__r.Area_Director__c,Market__r.Region__r.Regional_Manager__c, Market__r.Region__r.Unit_VP__c
      from Kiosk__c where Id=:kiosk.Id Limit 1];
      
      //get inventory records associated to kiosk where the location is at Kiosk
      List<Inventory__c> avilableInventoryList=[Select Id,Location__c from Inventory__c
      where Kiosk__c=:kiosk.Id and Location__c='Kiosk'];
      
      if(avilableInventoryList.size()>0)
      {
        Set<Id> employeeIdList=new Set<Id>();
        Set<Id> managementUserIds=new Set<Id>();
        //get supervisor id
        if(kiosk.Supervisor__c!=null)
        {
          employeeIdList.add(kiosk.Supervisor__c);
        }
        //get upper management user ids
        if(kiosk.Market__c!=null)
        {
          //get market general manager
          if(kiosk.Market__r.General_manager__c!=null)
          {
            managementUserIds.add(kiosk.Market__r.General_manager__c);            
          }          
          //if region is not null
          if(kiosk.Market__r.Region__c!=null)
          {
            //get Area Director
            if(kiosk.Market__r.Region__r.Area_Director__c!=null)
            {
              managementUserIds.add(kiosk.Market__r.Region__r.Area_Director__c);
            }
            //get Regional manager
            if(kiosk.Market__r.Region__r.Regional_Manager__c!=null)
            {
              managementUserIds.add(kiosk.Market__r.Region__r.Regional_Manager__c);
            }
            //get Unit VP
            if(kiosk.Market__r.Region__r.Unit_VP__c!=null)
            {
              managementUserIds.add(kiosk.Market__r.Region__r.Unit_VP__c);
            }
          }
        }  
        
        //build custodian list
        List<Employee__c> employeeList=[Select Id, Name,User_Name__c,User_Name__r.Profile.Name,
        User_Name__r.UserRoleId,User_Name__r.UserRole.Name from Employee__c where Status__c='Active' and 
        (Kiosk__c =:kiosk.Id or User_Name__c in:managementUserIds or Id in:employeeIdList) order by Name];
        for(Employee__c e:employeeList)
        {     
               //add if supervisor or upper management
               if(employeeIdList.contains(e.Id)|| managementUserIds.contains(e.User_Name__c))
               {
                 custodians.add(new SelectOption(e.Id,e.Name));   
               }   
               else
               {
                 if(e.User_Name__c!=null)
                 {
                   if(e.User_Name__r.Profile.Name.toUpperCase().endsWith('REP')==false)
                   {
                     custodians.add(new SelectOption(e.Id,e.Name));  
                   }
                 }
               }  
          }  
          if(custodians.size()>1)
          {
            showMainContent=true;
          }
          else
          {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'There are no Custodians Available!'));  
          }          
      }
      else
      {
        showMainContent=false;
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'There are no Inventory Records Available at this Kiosk!'));  
      }
    }
    catch(Exception ex)  
    {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Failed to Load Page! You may not have access to the Kiosk!'+ex));  
    }   
  }
}

 

Can anybody help me as how do i write a test class for this controller

 

 

public with sharing class CheckOutInventoryController {
  public Kiosk__c kiosk {get;set;}
  public boolean showMainContent {get;Set;}  
  public List<SelectOption> custodians {get;Set;}
  
  
  public CheckOutInventoryController(ApexPages.StandardController stdController)  
  {
    //initialize custodian list
    custodians = new List<SelectOption>();
        custodians.add(new SelectOption('','--None--'));
          
    try
    {
      this.kiosk=(Kiosk__c)stdController.getRecord();
      this.kiosk=[Select Id, Name, Account__c,Account__r.Name, Region__c,Supervisor__c,Market__c,Market__r.General_manager__c, 
      Market__r.Region__c,Market__r.Region__r.Area_Director__c,Market__r.Region__r.Regional_Manager__c, Market__r.Region__r.Unit_VP__c
      from Kiosk__c where Id=:kiosk.Id Limit 1];
      
      //get inventory records associated to kiosk where the location is at Kiosk
      List<Inventory__c> avilableInventoryList=[Select Id,Location__c from Inventory__c
      where Kiosk__c=:kiosk.Id and Location__c='Kiosk'];
      
      if(avilableInventoryList.size()>0)
      {
        Set<Id> employeeIdList=new Set<Id>();
        Set<Id> managementUserIds=new Set<Id>();
        //get supervisor id
        if(kiosk.Supervisor__c!=null)
        {
          employeeIdList.add(kiosk.Supervisor__c);
        }
        //get upper management user ids
        if(kiosk.Market__c!=null)
        {
          //get market general manager
          if(kiosk.Market__r.General_manager__c!=null)
          {
            managementUserIds.add(kiosk.Market__r.General_manager__c);            
          }          
          //if region is not null
          if(kiosk.Market__r.Region__c!=null)
          {
            //get Area Director
            if(kiosk.Market__r.Region__r.Area_Director__c!=null)
            {
              managementUserIds.add(kiosk.Market__r.Region__r.Area_Director__c);
            }
            //get Regional manager
            if(kiosk.Market__r.Region__r.Regional_Manager__c!=null)
            {
              managementUserIds.add(kiosk.Market__r.Region__r.Regional_Manager__c);
            }
            //get Unit VP
            if(kiosk.Market__r.Region__r.Unit_VP__c!=null)
            {
              managementUserIds.add(kiosk.Market__r.Region__r.Unit_VP__c);
            }
          }
        }  
        
        //build custodian list
        List<Employee__c> employeeList=[Select Id, Name,User_Name__c,User_Name__r.Profile.Name,
        User_Name__r.UserRoleId,User_Name__r.UserRole.Name from Employee__c where Status__c='Active' and 
        (Kiosk__c =:kiosk.Id or User_Name__c in:managementUserIds or Id in:employeeIdList) order by Name];
        for(Employee__c e:employeeList)
        {     
               //add if supervisor or upper management
               if(employeeIdList.contains(e.Id)|| managementUserIds.contains(e.User_Name__c))
               {
                 custodians.add(new SelectOption(e.Id,e.Name));   
               }   
               else
               {
                 if(e.User_Name__c!=null)
                 {
                   if(e.User_Name__r.Profile.Name.toUpperCase().endsWith('REP')==false)
                   {
                     custodians.add(new SelectOption(e.Id,e.Name));  
                   }
                 }
               }  
          }  
          if(custodians.size()>1)
          {
            showMainContent=true;
          }
          else
          {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'There are no Custodians Available!'));  
          }          
      }
      else
      {
        showMainContent=false;
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'There are no Inventory Records Available at this Kiosk!'));  
      }
    }
    catch(Exception ex)  
    {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Failed to Load Page! You may not have access to the Kiosk!'+ex));  
    }   
  }
}

HI all,

 

I am curious to know as how do it 

 

 

Whenever I create an oportunity I would be giving the Stage and Close Date

 

Say   Stage is Prospecting and Close Date is May7,2013

 

 

 

And 3 days later i would update the stage  and close date as follows

 

 

Now Stage is ID Decision Makers and Close Date is May 10,2013

 

 

I want to now make the Close Date for the stages in between  Prospecting  and Id Decsion Makers as May 10th,2013

 

Is it possible 

 

If yes can you please let me know the way  and how do i generate report for it 

 

 

 

Is it possible through Opportunity History Report 

I need to create an event whenever Opportunity field Probability is greater than 50%

 

I have written the code but it keeps firing on every update.I want it to fire on an insert or if there is any change in probability

 

My code is 

 

********************************

 

trigger AutoEventCreate on Opportunity (after insert , after update) {

List <Event> eventList = new List <Event> ();
Set<Id> oppIds = new Set<Id>();
for(Opportunity opp:Trigger.new){
if(opp.Id!=null &&(Trigger.isInsert || (Trigger.newMap.get(opp.id).Probability != Trigger.oldMap.get(opp.Id).Probability))){

oppIds.add(opp.Id);
}

}

for(Opportunity opp:Trigger.new){
if(opp.Probability !=null && opp.Probability>=25.00){

datetime myDate = datetime.now();



eventList.add (new Event(
Subject = 'Other',
WhatId = opp.Id,
OwnerId = opp.OwnerId,
StartDateTime = DateTime.Now(),
ActivityDateTime=null,
EndDateTime = DateTime.Now(),
DurationInMinutes = Integer.valueOf(Math.Floor( (myDate.getTime() - myDate.getTime()) / (1000.0*60.0)))

));

}
if(eventList.size() > 0)

insert eventList;

}

}

 

 

***************************

 

Can you please correct y code and let me know if any scenarios need to be added

 

Thanks in advance

I have two  fiellds on object   Colors    ,   Rejection Reason

 

Colors is MULTISELECT picklist

 

Rejection Reason  is just a picklist 

 

 

Whenever the colors B,C,D,E,F,G  in any combination are selected  Rejection Reason field is mandatory

 

Whenever the color A is selected Rejection Reason is not mandatory

 

 

Whenever the color A is selected along with B,C,D,E,F,G   (any combination as it is a multi select picklist )  Rejection Reason is not mandatory

 

 

Colors has the following values                                                    

A, B ,C ,D,E,F,G ,H      

 

 

I am able to get through all scenarios except the third  

 

 

Can anybody please be a life saver for me                                                                         

How do i give created date equal to this month in apex

 

if(CreatedDate=THISMONTH)

 

HOw do i give it in Apex

Can we write an after insert trigger on the same object 

 

 

My scenario is this way

 

 

I have three objects Sales , Order ,Inventory

 

 

Whenever a Sales Record is created an Order is created automatically

 

inventory is a field on Order which is a lookup type 

 

 

*****

I have a scenario where I have a before insert , before update trigger which fires based on Inventory field on Order 

 

The update part of the trigger is working fine ,but on an Insert the system doesnot have any value in Inventory field on Order  as it gets updated after the record is saved.Is my interoretation right or is there is something that I am missing as my code is not working on insert

 

The code is 

 

trigger UpdateAdditionalRevenueBasedOnInventory on Order__c (before insert , before update) {

Set<ID> inventoryIds=new Set<Id>();


 for(Order__c order : Trigger.new) {
         
       
         
                inventoryIds.add(order.Inventory__c);
             
        
 }
 
     
     
     List<Inventory__c> inventoryList = [Select Id, Name, Product__c, Product__r.Name from Inventory__c where Id IN: inventoryIds];
     Map<Id,String> inventoryMap=new Map<Id,String>();
     for(Inventory__c inv :inventoryList){
        if(inv.Product__c!=null)
        
        inventoryMap.put(inv.Id,inv.Product__r.Name);
     }  
         
               
     
  
 String recordtypeid=[Select Id from RecordType where Name='P18VG' and SobjectType='Order__c'].Id;    

   
    if(inventoryMap.size()>0 && inventoryMap!=null) {
        for(Order__c order:Trigger.new)
        {
               if(Trigger.isInsert||Trigger.oldMap.get(order.Id).Inventory__c != Trigger.newMap.get(order.Id).Inventory__c) {
              
                     if(order.RecordTypeId==recordtypeid ){
                   
                         Date myDate = date.newinstance(2013, 3, 11);
                         
                         if(inventoryMap!=null && 
                            order.Id!=null && 
                            order.Inventory__c != null && 
                            inventoryMap.get(order.Inventory__c) != null && 
                            inventoryMap.get(order.Inventory__c).length()>=8 && 
                            inventoryMap.get(order.Inventory__c).substring(0,8)=='V-Sample'&&                         
                            order.Date__c >=myDate
                            ){
        
                         
                             order.Revenue__c=15;
                            }
                            else{
                             
                                 order.Revenue__c=0;
                            }
                             
        
                     }
              }
                        
                        
              
                 
        }
      
    }
}

 

I have three objects Inventory , Order , Product

 

Fields on Inventory are Order (Lookup)

                               and Product(Lookup)

 

 

Field On Order is Revenue 

 

Field on Product is Product Name 

 

I need a to write a trigger on Inventory  to update a field  "Revenue" on Order object  if the product name conatins World , the value of the "Revenue" should be 20$ esle 0$

 

 

I am thinking i need to write an after update trigger on Inventory 

 

Can anybody help me with the code

 

Thanks in advance

 

 

 

Trigger on Order Entry 

 

 

ON CREATE ONLY

 

IF(RecordType.Name == "PG" && Product__r.Group__c == 'Data Plan) THEN

 

IF(LEFT(Order_Number__r.Inventory__r.Product__r.Name__c, 8) == "V-Portal" && Order_Number__r.Date__c >= 2013-02-11) THEN

            Additional_Revenue__c = 15

ELSE

            Additional_Revenue__c = 0

            ENDIF

 

 

******************How do I write a trigger as it has three cross references

 

Field on Order Entry :  Order Number    (Master Detail)

 

Field on OrderNumber : Inventory

 

Field on Inventory : Product

 

Field on Product :Name

 

*************************************************

 

Can you please help me write a trigger for the logic mentioned on top

 

Thanks in advance

How do i write the LEFT functionality in a trigger

 

 

Trigger on Order Entry 

 

 

ON CREATE ONLY

 

IF(RecordType.Name == "PG" && Product__r.Group__c == 'Data Plan) THEN

 

IF(LEFT(Order_Number__r.Inventory__r.Product__r.Name__c, 8) == "V-Portal" && Order_Number__r.Date__c >= 2013-02-11) THEN

            Additional_Revenue__c = 15

ELSE

            Additional_Revenue__c = 0

            ENDIF

 

ENDIF

 

 

 

Thanks in advance 

I am getting a null pointer exception.Do not know what mistake am doing 

 

 

CODE

 

 

trigger UpdateTransactRevenue on Order_Entry__c (before insert, before update) {
  Set<Id> productIdList=new Set<Id>();
  Set<Id> orderIdList=new Set<Id>();

  
  //process all records if they are new
  if(Trigger.isInsert)
  {
    for(Order_Entry__c oe:Trigger.new)
    {
      if(oe.Product__c!=null && oe.Order_Number__c!=null)
      {
        productIdList.add(oe.Product__c);
        orderIdList.add(oe.Order_Number__c);
      }
    }
  }
  
  if(Trigger.isUpdate)
  {
    for(Order_Entry__c oe:Trigger.new)
    {
         if(oe.Order_Number__c!=null && oe.Product__c!=null && oe.Product__c!=Trigger.oldMap.get(oe.Id).Product__c)
         {
         
           productIdList.add(oe.Product__c);
           orderIdList.add(oe.Order_Number__c);

           
         }
    }
  }
  
  
  
  if(productIdList.size()>0) 
  {
    //query for employee records
    Map<Id,Product_2020__c> productMap=new map<Id,Product_2020__c>([Select Id,Invoice_Rate_Blend__c , Invoice_Rate_Event__c from Product_2020__c where Id in:productIdList]);
    Map<Id,Order_2020__c>   orderMap = new Map<Id,Order_2020__c>([Select Id , Name , Transact_Kiosk_Category__c from Order_2020__c where Id in:orderIdList]);
    
    String recordtypeid=[Select Id from RecordType where Name='2020RK-VZ' and SobjectType='Order_Entry__c'].Id;
       
    if(orderMap!=null && orderMap.size()>0){
        for(Order_Entry__c oe:Trigger.new)
        {
         if(oe.RecordTypeId==recordtypeid){
           
           
               
               if(orderMap.get(oe.Order_Number__c)!=null && orderMap.get(oe.Order_Number__c).Transact_Kiosk_Category__c=='Event' && productMap!=null && productMap.get(oe.Product__c)!=null && productMap.size()>0 && productMap.get(oe.Product__c).Invoice_Rate_Event__c!=null)
               {
                   oe.Transact_Revenue__c=productMap.get(oe.Product__c).Invoice_Rate_Event__c * oe.Quantity__c; 
               }
               else if(orderMap.get(oe.Order_Number__c)!=null && orderMap.get(oe.Order_Number__c).Transact_Kiosk_Category__c!='Event'&& productMap!=null && productMap.get(oe.Product__c)!=null && productMap.size()>0 && productMap.get(oe.Product__c).Invoice_Rate_Blend__c!=null){
               
                   oe.Transact_Revenue__c=productMap.get(oe.Product__c).Invoice_Rate_Blend__c * oe.Quantity__c; 
               }
           
          }       
        } 
    }       
  } 

 

 

 

 

ERROR

 

 

caused by: System.NullPointerException: Argument 1 cannot be null

Trigger.UpdateTransactRevenue: line 57, column 1(highlighted is line 57)

 

 

 

 

Can any body help me please

I have three custom objects Product , Order ,  Order Entry

 

 

Order Entry has master detail with Order  and a  lookup to Product

 

 

I have a field called Revenue on Order Entry which needs to be  calculated based on  the  Category of Order 

 

 

I mean to say on Order I have a field called  Category  and based on this field I need to calculate the revenue  on Order Entry 

 

************

Trigger should execute upon Order Entry creation and whenever Order__r.Category__c is changed according to the following logic:

 

 

2.       IF(Order__r.Category__c <> "Event", Product__r.Invoice_Rate_Blend__c * Quantity__c, Product__r.Invoice_Rate_Event__c * Quantity__c)

 

 

 

I am struck as how do I do it do it  on an insert as well as an  update  as the Order field  is not changed  on the Order Entry but a particular field on Order is changed .

 

I am currently using two objects in the picture 

 

Account & Case

 

 

Account has a field Time_Zone__c which is a picklist with values EST , PST , CST ,MST

 

Case also has the same field Time_Zone__c

 

I have written trigger on case  which pulls the TimeZone automatically based on the Account Field.

 

Till here no issues

 

I have one more Field Client _Date__c(Date/Time) on Case which takes the same value as Created Date 

 

I have done this by just giving

 

Client_Date__c=System.Now()

 

 

My main issue is 

 

The Client_Date__c is taking the time zone of the created by user .But I want this to get updated based  on Time Zone field  on Case which is pulled from  Account 

 

 

I have a small doubt 
 
 
I have two obj Account and Contacts
 
 
Contact has a lookup to Account
 
 
 
I am trying  to insert  records of Accounts and I am able to do it successfully 
 
 
I am trying to insert records of Contact and I am able to do it successfully without the Account field
 
 
If i want to give the Account field in the Contact object what should i do
 
 
----------->I have only the Account names but not their ids . 
 
How can i do this
 

I have 3000 Salesforce platform licenses in my org.

 

 

A night batch job runs which inserts/updates users in our org.Batch size is 50

 

 

The issue which i am currently getting is " License Limit Exceeded ".But i still i have 30 salesforce platform licenses .Y  am getting license limit exceeded issue when I have licenses available still.

 

 

Is it because of the batch size 50?

 

And the entire batch is failing because the numberof licenses is less than 50

 

 

 

I  have a object in which i have a field

 

Dupage__c

 

 

 

I need this field to be a image ,Text. field.

 

 

All the images are in Documents .(salesforce)

 

 

How do i  get this

I  have a object in which i have a field

 

Dupage__c

 

 

 

I need this field to be a image ,Text. field.

 

 

All the images are in Documents .(salesforce)

 

 

How do i  get this

How to i give a check box field true if it meets a condition

 

 

Silly  but sensible

I had piece of Apex  trigger which was wrkng well till today morning.Suddenly it started to wrk in a wierd way..I tried to put the bck up code which is lyk 15dys old .Still i get the wierd behaviour from trigger.Can anybody had faced this kind of thing before

 

I have Lease Type field on  object Building__c.It is text field.

 

When Lease Type contains 'Monthly'

 

Status shud be active

 

 

If it was LeaseType equals Monthly i would have given straight forward.But am looking as to give  if it contains Monthly

 

Hello all,

 

I am getting the error below in my Lead trigger

 

Non-selective query against large object type (more than 100000 rows). Consider an indexed filter.

 

I am guessing my SOQL query in the list is returning too many results. It is:

 

List<CampaignMember> listCampaignMember = [Select Id,CampaignId,LeadId From CampaignMember Where LeadId IN:setLeadId];

 

I have read that a solution involves making one of the CampaignMember fields an "External ID" but don't know which one to do this for.

 

Any ideas on how to optimize my SOQL query or what field I should make an External ID on the CampaignMember object?

 

Thanks!

 

 

I need to create an event whenever Opportunity field Probability is greater than 50%

 

I have written the code but it keeps firing on every update.I want it to fire on an insert or if there is any change in probability

 

My code is 

 

********************************

 

trigger AutoEventCreate on Opportunity (after insert , after update) {

List <Event> eventList = new List <Event> ();
Set<Id> oppIds = new Set<Id>();
for(Opportunity opp:Trigger.new){
if(opp.Id!=null &&(Trigger.isInsert || (Trigger.newMap.get(opp.id).Probability != Trigger.oldMap.get(opp.Id).Probability))){

oppIds.add(opp.Id);
}

}

for(Opportunity opp:Trigger.new){
if(opp.Probability !=null && opp.Probability>=25.00){

datetime myDate = datetime.now();



eventList.add (new Event(
Subject = 'Other',
WhatId = opp.Id,
OwnerId = opp.OwnerId,
StartDateTime = DateTime.Now(),
ActivityDateTime=null,
EndDateTime = DateTime.Now(),
DurationInMinutes = Integer.valueOf(Math.Floor( (myDate.getTime() - myDate.getTime()) / (1000.0*60.0)))

));

}
if(eventList.size() > 0)

insert eventList;

}

}

 

 

***************************

 

Can you please correct y code and let me know if any scenarios need to be added

 

Thanks in advance

I have two  fiellds on object   Colors    ,   Rejection Reason

 

Colors is MULTISELECT picklist

 

Rejection Reason  is just a picklist 

 

 

Whenever the colors B,C,D,E,F,G  in any combination are selected  Rejection Reason field is mandatory

 

Whenever the color A is selected Rejection Reason is not mandatory

 

 

Whenever the color A is selected along with B,C,D,E,F,G   (any combination as it is a multi select picklist )  Rejection Reason is not mandatory

 

 

Colors has the following values                                                    

A, B ,C ,D,E,F,G ,H      

 

 

I am able to get through all scenarios except the third  

 

 

Can anybody please be a life saver for me                                                                         

How do i give created date equal to this month in apex

 

if(CreatedDate=THISMONTH)

 

HOw do i give it in Apex

 

Trigger on Order Entry 

 

 

ON CREATE ONLY

 

IF(RecordType.Name == "PG" && Product__r.Group__c == 'Data Plan) THEN

 

IF(LEFT(Order_Number__r.Inventory__r.Product__r.Name__c, 8) == "V-Portal" && Order_Number__r.Date__c >= 2013-02-11) THEN

            Additional_Revenue__c = 15

ELSE

            Additional_Revenue__c = 0

            ENDIF

 

 

******************How do I write a trigger as it has three cross references

 

Field on Order Entry :  Order Number    (Master Detail)

 

Field on OrderNumber : Inventory

 

Field on Inventory : Product

 

Field on Product :Name

 

*************************************************

 

Can you please help me write a trigger for the logic mentioned on top

 

Thanks in advance

Hi ,

I need to Clone a Record and once i clone i need the new record to have all fields carried and input the record Id from which it is cloned  ??

 

 

Please help me out with this very Urgent need

I am getting a null pointer exception.Do not know what mistake am doing 

 

 

CODE

 

 

trigger UpdateTransactRevenue on Order_Entry__c (before insert, before update) {
  Set<Id> productIdList=new Set<Id>();
  Set<Id> orderIdList=new Set<Id>();

  
  //process all records if they are new
  if(Trigger.isInsert)
  {
    for(Order_Entry__c oe:Trigger.new)
    {
      if(oe.Product__c!=null && oe.Order_Number__c!=null)
      {
        productIdList.add(oe.Product__c);
        orderIdList.add(oe.Order_Number__c);
      }
    }
  }
  
  if(Trigger.isUpdate)
  {
    for(Order_Entry__c oe:Trigger.new)
    {
         if(oe.Order_Number__c!=null && oe.Product__c!=null && oe.Product__c!=Trigger.oldMap.get(oe.Id).Product__c)
         {
         
           productIdList.add(oe.Product__c);
           orderIdList.add(oe.Order_Number__c);

           
         }
    }
  }
  
  
  
  if(productIdList.size()>0) 
  {
    //query for employee records
    Map<Id,Product_2020__c> productMap=new map<Id,Product_2020__c>([Select Id,Invoice_Rate_Blend__c , Invoice_Rate_Event__c from Product_2020__c where Id in:productIdList]);
    Map<Id,Order_2020__c>   orderMap = new Map<Id,Order_2020__c>([Select Id , Name , Transact_Kiosk_Category__c from Order_2020__c where Id in:orderIdList]);
    
    String recordtypeid=[Select Id from RecordType where Name='2020RK-VZ' and SobjectType='Order_Entry__c'].Id;
       
    if(orderMap!=null && orderMap.size()>0){
        for(Order_Entry__c oe:Trigger.new)
        {
         if(oe.RecordTypeId==recordtypeid){
           
           
               
               if(orderMap.get(oe.Order_Number__c)!=null && orderMap.get(oe.Order_Number__c).Transact_Kiosk_Category__c=='Event' && productMap!=null && productMap.get(oe.Product__c)!=null && productMap.size()>0 && productMap.get(oe.Product__c).Invoice_Rate_Event__c!=null)
               {
                   oe.Transact_Revenue__c=productMap.get(oe.Product__c).Invoice_Rate_Event__c * oe.Quantity__c; 
               }
               else if(orderMap.get(oe.Order_Number__c)!=null && orderMap.get(oe.Order_Number__c).Transact_Kiosk_Category__c!='Event'&& productMap!=null && productMap.get(oe.Product__c)!=null && productMap.size()>0 && productMap.get(oe.Product__c).Invoice_Rate_Blend__c!=null){
               
                   oe.Transact_Revenue__c=productMap.get(oe.Product__c).Invoice_Rate_Blend__c * oe.Quantity__c; 
               }
           
          }       
        } 
    }       
  } 

 

 

 

 

ERROR

 

 

caused by: System.NullPointerException: Argument 1 cannot be null

Trigger.UpdateTransactRevenue: line 57, column 1(highlighted is line 57)

 

 

 

 

Can any body help me please

I have three custom objects Product , Order ,  Order Entry

 

 

Order Entry has master detail with Order  and a  lookup to Product

 

 

I have a field called Revenue on Order Entry which needs to be  calculated based on  the  Category of Order 

 

 

I mean to say on Order I have a field called  Category  and based on this field I need to calculate the revenue  on Order Entry 

 

************

Trigger should execute upon Order Entry creation and whenever Order__r.Category__c is changed according to the following logic:

 

 

2.       IF(Order__r.Category__c <> "Event", Product__r.Invoice_Rate_Blend__c * Quantity__c, Product__r.Invoice_Rate_Event__c * Quantity__c)

 

 

 

I am struck as how do I do it do it  on an insert as well as an  update  as the Order field  is not changed  on the Order Entry but a particular field on Order is changed .

 

Hi All,

I'm not getting code coverage I need on this class.  Red lines aren't covered.  The test class is at the end of this post..

Any thoughts on how to cover these lines?  Thanks for any help!

 

UpdateMaxReviewDate (Code Covered: 69%)

 

 line source
 1  public with sharing class UpdateMaxReviewDate{
 2  
 3   public void updReviews(){
 4  
 5   Map<Id, Date> MaxDates = new Map<Id, Date>();
 6   List<IMNAccount__c> lstToUpdate = new List<IMNAccount__c>();
 7  
 8   for (AggregateResult ard : [Select imnaccount__c,
 9   Max(Review_Date__c) rd From Report_Review__c
 10   GROUP BY imnaccount__c]) {
 11  
 12   MaxDates.put(String.valueOf(ard.get('imnaccount__c')),(Date) ard.get('rd'));
 13  
 14  }
 15   Set <Id> imnacctSet = new Set<Id>();
 16   imnacctSet = MaxDates.keySet();
 17   for (IMNAccount__c imn : [Select i.Last_Report_Review__c, i.Id,
 18   i.Company__r.PM_Report_Review__c, i.PM_Report_Review_Date__c
 19   From IMNAccount__c i
 20   WHERE i.Id IN : imnacctSet]){
 21   imn.Last_Report_Review__c = MaxDates.get(imn.Id);
 22   imn.PM_Report_Review_Date__c = imn.Company__r.PM_Report_Review__c;
 23   lstToUpdate.add(imn);
 24   }
 25   if(lstToUpdate.size() > 0)
 26   update lstToUpdate;
 27  }

 

Here's my Test Code

 

@isTest
private class UpdateMaxReviewDateTest {

public static testMethod void testReviewDates() {
        
        Date d = Date.today();
        
        //Create Test Account
        Account atest = new Account();
        atest.Name = 'New Test Account';
        atest.PM_Report_Review__c = d;
        Database.insert(atest);
        
        //Create Test imnaccount
        IMNAccount__c itest = new IMNAccount__c();
        itest.Name = 'New Test Imnaccount';
        Database.insert (itest);
        
        //Create Test Report Review
        List<Report_Review__c> rList = new List<Report_Review__c>();
        for (Integer i=0; i<21; i++){
            Report_Review__c rtest = new Report_Review__c();
            rtest.Review_Date__c = d-i;
            rList.add(rtest);
        }
        
        Database.insert(rList);    
        
        Test.startTest();
        
        //instantiate class to be tested and call method
        UpdateMaxReviewDate urd = new UpdateMaxReviewDate();
        urd.updReviews();
        
        
        //validate
        for (IMNAccount__c imn : [Select i.Last_Report_Review__c, i.Id,
                            i.Company__r.PM_Report_Review__c, i.PM_Report_Review_Date__c
                            From IMNAccount__c i]){
                            Date a = imn.Company__r.PM_Report_Review__c;
                            Date b = imn.PM_Report_Review_Date__c;
                            System.assertEquals(a,b);
                                
                            AggregateResult agr = [Select Max(Review_Date__c) rd From Report_Review__c
                                        WHERE imnaccount__c = :imn.Id];
                            Date c = (Date) agr.get('rd');
                            Date e = imn.Last_Report_Review__c;
                            System.assertEquals(c,e);   
           }
           Test.stopTest();
}
}

  • February 14, 2013
  • Like
  • 0

Hi All,

I am an Apex noob and have never written an Apex trigger. I suspect that is what is required to do this. I am using basic Salesforce Accounts and Activities. I have tried to find a similar post on this board but have not found anything that does what I am trying to do - as simple as it may seem ;).

 

I have a read-only custom field in Accounts called CallCount_c (type number). I have a picklist field in Activities (aka Tasks) called MyActivity_c. I would like the custom field in Accounts to reflect the count of Activity records for this account where the MyActivity_c = "Phone Call". The Activity (Task) has a 'Related To" picklist where I choose 'Account" and then select the account to which this Activity is to be related.

 

Does that make sense?

Thanks in advance for reading, replies...

 

Currencies in our organization are loaded in 2010. Users are complaining about the change in exchange rates. If I update the exchnage rate under manage currencies section manually, will it impact the records created prior to this update?

 

Thank You in advance for the help.

  • February 14, 2013
  • Like
  • 0
I have a small doubt 
 
 
I have two obj Account and Contacts
 
 
Contact has a lookup to Account
 
 
 
I am trying  to insert  records of Accounts and I am able to do it successfully 
 
 
I am trying to insert records of Contact and I am able to do it successfully without the Account field
 
 
If i want to give the Account field in the Contact object what should i do
 
 
----------->I have only the Account names but not their ids . 
 
How can i do this
 

Hi all,

 

I have a workflow which creates two tasks when ever a record is created. To create a record I have 4 fields.

1)Year

2)Status

3)Project Manager

4)DIrector.

 

Now my question is when ever I create a record, My tasks which would be created should be assigned to the project manager dynamically. 

 

So we are looking at some 100 records where say may be 10 diffrent project managers are owning each 10 records.

 

So example 

 

If the project manager field is filled with the name Thomas then the work flow should trigger creating two tasks assigning them to thomas.

 

Similarly for Robin, kayla etc.

 

So I would insert 100 records with a dataloader and all records should be created with two tasks each assigned to respective PM .

 

If the task is always assigned to a single person, I'm able to do that but dynamically changing is what im faceing trouble.

 

Could some one help me in this. Can it be performed using wokflows or it needs to be coded?