• Maciej Gunia 8
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 19
    Replies
Hello,

I would like to build the visualforce page which will be used as a tab to re-direct the specific user to record. In other words I would like to hard code it in the way
IF UserID = 00520000003ZoWk THEN go to "https://emea.salesforce.com/a0z20000007eLqk" 
IF UserID = 00520000003cCNn THEN go to "https://emea.salesforce.com/a0z20000059eQtF"

Could someone help me with that please?

Regards,
Maciej

Hello,

I was just wondering if it's possible to build the apex trigger which will grab the Amount (converted) from the Opportunity and copy it to the Campaign which the opportunity is related to? 
 

The reason why I am asking is if you use multi currencies, then let's say Opportunities in USD are being convereted to the Coroporate currency (in our case GBP). On the Campaign level there is a field called "total value of won opportunities". But this field brings the value according to the current exchange rate. Where Amount (converted)  brings the historical values (i.e. amount converted to the exchange rate from March - as it was the time when the opportunity was closed).

So I was thinking if Apex Trigger could help or Amount (Converted) can't be used anywhere?

Regards,
Maciej

I have a trigger which works in the sandbox. The workflow checks the field in the campaign level and compares it with the custom setting. If it matches, then it returns the target to the DS Multiplier field. The trigger looks as follows

trigger PopulateTarget on Campaign (before insert, before update) 
{
for(Campaign campaign : Trigger.new)
{
    if (String.isNotBlank(campaign.Apex_Calculator__c) == true)
    {
        DSTargets__c targetInstance = DSTargets__c.getInstance(campaign.Apex_Calculator__c);
        {
            String target = targetInstance .Target__c;
             campaign.DS_Target_Multiplier__c = Target;
        }
    }
}
}

However, I had problems to write a proper test to this and asked for the help on the internet. I received the test

@isTest
private class testPopulateTarget{
static testMethod void testMethod1(){

      // Load the Custom Settings
      DSTargets__c testSetting = new DSTargets__c(Name='Africa - 10 Weeks; CW 10',Target__c='0.1538', SetupOwnerId = apexCalculatorUserId);
      insert testSetting;


       // Create Campaign. Since it would execute trigger, put it in start and stoptests
       Test.startTest();
           Campaign testCamp = new Campaign();
           // populate all reqd. fields.
           testCamp.Name = 'test DS campaign';
           testCamp.RecordTypeId = '012200000001b3v';
           testCamp.Started_Campaign_weeks_before_Event__c = '12 Weeks';
           testCamp.ParentId= '701g0000000EZRk';


           insert testCamp;
       Test.stopTest();
       testCamp = [Select ID,Apex_Calculator__c,DS_Target_Multiplier__c from Campaign where Id = :testCamp.Id];
       system.assertEquals(testCamp.DS_Target_Multiplier__c,testSetting.Target__c);// assert that target is populated right

}

}

Such test returns the error "Compile Error: Variable does not exist: apexCalculatorUserId at line 6 column 122". If I remove that ApexCalculator part System.assertEquals then the test passes. However it covers 4/6 part of the code (which is 66%). 

As I was able to find out that apexCalculatorUserId has not been defined. I was suggested to look at the constructor DSTargets__c and see what kind of ID it is expecting there. However, my knowledge doesn't allow me to amend it this way it will work. Would any of you help me to amend it as it seems I am on the last corner before the finish line and am hopeless with this test?

Regards,
Maciej
Hello,

I would like to create the custom object called „Management Panel”. It would be the object where few people from management could go and see the most important stuff for them gathered in one place. The idea is that I will create 1 record for 1 senior managers. They will have separate page layouts – so they will see different fields.
What I would like to do is a visualforce page which will allow me to identify Current User ID and match it with the Record Owner ID. So by clicking the visualforce tab “Management Panel” they would be taken directly to their record. I assume this would be a very few lines of the code, where I could hard code the ids (saying if ID is equal to this, then bring this record). Could anyone help me with that please?

Regards,
Maciej
Hello,

I have a trigger on the campaigns level. In this post I explained the details of the solution needed - https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AbhHIAS but in few words I have the field where its value should match the custom setting and if yes, then it should bring the target value from the custom value. The trigger looks like that:

trigger PopulateTarget on Campaign (before insert, before update) 
{
    for(Campaign campaign : Trigger.new)
    {
        if (String.isNotBlank(campaign.Apex_Calculator__c) == true)
        {
            String target = DSTargets__c.getInstance(campaign.Apex_Calculator__c).Target__c;
            campaign.DS_Target_Multiplier__c = Target;
        }
    }
}

The trigger at the beining was generating the error but I amended the system this way, that it works fine and provides me with the relevant information. I've made the test class for this trigger and it fails returning me the error. Here is the test class and the error message:

TEST CLASS:

@isTest
private class testPopulateTarget{
   static testMethod void testMethod1(){
       
          // Load the Custom Settings
          DSTargets__c testSetting = new DSTargets__c(Name='Africa - 10 Weeks; CW 10',Target__c='0.1538');
          insert testSetting;
           
          
           // Create Campaign. Since it would execute trigger, put it in start and stoptests
           Test.startTest();
               Campaign testCamp = new Campaign();
               // populate all reqd. fields.
               testCamp.Name = 'test DS campaign';
               testCamp.RecordTypeId = '012200000001b3v';
               testCamp.Started_Campaign_weeks_before_Event__c = '12 Weeks';
               testCamp.ParentId= '701g0000000EZRk';


               insert testCamp;
           Test.stopTest();
           testCamp = [Select ID,Apex_Calculator__c,DS_Target_Multiplier__c from Campaign where Id = :testCamp.Id];
           system.assertEquals(testCamp.DS_Target_Multiplier__c,testSetting.Target__c);// assert that target is populated right

}

}


ERROR MESSAGE:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopulateTarget: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.PopulateTarget: line 7, column 1: []

I tried to re-produce this test by myself and there is no error in Salesforce. Could anyone of you help me with that?

Regards,
Maciej
Hello, 

I wanted to set up a flexible targets for Sales Department. Thanks to good people on the internet I was provided with the code which does the job for me:

trigger PopulateTarget on Campaign (before insert, before update)
{
    Map <String, Id> recordTypes = new Map <String, Id> ();

    for (RecordType recordType : [SELECT Id, DeveloperName FROM RecordType WHERE sObjectType = 'Campaign'])
    {
        if (recordType.DeveloperName == 'Conference')
        {
            recordTypes.put(recordType.DeveloperName, recordType.Id);
        }
    }

    for(Campaign campaign : Trigger.new)
    {
        // Make sure that the campaign record type is not in the map (in the map we keep the ones that we want to exclude)
        if (recordTypes.get(campaign.RecordTypeId) == null && String.isNotBlank(campaign.Apex_Calculator__c) == true)
        {
            String target = DSTargets__c.getInstance(campaign.Apex_Calculator__c).Target__c;
            campaign.DS_Target_Multiplier__c = Target;
        }
    }
}

I have a custom setting called DSTargets where I store the information (details can be found here: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AbhHIAS). I set up the system this way it works perfectly in Sandbox. I wanted to deploy the trigger to Production but it occured I need to have the Apex Test Class to test this trigger (which I assume it is something very obvious for experienced developer but not for person like me, who starts to crawl with code usage in SF).

Could anyone be so kind and help me as I don't have any idea about testing triggers? It would be such a shame if this would fail on the last corner before the finish line as so much work has been done to achieve it.

Regards,
Maciej
Hello,

I would like to create the solution which will give me the possibility to assign flexible targets for campaigns. I was trying to solve it via formula field but it occurred to be too complex and I was advised it needs to be the apex trigger.

What I have are values 40 values which indicate the targets for:
North America 12, 11,10…2 weeks before event
Latin America 12, 11,10…2 weeks before event
Europe 12, 11,10…2 weeks before event
Africa 12, 11,10…2 weeks before event

As far as I understand, I will have to create the custom setting of list type, so then I could query it in the apex trigger. Unfortunately, my knowledge of apex coding is a bit limited. Could anyone help me with the apex trigger code for such solution?

Regards,
Maciej
Hello All,

I have posted my question on the success community page (https://success.salesforce.com/answers?id=90630000000hyiUAAQ) but it seems developer forum is the appropriate place. I wanted to implement “movable” weekly targets for our sales department. The reason behind this is that Sales guys work on a different market and for instance the customer behaviour in Latin America is different than in Europe (in Latam people tend to book much later). Our Sales Director did the 3 year analysis and we came up with the % per week which the Sales rep should achieve according to the region he/she is currently working on. I thought I have an idea but Salesforce limitation seem to spoil it and I would like to ask you for the advise how I could solve this problem

GOAL:
We wanted to be able to achieve two things – first, set up weekly targets for the sales rep according to the region the person operates. Second, be able to specify how many weeks to the event the sales rep joined the campaign. Standard procedure is 12 weeks before the event and steps out 2 weeks before event starts. But it is common that the sales rep finishes the first campaign and steps in to the other campaign in less than 12 weeks before the event. In such situation the percentage from the missing weeks should be added equally to the rest remaining weeks.

MY CURRENT SOLUTION SO FAR:
I knew probably trigger would be the best solution. However, the fact I don’t feel comfortable with triggers and we also have some additional solutions prepared by 3rd party I came up with the much more primitive idea. I decided to create a formula field which will provide the appropriate values according per week per region. Here is the formula:

IF( ISPICKVAL( Parent.Event_Region__c , "Europe"), CASE(FLOOR( Weeks_Remaining__c ),12,0.13,
11,0.08,
10,0.12,
9,0.11,
8,0.13,
7,0.14,
6,0.09,
5,0.07,
4,0.08,
3,0.05,0), IF( ISPICKVAL( Parent.Event_Region__c , "North America"), CASE(FLOOR( Weeks_Remaining__c ),12,0.09,
11,0.11,
10,0.13,
9,0.14,
8,0.12,
7,0.08,
6,0.11,
5,0.09,
4,0.07,
3,0.06,0),IF( ISPICKVAL( Parent.Event_Region__c , "Africa"), CASE(FLOOR( Weeks_Remaining__c ),12,0.09,
11,0.10,
10,0.13,
9,0.12,
8,0.10,
7,0.07,
6,0.06,
5,0.11,
4,0.08,
3,0.14,0),IF( ISPICKVAL( Parent.Event_Region__c , "Latin America"), CASE(FLOOR( Weeks_Remaining__c ),12,0.09,
11,0.08,
10,0.11,
9,0.12,
8,0.13,
7,0.11,
6,0.14,
5,0.10,
4,0.07,
3,0.05,0), -1))))


That brought me the results in a situation the sales person steps in to the campaign 12 weeks before the event. To simulate that somebody steps in later I decided to create 10 fields and amend the existing formula to have 12,11,10 (…), 2 weeks. I also created the pick list field where the sales rep would choose when he/she stepped in to the campaign in weeks. All the formula fields were meant to be hidden from the page layout and I wanted to create the “Weekly target” field which would check the value from the weeks field and according to that provide the proper values from one of the 10 calculation fields.

THE PROBLEM:
As far as 10 calculating fields are in the 5000 character limits, then the Weekly target formula I was trying to implement returned the error of exceeded number of characters. That spoils my solution making it useless. I assume probably trigger would help here. Could you please help me with your ideas and if indeed my assumption are correct and the trigger is the only option could you be so kind and explain me how should I do this?

Regards,
Maciej
Hello,

I would like to build the visualforce page which will be used as a tab to re-direct the specific user to record. In other words I would like to hard code it in the way
IF UserID = 00520000003ZoWk THEN go to "https://emea.salesforce.com/a0z20000007eLqk" 
IF UserID = 00520000003cCNn THEN go to "https://emea.salesforce.com/a0z20000059eQtF"

Could someone help me with that please?

Regards,
Maciej
I have a trigger which works in the sandbox. The workflow checks the field in the campaign level and compares it with the custom setting. If it matches, then it returns the target to the DS Multiplier field. The trigger looks as follows

trigger PopulateTarget on Campaign (before insert, before update) 
{
for(Campaign campaign : Trigger.new)
{
    if (String.isNotBlank(campaign.Apex_Calculator__c) == true)
    {
        DSTargets__c targetInstance = DSTargets__c.getInstance(campaign.Apex_Calculator__c);
        {
            String target = targetInstance .Target__c;
             campaign.DS_Target_Multiplier__c = Target;
        }
    }
}
}

However, I had problems to write a proper test to this and asked for the help on the internet. I received the test

@isTest
private class testPopulateTarget{
static testMethod void testMethod1(){

      // Load the Custom Settings
      DSTargets__c testSetting = new DSTargets__c(Name='Africa - 10 Weeks; CW 10',Target__c='0.1538', SetupOwnerId = apexCalculatorUserId);
      insert testSetting;


       // Create Campaign. Since it would execute trigger, put it in start and stoptests
       Test.startTest();
           Campaign testCamp = new Campaign();
           // populate all reqd. fields.
           testCamp.Name = 'test DS campaign';
           testCamp.RecordTypeId = '012200000001b3v';
           testCamp.Started_Campaign_weeks_before_Event__c = '12 Weeks';
           testCamp.ParentId= '701g0000000EZRk';


           insert testCamp;
       Test.stopTest();
       testCamp = [Select ID,Apex_Calculator__c,DS_Target_Multiplier__c from Campaign where Id = :testCamp.Id];
       system.assertEquals(testCamp.DS_Target_Multiplier__c,testSetting.Target__c);// assert that target is populated right

}

}

Such test returns the error "Compile Error: Variable does not exist: apexCalculatorUserId at line 6 column 122". If I remove that ApexCalculator part System.assertEquals then the test passes. However it covers 4/6 part of the code (which is 66%). 

As I was able to find out that apexCalculatorUserId has not been defined. I was suggested to look at the constructor DSTargets__c and see what kind of ID it is expecting there. However, my knowledge doesn't allow me to amend it this way it will work. Would any of you help me to amend it as it seems I am on the last corner before the finish line and am hopeless with this test?

Regards,
Maciej
Hello,

I have a trigger on the campaigns level. In this post I explained the details of the solution needed - https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AbhHIAS but in few words I have the field where its value should match the custom setting and if yes, then it should bring the target value from the custom value. The trigger looks like that:

trigger PopulateTarget on Campaign (before insert, before update) 
{
    for(Campaign campaign : Trigger.new)
    {
        if (String.isNotBlank(campaign.Apex_Calculator__c) == true)
        {
            String target = DSTargets__c.getInstance(campaign.Apex_Calculator__c).Target__c;
            campaign.DS_Target_Multiplier__c = Target;
        }
    }
}

The trigger at the beining was generating the error but I amended the system this way, that it works fine and provides me with the relevant information. I've made the test class for this trigger and it fails returning me the error. Here is the test class and the error message:

TEST CLASS:

@isTest
private class testPopulateTarget{
   static testMethod void testMethod1(){
       
          // Load the Custom Settings
          DSTargets__c testSetting = new DSTargets__c(Name='Africa - 10 Weeks; CW 10',Target__c='0.1538');
          insert testSetting;
           
          
           // Create Campaign. Since it would execute trigger, put it in start and stoptests
           Test.startTest();
               Campaign testCamp = new Campaign();
               // populate all reqd. fields.
               testCamp.Name = 'test DS campaign';
               testCamp.RecordTypeId = '012200000001b3v';
               testCamp.Started_Campaign_weeks_before_Event__c = '12 Weeks';
               testCamp.ParentId= '701g0000000EZRk';


               insert testCamp;
           Test.stopTest();
           testCamp = [Select ID,Apex_Calculator__c,DS_Target_Multiplier__c from Campaign where Id = :testCamp.Id];
           system.assertEquals(testCamp.DS_Target_Multiplier__c,testSetting.Target__c);// assert that target is populated right

}

}


ERROR MESSAGE:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopulateTarget: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.PopulateTarget: line 7, column 1: []

I tried to re-produce this test by myself and there is no error in Salesforce. Could anyone of you help me with that?

Regards,
Maciej
Hello, 

I wanted to set up a flexible targets for Sales Department. Thanks to good people on the internet I was provided with the code which does the job for me:

trigger PopulateTarget on Campaign (before insert, before update)
{
    Map <String, Id> recordTypes = new Map <String, Id> ();

    for (RecordType recordType : [SELECT Id, DeveloperName FROM RecordType WHERE sObjectType = 'Campaign'])
    {
        if (recordType.DeveloperName == 'Conference')
        {
            recordTypes.put(recordType.DeveloperName, recordType.Id);
        }
    }

    for(Campaign campaign : Trigger.new)
    {
        // Make sure that the campaign record type is not in the map (in the map we keep the ones that we want to exclude)
        if (recordTypes.get(campaign.RecordTypeId) == null && String.isNotBlank(campaign.Apex_Calculator__c) == true)
        {
            String target = DSTargets__c.getInstance(campaign.Apex_Calculator__c).Target__c;
            campaign.DS_Target_Multiplier__c = Target;
        }
    }
}

I have a custom setting called DSTargets where I store the information (details can be found here: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AbhHIAS). I set up the system this way it works perfectly in Sandbox. I wanted to deploy the trigger to Production but it occured I need to have the Apex Test Class to test this trigger (which I assume it is something very obvious for experienced developer but not for person like me, who starts to crawl with code usage in SF).

Could anyone be so kind and help me as I don't have any idea about testing triggers? It would be such a shame if this would fail on the last corner before the finish line as so much work has been done to achieve it.

Regards,
Maciej
Hello,

I would like to create the solution which will give me the possibility to assign flexible targets for campaigns. I was trying to solve it via formula field but it occurred to be too complex and I was advised it needs to be the apex trigger.

What I have are values 40 values which indicate the targets for:
North America 12, 11,10…2 weeks before event
Latin America 12, 11,10…2 weeks before event
Europe 12, 11,10…2 weeks before event
Africa 12, 11,10…2 weeks before event

As far as I understand, I will have to create the custom setting of list type, so then I could query it in the apex trigger. Unfortunately, my knowledge of apex coding is a bit limited. Could anyone help me with the apex trigger code for such solution?

Regards,
Maciej
Hello All,

I have posted my question on the success community page (https://success.salesforce.com/answers?id=90630000000hyiUAAQ) but it seems developer forum is the appropriate place. I wanted to implement “movable” weekly targets for our sales department. The reason behind this is that Sales guys work on a different market and for instance the customer behaviour in Latin America is different than in Europe (in Latam people tend to book much later). Our Sales Director did the 3 year analysis and we came up with the % per week which the Sales rep should achieve according to the region he/she is currently working on. I thought I have an idea but Salesforce limitation seem to spoil it and I would like to ask you for the advise how I could solve this problem

GOAL:
We wanted to be able to achieve two things – first, set up weekly targets for the sales rep according to the region the person operates. Second, be able to specify how many weeks to the event the sales rep joined the campaign. Standard procedure is 12 weeks before the event and steps out 2 weeks before event starts. But it is common that the sales rep finishes the first campaign and steps in to the other campaign in less than 12 weeks before the event. In such situation the percentage from the missing weeks should be added equally to the rest remaining weeks.

MY CURRENT SOLUTION SO FAR:
I knew probably trigger would be the best solution. However, the fact I don’t feel comfortable with triggers and we also have some additional solutions prepared by 3rd party I came up with the much more primitive idea. I decided to create a formula field which will provide the appropriate values according per week per region. Here is the formula:

IF( ISPICKVAL( Parent.Event_Region__c , "Europe"), CASE(FLOOR( Weeks_Remaining__c ),12,0.13,
11,0.08,
10,0.12,
9,0.11,
8,0.13,
7,0.14,
6,0.09,
5,0.07,
4,0.08,
3,0.05,0), IF( ISPICKVAL( Parent.Event_Region__c , "North America"), CASE(FLOOR( Weeks_Remaining__c ),12,0.09,
11,0.11,
10,0.13,
9,0.14,
8,0.12,
7,0.08,
6,0.11,
5,0.09,
4,0.07,
3,0.06,0),IF( ISPICKVAL( Parent.Event_Region__c , "Africa"), CASE(FLOOR( Weeks_Remaining__c ),12,0.09,
11,0.10,
10,0.13,
9,0.12,
8,0.10,
7,0.07,
6,0.06,
5,0.11,
4,0.08,
3,0.14,0),IF( ISPICKVAL( Parent.Event_Region__c , "Latin America"), CASE(FLOOR( Weeks_Remaining__c ),12,0.09,
11,0.08,
10,0.11,
9,0.12,
8,0.13,
7,0.11,
6,0.14,
5,0.10,
4,0.07,
3,0.05,0), -1))))


That brought me the results in a situation the sales person steps in to the campaign 12 weeks before the event. To simulate that somebody steps in later I decided to create 10 fields and amend the existing formula to have 12,11,10 (…), 2 weeks. I also created the pick list field where the sales rep would choose when he/she stepped in to the campaign in weeks. All the formula fields were meant to be hidden from the page layout and I wanted to create the “Weekly target” field which would check the value from the weeks field and according to that provide the proper values from one of the 10 calculation fields.

THE PROBLEM:
As far as 10 calculating fields are in the 5000 character limits, then the Weekly target formula I was trying to implement returned the error of exceeded number of characters. That spoils my solution making it useless. I assume probably trigger would help here. Could you please help me with your ideas and if indeed my assumption are correct and the trigger is the only option could you be so kind and explain me how should I do this?

Regards,
Maciej