• cribis
  • NEWBIE
  • 25 Points
  • Member since 2010

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

I am working on a trigger to redirect a lookup based on a picklist value (field: Measurement system with values 'english' and 'metric'. The intended, finished workflow will be when the user has chosen one of the two values and clicks save, the system will repopulate the lookup with the appropriate record based on the original value.

 

Logially, the system will look up the value based on the product, metric family, and the new value converted from the original value multiplied by the conversion rate.

 

The specific field names are:

 

The obje4ctive is to change the Bulk Density according to the Customer Product and the Measurement System. The converted rate will be applied the original Bulk Density to determine the new bulk density. The bulk density field is a lookup.

 

Below is my code:

 

trigger BulkDensityChange on Opportunity(after insert, after update) {
    Set<id> cid = new Set<id>();
    for(Opportunity opp : Trigger.new) {
    System.debug('**** 0 cid id : '+opp.Customer_Product_1__c);
    
        cid.add(opp.Customer_Product_1__c);
    System.debug('**** 1 opp id : '+opp.id);
    }
    List<Customer_Bulk_Density__c> density = [select id, name, Customer_Product__c from Customer_Bulk_Density__c 
                                   Where Customer_Product__c in (
                                      select id from Customer_Product__c)];
                                      
    
 
}

 

Currently I have set up the list relationship between the customer product and  the customer bulk density. I am not sure I have done this correctly as I am trying to link the opportunity, customer product, and bulk density objects together.

 

I believe my next step is to calculate the converted amount from measurement 1 to measurement 2.

 

I would like to write the following:

 

If the new bulk density equals the old bulk density times the conversion rate and is related to the customer product, then populate.

 

The bulk densities will be prpopulated for both the metric and english measurements.

 

My questions are:

 

1. Have I started the trigger correctly, as I have described above?

2. How do I write the next part of the trigger to convert the bulk density values?

  • August 05, 2010
  • Like
  • 0

I am writing a test class and am running into this error:

Error: Compile Error: Illegal assignment from SOBJECT:Customer_Product__c to Id at line 11 column 9

 Here is my test class:

@isTest
private class BulkDensityTest{
    testmethod private static void TestTrigger() {
        Customer_Product__c cp = new Customer_Product__c
            (name = 'apple');
        insert cp;
        
        Customer_Bulk_Density__c  c = new Customer_Bulk_Density__c ();
        c.Name = '4';
        c.Metric_Label__c = 'kg/m3';
        c.Customer_Product__c = cp;
        insert c;
        
        System.debug('c:' + c);
        c = [SELECT ID, Name FROM Customer_Bulk_Density__c  WHERE id = :c.id];
        System.debug('c:' + c);
        System.assertEquals(c.Customer_Product__c, c.Name);
        Profile p = [select id from profile where name='Standard User'];

    User u = new User(alias = 'standt', email='standarduser@testorg.com',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com');
System.runAs(u) {
// The following code runs as user 'u'
System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId()); }
}
     

}

 

Here is the trigger:

 

trigger BulkDensityConversion on Customer_Bulk_Density__c (before insert) {
    Set<Id> bIds = new Set<Id>();

list<Customer_Bulk_Density__c> customerBulkDensityList = new List<Customer_Bulk_Density__c>();

if(StaticClass.doNotExecute ==true)
{
system.debug('Inserting'+StaticClass.doNotExecute);
    for(Customer_Bulk_Density__c c:trigger.new)
    {
     bIds.add(c.id);
     
     if(c.Metric_Label__c =='Lbs./ft3')
     {
     Double conversion = Double.valueof(c.Name) * 16.018;
         Long L1 = conversion.round();
        
      Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
        Metric_Label__c = 'Kg/m3',
        Name = String.Valueof(L1) + String.ValueOf(' ') + String.Valueof('Kg/m3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        );
        customerBulkDensityList.add(s);   
        }
         else
        {
         Double conversion1 = Double.valueof(c.Name) * 1 / 16.018;
              Long L2 = conversion1.round();        
              
         Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
         
        Metric_Label__c = 'Lbs/ft3',
        Name = String.Valueof(L2) + String.ValueOf(' ') + String.Valueof('Lbs./ft3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        
        );
        customerBulkDensityList.add(s);   
        } 
    }
    StaticClass.doNotExecute =false;
    if(!customerBulkDensityList.isEmpty())
    {
        insert customerBulkDensityList;
    }
    
    System.debug('****1 : B Id size '+ bIds.size());
 
  }
  else
  {
  StaticClass.doNotExecute =true;
  }

  }

 

How to I solve the error?

 

Thank you again

  • August 02, 2010
  • Like
  • 0

I am working on a trigger that creates a new record and conducts conversion at the same time, while adding a label at the end of the value. I am now trying to update the source record with the value in the same trigger.

 

 For example. existing record has 60 miles in field a. The trigger will duplicate the record and calculate the miles in to kilometers. The final value in field a on the second record of 100 km. I am having trouble with changing the 60 to 60 miles in the source field on the source record.

 

How do I do this?

 

Here is my trigger that is working successfully to this point:

 

trigger BulkDensityConversion on Customer_Bulk_Density__c (before insert) {
    Set<Id> bIds = new Set<Id>();

list<Customer_Bulk_Density__c> customerBulkDensityList = new List<Customer_Bulk_Density__c>();

if(StaticClass.doNotExecute ==true)
{
system.debug('Inserting'+StaticClass.doNotExecute);
    for(Customer_Bulk_Density__c c:trigger.new)
    {
     bIds.add(c.id);
     
     if(c.Metric_Label__c =='Lbs./ft3')
     {
     Double conversion = Double.valueof(c.Name) * 16.018;
        
      Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
        Metric_Label__c = 'Kg/m3',
        Name = String.Valueof(conversion) + String.ValueOf(' ') + String.Valueof('Kg/m3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        );
        customerBulkDensityList.add(s);   
        }
         else
        {
         Double conversion1 = Double.valueof(c.Name) * 1 / 16.018;
        
         Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
         
        Metric_Label__c = 'Lbs/ft3',
        Name = String.Valueof(conversion1) + String.ValueOf(' ') + String.Valueof('Lbs./ft3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        
        );
        customerBulkDensityList.add(s);   
        } 
    }
    StaticClass.doNotExecute =false;
    if(!customerBulkDensityList.isEmpty())
    {
        insert customerBulkDensityList;
    }
    
    System.debug('****1 : B Id size '+ bIds.size());
 
  }
  else
  {
  StaticClass.doNotExecute =true;
  }

}

 

Thank you

I am wortking on a conversion tool for a custom object (Customer Bulk Density). the thought process is that if a user create a bulk density record in Lbs/ft3, Salesforce will create a duplicate record in Kg/m3. Currently I am trying to write the trigger to create the new record, but am running into the following error:

 

Error: Compile Error: Method does not exist or incorrect signature: Customer_Bulk_Density__c.put(Id, SOBJECT:Customer_Bulk_Density__c) at line 15 column 7

 

Below is the code:

 

trigger BulkDensityConversion on Customer_Bulk_Density__c (after insert) {
    Set<Id> bIds = new Set<Id>();
    for(Customer_Bulk_Density__c c:trigger.new){
    bIds.add(c.id);
    }
    
    System.debug('****1 : B Id size '+ bIds.size());
    List<Customer_Bulk_Density__c> c = [Select id, name, Customer_Product__c, Customer_Product_2__c, Customer_Product_3__c from Customer_Bulk_Density__c where id in:bIds];
    
    System.debug('****2 : b size '+ bIds.size());
    if (c.size() > 0) {
    List <Customer_Bulk_Density__c> design= new List <Customer_Bulk_Density__c>();
    Map<id, Customer_Bulk_Density__c> capacity = new map<id, Customer_Bulk_Density__c>();
    for(Customer_Bulk_Density__c m: c) {
      Customer_Bulk_Density__c.put(m.id, m);
    }
    
    //Loop through the records and create a Bulk Density Record

    Id n1;

        for(Customer_Bulk_Density__c y : trigger.new) {
        n1 = bulk.get(y.id).WhatId;
        
        Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
        Name = trigger.new[0].name,
        Customer_Product__c=trigger.new[0].Customer_Product__c,
        Customer_Product_2__c=trigger.new[0].Customer_Product_2__c,
        Customer_Product_3__c=trigger.new[0].Customer_Product_3__c
        );
        
        insert s;


       }
        
    }
    }

 

How do I solve this error?

Does anyone display the current currency exchange rate to users from the home page or in another place, than in the administrator setup? I am wanting to make the current exchange rate visible to my users, but I do not want to give them editing rights to the exchange rate.

I am turning on the data currency exchange and am needing to update the exchange rate on each opportunity more frequently than when the amount field on the opportunity is update or when the opportunity is closed. We will be updating the currency exchange rate once a month and need to see all of the opportunity amount (converted) reflect the current currency exchange rate automatically.

 

Has anyone had this type of business requirement?

I have the following trigger that is pulling an address from a custom formula field. into a text field on the opportunity. When the address is pasted onto the opportunity, the address includes the line break syntax <br>, but pastes the entire address on one line.

 

Below is the code for the trigger:

 

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

    Set<Id> UserIds = new Set<Id>();
    for (Opportunity oppo: Trigger.new){
    System.debug('**** 0 userids id : '+oppo.ownerid);
    
        UserIds.add(oppo.ownerId);
     System.debug('**** 1 oppo id : '+oppo.id);
     
     }
    
    Map<Id, User> entries = new Map<Id, User>();
    List<user> us = [select Id, User_Address__c from User where id in :UserIds];
  
    for(Opportunity unity: Trigger.new) {
       unity.Opp_Owner_Address__c = us[0].User_Address__c;
    }
}

 

How do I format the custom field to correctly format the address in the new field?

 

Thank you

I am trying to write a trigger that will check the opportunity ownerid and returns fields from the owner's user record. but I am recieving the following error.

 

Compile Error: Expression cannot be assigned at line -1 column -1  

 

Here is my code:

 

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

    Set<Id> UserIds = new Set<Id>();
    for (Opportunity oppo: Trigger.new){
    System.debug('**** 0 userids id : '+oppo.ownerid);
    
        UserIds.add(oppo.Id);
     System.debug('**** 1 oppo id : '+oppo.id);
     
     }
    
    Map<Id, User> entries = new Map<Id, User>( 
        [select Id, Street from User where id in :UserIds limit 1]);
  
    for(Opportunity unity: Trigger.new) {
       opportunity.Opp_Owner_Address__c = user.street;
    }
}

 

How can this be solved?

 

Thank you,

 

I am working on a trigger to redirect a lookup based on a picklist value (field: Measurement system with values 'english' and 'metric'. The intended, finished workflow will be when the user has chosen one of the two values and clicks save, the system will repopulate the lookup with the appropriate record based on the original value.

 

Logially, the system will look up the value based on the product, metric family, and the new value converted from the original value multiplied by the conversion rate.

 

The specific field names are:

 

The obje4ctive is to change the Bulk Density according to the Customer Product and the Measurement System. The converted rate will be applied the original Bulk Density to determine the new bulk density. The bulk density field is a lookup.

 

Below is my code:

 

trigger BulkDensityChange on Opportunity(after insert, after update) {
    Set<id> cid = new Set<id>();
    for(Opportunity opp : Trigger.new) {
    System.debug('**** 0 cid id : '+opp.Customer_Product_1__c);
    
        cid.add(opp.Customer_Product_1__c);
    System.debug('**** 1 opp id : '+opp.id);
    }
    List<Customer_Bulk_Density__c> density = [select id, name, Customer_Product__c from Customer_Bulk_Density__c 
                                   Where Customer_Product__c in (
                                      select id from Customer_Product__c)];
                                      
    
 
}

 

Currently I have set up the list relationship between the customer product and  the customer bulk density. I am not sure I have done this correctly as I am trying to link the opportunity, customer product, and bulk density objects together.

 

I believe my next step is to calculate the converted amount from measurement 1 to measurement 2.

 

I would like to write the following:

 

If the new bulk density equals the old bulk density times the conversion rate and is related to the customer product, then populate.

 

The bulk densities will be prpopulated for both the metric and english measurements.

 

My questions are:

 

1. Have I started the trigger correctly, as I have described above?

2. How do I write the next part of the trigger to convert the bulk density values?

  • August 05, 2010
  • Like
  • 0

I am working on a trigger that creates a new record and conducts conversion at the same time, while adding a label at the end of the value. I am now trying to update the source record with the value in the same trigger.

 

 For example. existing record has 60 miles in field a. The trigger will duplicate the record and calculate the miles in to kilometers. The final value in field a on the second record of 100 km. I am having trouble with changing the 60 to 60 miles in the source field on the source record.

 

How do I do this?

 

Here is my trigger that is working successfully to this point:

 

trigger BulkDensityConversion on Customer_Bulk_Density__c (before insert) {
    Set<Id> bIds = new Set<Id>();

list<Customer_Bulk_Density__c> customerBulkDensityList = new List<Customer_Bulk_Density__c>();

if(StaticClass.doNotExecute ==true)
{
system.debug('Inserting'+StaticClass.doNotExecute);
    for(Customer_Bulk_Density__c c:trigger.new)
    {
     bIds.add(c.id);
     
     if(c.Metric_Label__c =='Lbs./ft3')
     {
     Double conversion = Double.valueof(c.Name) * 16.018;
        
      Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
        Metric_Label__c = 'Kg/m3',
        Name = String.Valueof(conversion) + String.ValueOf(' ') + String.Valueof('Kg/m3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        );
        customerBulkDensityList.add(s);   
        }
         else
        {
         Double conversion1 = Double.valueof(c.Name) * 1 / 16.018;
        
         Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
         
        Metric_Label__c = 'Lbs/ft3',
        Name = String.Valueof(conversion1) + String.ValueOf(' ') + String.Valueof('Lbs./ft3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        
        );
        customerBulkDensityList.add(s);   
        } 
    }
    StaticClass.doNotExecute =false;
    if(!customerBulkDensityList.isEmpty())
    {
        insert customerBulkDensityList;
    }
    
    System.debug('****1 : B Id size '+ bIds.size());
 
  }
  else
  {
  StaticClass.doNotExecute =true;
  }

}

 

Thank you

I am wortking on a conversion tool for a custom object (Customer Bulk Density). the thought process is that if a user create a bulk density record in Lbs/ft3, Salesforce will create a duplicate record in Kg/m3. Currently I am trying to write the trigger to create the new record, but am running into the following error:

 

Error: Compile Error: Method does not exist or incorrect signature: Customer_Bulk_Density__c.put(Id, SOBJECT:Customer_Bulk_Density__c) at line 15 column 7

 

Below is the code:

 

trigger BulkDensityConversion on Customer_Bulk_Density__c (after insert) {
    Set<Id> bIds = new Set<Id>();
    for(Customer_Bulk_Density__c c:trigger.new){
    bIds.add(c.id);
    }
    
    System.debug('****1 : B Id size '+ bIds.size());
    List<Customer_Bulk_Density__c> c = [Select id, name, Customer_Product__c, Customer_Product_2__c, Customer_Product_3__c from Customer_Bulk_Density__c where id in:bIds];
    
    System.debug('****2 : b size '+ bIds.size());
    if (c.size() > 0) {
    List <Customer_Bulk_Density__c> design= new List <Customer_Bulk_Density__c>();
    Map<id, Customer_Bulk_Density__c> capacity = new map<id, Customer_Bulk_Density__c>();
    for(Customer_Bulk_Density__c m: c) {
      Customer_Bulk_Density__c.put(m.id, m);
    }
    
    //Loop through the records and create a Bulk Density Record

    Id n1;

        for(Customer_Bulk_Density__c y : trigger.new) {
        n1 = bulk.get(y.id).WhatId;
        
        Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
        Name = trigger.new[0].name,
        Customer_Product__c=trigger.new[0].Customer_Product__c,
        Customer_Product_2__c=trigger.new[0].Customer_Product_2__c,
        Customer_Product_3__c=trigger.new[0].Customer_Product_3__c
        );
        
        insert s;


       }
        
    }
    }

 

How do I solve this error?

I am turning on the data currency exchange and am needing to update the exchange rate on each opportunity more frequently than when the amount field on the opportunity is update or when the opportunity is closed. We will be updating the currency exchange rate once a month and need to see all of the opportunity amount (converted) reflect the current currency exchange rate automatically.

 

Has anyone had this type of business requirement?

I am trying to write a trigger that will check the opportunity ownerid and returns fields from the owner's user record. but I am recieving the following error.

 

Compile Error: Expression cannot be assigned at line -1 column -1  

 

Here is my code:

 

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

    Set<Id> UserIds = new Set<Id>();
    for (Opportunity oppo: Trigger.new){
    System.debug('**** 0 userids id : '+oppo.ownerid);
    
        UserIds.add(oppo.Id);
     System.debug('**** 1 oppo id : '+oppo.id);
     
     }
    
    Map<Id, User> entries = new Map<Id, User>( 
        [select Id, Street from User where id in :UserIds limit 1]);
  
    for(Opportunity unity: Trigger.new) {
       opportunity.Opp_Owner_Address__c = user.street;
    }
}

 

How can this be solved?

 

Thank you,