• RVJ
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies

Hi - we have just gone live with SF Partner Portal and have partners creating opps - however, we would like a specific campaign to be populated on creation.

 

I have found that I am not able to do this using standard workflow, and I would like to avoid apex coding as we do not have a developer on board.  I have been looking at using a custom 'new' button to pre-populate the field but I can't get this to work, so far I have:

 

https://eu1.salesforce.com/006/e?opp17_lkid=701D0000000ttOD 

 

Of course this is assuming that I can hide the list view button, if not any advice on the code needed?

 

Any help much appreciated, many thanks.

  • January 15, 2013
  • Like
  • 0

Hi - I am not a developer but have been working on an Apex class to roll up opportunity/account information from a group of accounts onto the top level account (accounts in the hierarchy - we have a multi-tier hierarchy in which child records share a group ID - top level account is defined by record type), the reason that we are not able to do this using roll up summary fields is because we have multi-currency and dated exchange rates - therefore the option is not available to us - hence I have had to find a coding solution. Everything is set up and appears to be working (sandbox), however it seems to be slow in updating the account - I am sure there must be a neater way of writing this code but I am not sure how. Also, I think I need to take into account Account Merges - how would I do that? So I guess my 2 questions are:

 

1. Is there a better/neater way of writing the below code for both trigger and class?

2. Any insight on what to do if accounts are merged - I would need to update both the old hierarchy and the new one I think

 

Any guidance and assistance here - much appreciated.

This is the trigger to call the class:

---------------------------------------------

trigger RollUpF50Stats on Account (after update, before delete) 
{
for (Account a: Trigger.old) {

    if (a.F50__c == 'Yes') {
    //I am setting up a list to hold the singular root account. There might be a better way of doing this?
    
    if (Trigger.isDelete) {
            String RootAccount = a.ITBgroup__Group_Id__c;
            //Checking if the trigger has already ran in this instance so that we don't get a recurring loop  
            if (RichWF50.F50AlreadyCalled()==FALSE){
                //Calling our class and sending the list of accounts (Which should just be the 1!)
                RichWF50.updateF50root(RootAccount);
            }
    }
    
    if (Trigger.isUpdate) {
                for (Account n: Trigger.new) {
                    if (a.F50__c == 'Yes') {
                    if (n.ITBgroup__Group_Id__c <> a.ITBgroup__Group_Id__c) {
                    
                        String NewRootAccount = n.ITBgroup__Group_Id__c;
                        String OldRootAccount = a.ITBgroup__Group_Id__c;
                
                    //Checking if the trigger has already ran in this instance so that we don't get a recurring loop  
                    if (RichWF50.F50AlreadyCalled()==FALSE){
                        //Calling our class and sending the list of accounts (Which should just be the 1!)
                        RichWF50.updateF50root(NewRootAccount);
                        RichWF50.updateF50root(OldRootAccount);
                    }
                }
                else {
                    String RootAccount = n.ITBgroup__Group_Id__c;
                    if (RichWF50.F50AlreadyCalled()==FALSE){
                        //Calling our class and sending the list of accounts (Which should just be the 1!)
                        RichWF50.updateF50root(RootAccount);
                    }             
            }
            }
            }
    }
    }
    }    
  }

 

-----------------------------------------

This is the Class the trigger is calling:

public class RichWF50 {
   
   //Setting a variable to be false, this is used for the recursion check.
   public static Boolean F50AlreadyCalled=FALSE;
   
   //This method returns the state of the recursion check
   public static boolean F50AlreadyCalled(){
       //returns the variable (I don't even know why I am commenting this as it is so obvious)
       return F50AlreadyCalled;
   }
   
  @future
  public static void updateF50root(String RootAcc){
        //Step 1. Set the public variable to true so that the trigger will not get stuck in a loop.
        F50AlreadyCalled=TRUE;
        
        Account a = new Account();
        
        a = [SELECT Id, Total_Users__c FROM Account WHERE Id =: RootAcc];
            
            System.debug('The ID of the account object is: ' + a.Id);
            
            string id15cr = a.Id;
            
            System.debug('The formatted ID of the account object is: ' + id15cr.substring(0, 15));
            
            //Step 2. Create a list of Accounts 
            List<Account> Accs = [Select Total_Number_of_Seats__c From Account where ITBgroup__Group_Id__c =: id15cr.substring(0, 15)];
        
            Double j = 0;
 
            // Loop through the filtered Accounts and sum up their amounts.
             
             for(Account Acc : Accs)
                {
                    If (Acc.Total_Number_of_Seats__c != Null)
                    {
                        j += Acc.Total_Number_of_Seats__c;
                    }
                }
                
            System.debug('Top account actual before: ' + a.Total_Users__c);
            System.debug('Calculated new amount of users: ' + j);
            a.Total_Users__c  = j;
            System.debug('Top account after: ' + a.Total_Users__c);
            
            //Step 3. Create a list of Open Opportunities 
            
            List<Opportunity> Opps = [Select Opportunity_Number_of_Seats__c, Converted_Value__c From Opportunity where (ForecastCategoryName != 'Omitted' AND ForecastCategoryName != 'Closed') AND Group_ID2__c =: id15cr.substring(0, 15)];
 
            Double k = 0;
            Double L = 0;
 
            // Loop through the filtered Opportunities and sum up their amounts.
             for(Opportunity Opp : Opps)
             {
                If (Opp.Opportunity_Number_of_Seats__c != Null)
                {
                    k += Opp.Opportunity_Number_of_Seats__c;
                }
            }
            
            a.Total_Opp_Seats_del__c  = k;

            for(Opportunity Opp : Opps)
            {
                If (Opp.Converted_Value__c != Null)
                {
                    L += Opp.Converted_Value__c;
                }
            }
            
            a.Total_Opp_Value__c  = L;
            
            //Step 4. Create a list of Won Opportunities 
            List<Opportunity> Oppys = [Select Opportunity_Number_of_Seats__c,Converted_Value__c, convertCurrency(Amount)From Opportunity where ForecastCategoryName = 'Closed' AND Group_ID2__c =: id15cr.substring(0, 15)];
 
            Double m = 0;
            Double n = 0;
   
            // Loop through the filtered Opportunities and sum up their amounts.
            for(Opportunity Opp : Oppys)
            {
                If (Opp.Converted_Value__c != Null)
                {
                    m += Opp.Converted_Value__c;
                }
            }
            a.Total_Won_Opp_Value__c  = m;
            
            for(Opportunity Opp : Oppys)
            {
                If (Opp.Opportunity_Number_of_Seats__c != Null)
                {
                    n += Opp.Opportunity_Number_of_Seats__c;
                }
            }
            a.Total_Seats_All__c = n;
            
             //Step 5. Create a list of Lost Opportunities 
            List<Opportunity> Oppys2 = [Select Opportunity_Number_of_Seats__c,Converted_Value__c, convertCurrency(Amount)From Opportunity where StageName = '99 - Closed lost' AND Group_ID2__c =: id15cr.substring(0, 15)];
 
            Double P = 0;
            Double Q = 0;
   
            // Loop through the filtered Opportunities and sum up their amounts.
            for(Opportunity Opp : Oppys2)
            {
                If (Opp.Converted_Value__c != Null)
                {
                    P += Opp.Converted_Value__c;
                }
            }
            a.Total_Value_Lost__c  = P;
            
            for(Opportunity Opp : Oppys2)
            {
                If (Opp.Opportunity_Number_of_Seats__c != Null)
                {
                    Q += Opp.Opportunity_Number_of_Seats__c;
                }
            }
            a.Total_Seats_Lost__c = Q;
            
        update a;
         
    } 
}

 

  • January 31, 2012
  • Like
  • 0

Hi - I am trying to copy the converted currency amount on opportunity to a custom field.  My purpose for doing this is to use the custom field in another trigger to roll up information to the Top Level Account - I can't use SF roll up features because we use multi-currency and dated exchange rates - at this point I am not concerned about the dated exchange rates - but as I say it limits what I can in SF.  

 

I am very new to Apex Code but have given it a bash, I have the following code - which does work - however I have it on before update and therefore it is taking the amount value from the opportunity - I really need to either change this to an after update trigger or modify my code to look at the new value.  I get an error when I change to after update saying that the record is read only.  If someone is able to point me in the right direction, it would be much appreciated.  Thank you.

 

trigger CopyConvertedValue on Opportunity (before update) {

 

Integer i = 0;
Opportunity Oppy = Trigger.new[i];

String intTest = Trigger.new[i].ID;

//Step 2. Create a list of Opps
List<Opportunity> Oppys = [Select convertCurrency(Amount)From Opportunity where ID =: intTest];

for (Opportunity Opp : oppys)


//Step 3. Update Oppy
Trigger.new[i].Converted_Value__c = Trigger.new[i].Amount;
}

  • January 16, 2012
  • Like
  • 0

We are implementing using SF Approval workflow for our opportunities. Part of the entry criteria and step criteria needs to be on the Primary partner - something like this: *If the Primary Partner on the opportunity = 'my company' then 'step 1' else *If the Primary Partner on the opportunity <> 'my company' then 'step 2'.

 

What I would really, really like is to be able to pull through the Primary Partner account name into a blank field on the opportunity - I could then use this field in filters etc.

I cannot see anywhere an option to lookup on Primary parent is any of the filters. As part of an existing validation rule we do already have an apex trigger set up to show if the primary partner is assigned on an opportunity by updating a checkbox on the opportunity (trigger below), this works fine for its purpose but I think I need to clone and modify it to achieve the above, but just not sure where to start, any help much appreciated!


trigger updatepartnercount on Opportunity (before insert, before update)
{

Boolean isPrimary;
Integer iCount;

Map<String, Opportunity> oppty_con = new Map<String, Opportunity>();//check if the contact role is needed and add it to the oppty_con map
for (Integer i = 0; i < Trigger.new.size(); i++)
{
oppty_con.put(Trigger.new[i].id,
Trigger.new[i]);
}
isPrimary = False;
for (List<Opportunitypartner> oppcntctrle :[select OpportunityId from Opportunitypartner where (Opportunitypartner.IsPrimary = True and Opportunitypartner.OpportunityId in :oppty_con.keySet())])
{
if (oppcntctrle .Size() >0)
{
isPrimary = True;
}
}
iCount = 0;
for (List<Opportunitypartner> oppcntctrle2 : [select OpportunityId from Opportunitypartner where (Opportunitypartner.OpportunityId in :oppty_con.keySet())])//Query for Contact Roles
{
if (oppcntctrle2 .Size()>0)
{
iCount= oppcntctrle2 .Size();
}
}
for (Opportunity Oppty : system.trigger.new) //Check if roles exist in the map or contact role isn't required
{
Oppty.Number_of_partners__c = iCount;
Oppty.Primary_partner_Assigned__c =isPrimary;
}
  • October 25, 2011
  • Like
  • 0

Hi, I am trying to create a trigger to start an approval process after insert if a certain field is checked - we are getting this save error: 'Expression cannot be assigned'

 

 

MDFSubmitForApproval on MDF__c (after insert) {

for (MDF__c a : trigger.new) {


if (MDF__c.Submitted__c = 'true') {


Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();app.setObjectId(a.id);
Approval.ProcessResult result = Approval.process(app);
}
}
}

 

Not sure where we are going wrong with this?  Any help much appreciated.

  • September 01, 2011
  • Like
  • 0

Hi - we have just gone live with SF Partner Portal and have partners creating opps - however, we would like a specific campaign to be populated on creation.

 

I have found that I am not able to do this using standard workflow, and I would like to avoid apex coding as we do not have a developer on board.  I have been looking at using a custom 'new' button to pre-populate the field but I can't get this to work, so far I have:

 

https://eu1.salesforce.com/006/e?opp17_lkid=701D0000000ttOD 

 

Of course this is assuming that I can hide the list view button, if not any advice on the code needed?

 

Any help much appreciated, many thanks.

  • January 15, 2013
  • Like
  • 0

Hi - I am not a developer but have been working on an Apex class to roll up opportunity/account information from a group of accounts onto the top level account (accounts in the hierarchy - we have a multi-tier hierarchy in which child records share a group ID - top level account is defined by record type), the reason that we are not able to do this using roll up summary fields is because we have multi-currency and dated exchange rates - therefore the option is not available to us - hence I have had to find a coding solution. Everything is set up and appears to be working (sandbox), however it seems to be slow in updating the account - I am sure there must be a neater way of writing this code but I am not sure how. Also, I think I need to take into account Account Merges - how would I do that? So I guess my 2 questions are:

 

1. Is there a better/neater way of writing the below code for both trigger and class?

2. Any insight on what to do if accounts are merged - I would need to update both the old hierarchy and the new one I think

 

Any guidance and assistance here - much appreciated.

This is the trigger to call the class:

---------------------------------------------

trigger RollUpF50Stats on Account (after update, before delete) 
{
for (Account a: Trigger.old) {

    if (a.F50__c == 'Yes') {
    //I am setting up a list to hold the singular root account. There might be a better way of doing this?
    
    if (Trigger.isDelete) {
            String RootAccount = a.ITBgroup__Group_Id__c;
            //Checking if the trigger has already ran in this instance so that we don't get a recurring loop  
            if (RichWF50.F50AlreadyCalled()==FALSE){
                //Calling our class and sending the list of accounts (Which should just be the 1!)
                RichWF50.updateF50root(RootAccount);
            }
    }
    
    if (Trigger.isUpdate) {
                for (Account n: Trigger.new) {
                    if (a.F50__c == 'Yes') {
                    if (n.ITBgroup__Group_Id__c <> a.ITBgroup__Group_Id__c) {
                    
                        String NewRootAccount = n.ITBgroup__Group_Id__c;
                        String OldRootAccount = a.ITBgroup__Group_Id__c;
                
                    //Checking if the trigger has already ran in this instance so that we don't get a recurring loop  
                    if (RichWF50.F50AlreadyCalled()==FALSE){
                        //Calling our class and sending the list of accounts (Which should just be the 1!)
                        RichWF50.updateF50root(NewRootAccount);
                        RichWF50.updateF50root(OldRootAccount);
                    }
                }
                else {
                    String RootAccount = n.ITBgroup__Group_Id__c;
                    if (RichWF50.F50AlreadyCalled()==FALSE){
                        //Calling our class and sending the list of accounts (Which should just be the 1!)
                        RichWF50.updateF50root(RootAccount);
                    }             
            }
            }
            }
    }
    }
    }    
  }

 

-----------------------------------------

This is the Class the trigger is calling:

public class RichWF50 {
   
   //Setting a variable to be false, this is used for the recursion check.
   public static Boolean F50AlreadyCalled=FALSE;
   
   //This method returns the state of the recursion check
   public static boolean F50AlreadyCalled(){
       //returns the variable (I don't even know why I am commenting this as it is so obvious)
       return F50AlreadyCalled;
   }
   
  @future
  public static void updateF50root(String RootAcc){
        //Step 1. Set the public variable to true so that the trigger will not get stuck in a loop.
        F50AlreadyCalled=TRUE;
        
        Account a = new Account();
        
        a = [SELECT Id, Total_Users__c FROM Account WHERE Id =: RootAcc];
            
            System.debug('The ID of the account object is: ' + a.Id);
            
            string id15cr = a.Id;
            
            System.debug('The formatted ID of the account object is: ' + id15cr.substring(0, 15));
            
            //Step 2. Create a list of Accounts 
            List<Account> Accs = [Select Total_Number_of_Seats__c From Account where ITBgroup__Group_Id__c =: id15cr.substring(0, 15)];
        
            Double j = 0;
 
            // Loop through the filtered Accounts and sum up their amounts.
             
             for(Account Acc : Accs)
                {
                    If (Acc.Total_Number_of_Seats__c != Null)
                    {
                        j += Acc.Total_Number_of_Seats__c;
                    }
                }
                
            System.debug('Top account actual before: ' + a.Total_Users__c);
            System.debug('Calculated new amount of users: ' + j);
            a.Total_Users__c  = j;
            System.debug('Top account after: ' + a.Total_Users__c);
            
            //Step 3. Create a list of Open Opportunities 
            
            List<Opportunity> Opps = [Select Opportunity_Number_of_Seats__c, Converted_Value__c From Opportunity where (ForecastCategoryName != 'Omitted' AND ForecastCategoryName != 'Closed') AND Group_ID2__c =: id15cr.substring(0, 15)];
 
            Double k = 0;
            Double L = 0;
 
            // Loop through the filtered Opportunities and sum up their amounts.
             for(Opportunity Opp : Opps)
             {
                If (Opp.Opportunity_Number_of_Seats__c != Null)
                {
                    k += Opp.Opportunity_Number_of_Seats__c;
                }
            }
            
            a.Total_Opp_Seats_del__c  = k;

            for(Opportunity Opp : Opps)
            {
                If (Opp.Converted_Value__c != Null)
                {
                    L += Opp.Converted_Value__c;
                }
            }
            
            a.Total_Opp_Value__c  = L;
            
            //Step 4. Create a list of Won Opportunities 
            List<Opportunity> Oppys = [Select Opportunity_Number_of_Seats__c,Converted_Value__c, convertCurrency(Amount)From Opportunity where ForecastCategoryName = 'Closed' AND Group_ID2__c =: id15cr.substring(0, 15)];
 
            Double m = 0;
            Double n = 0;
   
            // Loop through the filtered Opportunities and sum up their amounts.
            for(Opportunity Opp : Oppys)
            {
                If (Opp.Converted_Value__c != Null)
                {
                    m += Opp.Converted_Value__c;
                }
            }
            a.Total_Won_Opp_Value__c  = m;
            
            for(Opportunity Opp : Oppys)
            {
                If (Opp.Opportunity_Number_of_Seats__c != Null)
                {
                    n += Opp.Opportunity_Number_of_Seats__c;
                }
            }
            a.Total_Seats_All__c = n;
            
             //Step 5. Create a list of Lost Opportunities 
            List<Opportunity> Oppys2 = [Select Opportunity_Number_of_Seats__c,Converted_Value__c, convertCurrency(Amount)From Opportunity where StageName = '99 - Closed lost' AND Group_ID2__c =: id15cr.substring(0, 15)];
 
            Double P = 0;
            Double Q = 0;
   
            // Loop through the filtered Opportunities and sum up their amounts.
            for(Opportunity Opp : Oppys2)
            {
                If (Opp.Converted_Value__c != Null)
                {
                    P += Opp.Converted_Value__c;
                }
            }
            a.Total_Value_Lost__c  = P;
            
            for(Opportunity Opp : Oppys2)
            {
                If (Opp.Opportunity_Number_of_Seats__c != Null)
                {
                    Q += Opp.Opportunity_Number_of_Seats__c;
                }
            }
            a.Total_Seats_Lost__c = Q;
            
        update a;
         
    } 
}

 

  • January 31, 2012
  • Like
  • 0

Hi - I am trying to copy the converted currency amount on opportunity to a custom field.  My purpose for doing this is to use the custom field in another trigger to roll up information to the Top Level Account - I can't use SF roll up features because we use multi-currency and dated exchange rates - at this point I am not concerned about the dated exchange rates - but as I say it limits what I can in SF.  

 

I am very new to Apex Code but have given it a bash, I have the following code - which does work - however I have it on before update and therefore it is taking the amount value from the opportunity - I really need to either change this to an after update trigger or modify my code to look at the new value.  I get an error when I change to after update saying that the record is read only.  If someone is able to point me in the right direction, it would be much appreciated.  Thank you.

 

trigger CopyConvertedValue on Opportunity (before update) {

 

Integer i = 0;
Opportunity Oppy = Trigger.new[i];

String intTest = Trigger.new[i].ID;

//Step 2. Create a list of Opps
List<Opportunity> Oppys = [Select convertCurrency(Amount)From Opportunity where ID =: intTest];

for (Opportunity Opp : oppys)


//Step 3. Update Oppy
Trigger.new[i].Converted_Value__c = Trigger.new[i].Amount;
}

  • January 16, 2012
  • Like
  • 0

Hi, I am trying to create a trigger to start an approval process after insert if a certain field is checked - we are getting this save error: 'Expression cannot be assigned'

 

 

MDFSubmitForApproval on MDF__c (after insert) {

for (MDF__c a : trigger.new) {


if (MDF__c.Submitted__c = 'true') {


Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();app.setObjectId(a.id);
Approval.ProcessResult result = Approval.process(app);
}
}
}

 

Not sure where we are going wrong with this?  Any help much appreciated.

  • September 01, 2011
  • Like
  • 0