• Jill Hedberg
  • NEWBIE
  • 25 Points
  • Member since 2013

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

Hi,

 

I know it is not possible to select multiple values from a lookup fields, but there must be a way to make this possible anyway.

 

On each contract we want to be able to specify all products that are included in that specific contact.

First I created a lookup field that relates to the products in the pricebook. That worked, but then I realized that we needed to select multiple values, so I created a mullti select picklist instead. The problem then is that we update and add products every now and then, and every time I would then need to remember to update the picklist with the correct/new values. This is not the ultimate way to do it, since it includes a lot of manual work. I am sure there must be a smart way to do this. Just not able to figure it out myself :) 

 

Could you please help me figure out a good way?

 

Thanks!

 

Hi,

 

I have a trigger that ensures a delivery contact is added to the opportunity. I now want to make the trigger NOT fire when a Finance user edits the opportunity. So somehow I want to add NOT profileId = '00e20000000me3Q'. So that Finance users can go in and change stuff without having to add a delivery contact, but everyone else have to.

 

Where would I add this? Can you use NOT in apex code?

 

 

Here is my trigger:

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

    //map to keep track of the contact_required = 1
    Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>();

    //Trigger.new is an array of opportunities 
    //and adds any that have Contact_Required = 1 to the oppy_contact Map
    for (Integer i = 0; i < Trigger.new.size(); i++) {
        System.debug('*****Required? ' + Trigger.new[i].contact_required__c);
        if  (Trigger.new[i].contact_required__c == 1) {
            oppy_contact.put(Trigger.new[i].id,Trigger.new[i]);
        }
    }

    //map to keep track of the opportunity contact roles
    map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>();

    //select OpportunityContactRoles for the opportunities with contact role required 

    List<OpportunityContactRole> roles = [select OpportunityId, Role from OpportunityContactRole
        where (OpportunityContactRole.Role ='Delivery Contact') and OpportunityContactRole.OpportunityId
        in :oppy_contact.keySet()];


    for (OpportunityContactRole ocr : roles) {
        //puts the contact roles in the map with the Opportunity ID as the key
        oppycontactroles.put(ocr.OpportunityId,ocr);
    }

    // Loop through the opportunities and check if they exists in the contact roles map or contact role isn't required    
String OppRectypeId = [SELECT Id, Name FROM RecordType WHERE Sobjecttype = 'Opportunity' AND Name = 'License Opportunity'].Id;

for (Opportunity oppy : system.trigger.new) 
{
    if(Oppy.RecordTypeId == OppRectypeId)
    {
        if (oppy.contact_required__c ==1 && !oppycontactroles.containsKey(oppy.id))
        {
            oppy.addError('No Delivery Contact exists. Please go to the Contact Roles area and select a delivery contact before you can move on to stage "A6 - Closed Won".');
        }
    }
}   
 }

 

Hi!

 

I have a trigger that converts products in an opportunity to assets in the account when the opportunity moves to the stage Closed Won. This part works good.

However, when a product is converted to an asset for that account it gets marked as Converted (Checkbox). If another opportunity (under the same account) with for example additional users for that same product is closed it does not add anything to the assets for the account today.

 

What I want it to do is: IF Product X is already converted to Asset X on the account - then update the quantity of existing Asset X from the last opportunity Closed Won + quantity from Product X for the newly Closed Won opportunity.

 

Old Asset X (Quantity10) + New Product X (Quantity 5) = Old Asset X (Quantity 15).

 

Help please! :)

 

My Trigger:

trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
     for(Opportunity o: trigger.new){ 
      if(o.isWon == true && o.HasOpportunityLineItem == true && o.RecordTypeId == '012200000004fxZ'){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select Total_Price__c, Cost__c, Quantity, Revenue_Type__c, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_Asset__c  
                                      From OpportunityLineItem 
                                      where OpportunityId = :opptyId and Converted_to_Asset__c = false];
         Asset[] ast = new Asset[]{};
         Asset a = new Asset();
         for(OpportunityLineItem ol: OLI){
            a = new Asset();
            a.AccountId = o.AccountId;
            a.Product2Id = ol.PricebookEntry.Product2Id;
            a.Quantity = ol.Quantity;
            a.Price =  ol.Total_Price__c;
            a.PurchaseDate = o.CloseDate;
            a.Status = 'A6 - Closed Won';
            a.Description = ol.Description;
            a.Name = ol.PricebookEntry.Product2.Name;
            ast.add(a);
            ol.Converted_to_Asset__c = true;
       }
      update OLI; 
      insert ast;
     }
    }
}

 

Hi,

 

Could you please help me write a test class for my trigger? I managed to get 10% covered, but since I am not a programmer I am having a hard time understanding how to correct it to get more. Thank you in advance!

 

This is my Trigger:

trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
     for(Opportunity o: trigger.new){ 
      if(o.isWon == true && o.HasOpportunityLineItem == true && o.RecordTypeId == '012200000004fxZ'){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_Asset__c  
                                      From OpportunityLineItem 
                                      where OpportunityId = :opptyId and Converted_to_Asset__c = false];
         Asset[] ast = new Asset[]{};
         Asset a = new Asset();
         for(OpportunityLineItem ol: OLI){
            a = new Asset();
        a.AccountId = o.AccountId;
            a.Product2Id = ol.PricebookEntry.Product2Id;
            a.Quantity = ol.Quantity;
            a.Price =  ol.UnitPrice;
            a.PurchaseDate = o.CloseDate;
            a.Status = 'Purchased';
            a.Description = ol.Description;
            a.Name = ol.PricebookEntry.Product2.Name;
            ast.add(a);
            ol.Converted_to_Asset__c = true;
       }
      update OLI; 
      insert ast;
     }
    }
}

 

I have this Apex Trigger which works good. However I want it to only be valid for license opportunities (all other record types should be able to close deal without having to add Delivery Contact), so I want to add $RecordType.Name = "License Opportunity" somewhere, but don't know where or how.

 

Anyone who has a solution for this? :)

 

This is the trigger:

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

//map to keep track of the contact_required = 1
Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>();

//Trigger.new is an array of opportunities
//and adds any that have Contact_Required = 1 to the oppy_contact Map
for (Integer i = 0; i < Trigger.new.size(); i++) {
System.debug('*****Required? ' + Trigger.new[i].contact_required__c);
if (Trigger.new[i].contact_required__c == 1) {
oppy_contact.put(Trigger.new[i].id,Trigger.new[i]);
}
}

//map to keep track of the opportunity contact roles
map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>();

//select OpportunityContactRoles for the opportunities with contact role required

List<OpportunityContactRole> roles = [select OpportunityId, Role from OpportunityContactRole
where (OpportunityContactRole.Role ='Delivery Contact') and OpportunityContactRole.OpportunityId
in :oppy_contact.keySet()];


for (OpportunityContactRole ocr : roles) {
//puts the contact roles in the map with the Opportunity ID as the key
oppycontactroles.put(ocr.OpportunityId,ocr);
}

// Loop through the opportunities and check if they exists in the contact roles map or contact role isn't required
for (Opportunity oppy : system.trigger.new) {
//system.debug('List oppy Id - '+oppy.id);
if (oppy.contact_required__c ==1 && !oppycontactroles.containsKey(oppy.id))
{
oppy.addError('No Delivery Contact exists. Please go to the Contact Roles area and select a delivery contact before you can move on to stage "A6 - Closed Won".');
}
} //for
}

 

Hi,

 

Could you please help me write an IF statement (I think that's what I need?) for my Visualforce email template?

 

I have a VF email template that (among other things) pulls all information from the opportunity contact role related list. What I really would like is for it to just pull the information from one specific role = "Delivery Contact". So that if several roles are specified in the list the others will not show up in my email, and if the role "Delivery Contact" is not specified at all in the opportunity contact role related list  the table is left blank.

 

Is it an IF statement I need, and how would it look?

 

This is my code:

 

<p>
<table border="0" width="560">
<tr >
<th>Role</th><th>Name</th><th>Email</th><th>Phone</th><th>Primary Contact?</th>
</tr>
<apex:repeat var="ContactRole" value="{!relatedTo.OpportunityContactRoles}">
<tr>
<td>{!ContactRole.Role}</td>
<td>{!ContactRole.Contact.Name}</td>
<td>{!ContactRole.Contact.Email}</td>
<td>{!ContactRole.Contact.Phone}</td>
<td>{!ContactRole.IsPrimary}</td>
</tr>
</apex:repeat>
</table>
</p>

 

 Thanks in advance!

Hi!

 

I want to get the name, email address and phone number of the person marked as primary contact on the Contact Roles related list in the opportunity into my Visualforce email template.

 

I have created this code:

<apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
{!ContactRole.Contact.Name}, {!ContactRole.Contact.Title}, {!ContactRole.Contact.Email}, {!ContactRole.Contact.Phone},
</apex:repeat>

 

but it lists ALL people in the Contact roles related list, and I just want the primary contact. How can I accomplish this?

Hi,

 

We are not able to use the deploy function at our company because of a trigger on the production server that has 0% code coverage. I am an administrator and have never had to write test code before. Have read everything I can about how to do it, but I don't understand the logic. Have tried to write it in every way I could possibly think of. Could you please try to help me write a test class for this?

 

I REALLY appreciate all help I can get!

 

This is the trigger:

trigger subscription on subscription_update__c (after insert) {
 Map<Id,Subscription_Update__c> subsToKill = new Map<Id,Subscription_Update__c>();
 List<Contact> contactsToProcess = new List<Contact>();
 for (Subscription_Update__c sub : Trigger.new) {
  Contact contact = new Contact (    
   id=sub.contact__c,
   Email = sub.email_address__c,
   HasOptedOutOfEmail = sub.Unsubscribe_Me__c,
   Subscription_Type__c = sub.Subscription_Type__c );
   contactsToProcess.add(contact);
  subsToKill.put(sub.id,sub);
 }
 if(contactsToProcess.size()>0){
  try {
   update contactsToProcess;  
   //delete subsToKill.values();
        } catch (exception e) { 
         system.debug(e.getMessage()); 
        }  
 } 
}

 

 

Hi,

 

I have a trigger that ensures a delivery contact is added to the opportunity. I now want to make the trigger NOT fire when a Finance user edits the opportunity. So somehow I want to add NOT profileId = '00e20000000me3Q'. So that Finance users can go in and change stuff without having to add a delivery contact, but everyone else have to.

 

Where would I add this? Can you use NOT in apex code?

 

 

Here is my trigger:

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

    //map to keep track of the contact_required = 1
    Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>();

    //Trigger.new is an array of opportunities 
    //and adds any that have Contact_Required = 1 to the oppy_contact Map
    for (Integer i = 0; i < Trigger.new.size(); i++) {
        System.debug('*****Required? ' + Trigger.new[i].contact_required__c);
        if  (Trigger.new[i].contact_required__c == 1) {
            oppy_contact.put(Trigger.new[i].id,Trigger.new[i]);
        }
    }

    //map to keep track of the opportunity contact roles
    map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>();

    //select OpportunityContactRoles for the opportunities with contact role required 

    List<OpportunityContactRole> roles = [select OpportunityId, Role from OpportunityContactRole
        where (OpportunityContactRole.Role ='Delivery Contact') and OpportunityContactRole.OpportunityId
        in :oppy_contact.keySet()];


    for (OpportunityContactRole ocr : roles) {
        //puts the contact roles in the map with the Opportunity ID as the key
        oppycontactroles.put(ocr.OpportunityId,ocr);
    }

    // Loop through the opportunities and check if they exists in the contact roles map or contact role isn't required    
String OppRectypeId = [SELECT Id, Name FROM RecordType WHERE Sobjecttype = 'Opportunity' AND Name = 'License Opportunity'].Id;

for (Opportunity oppy : system.trigger.new) 
{
    if(Oppy.RecordTypeId == OppRectypeId)
    {
        if (oppy.contact_required__c ==1 && !oppycontactroles.containsKey(oppy.id))
        {
            oppy.addError('No Delivery Contact exists. Please go to the Contact Roles area and select a delivery contact before you can move on to stage "A6 - Closed Won".');
        }
    }
}   
 }

 

Hi!

 

I have a trigger that converts products in an opportunity to assets in the account when the opportunity moves to the stage Closed Won. This part works good.

However, when a product is converted to an asset for that account it gets marked as Converted (Checkbox). If another opportunity (under the same account) with for example additional users for that same product is closed it does not add anything to the assets for the account today.

 

What I want it to do is: IF Product X is already converted to Asset X on the account - then update the quantity of existing Asset X from the last opportunity Closed Won + quantity from Product X for the newly Closed Won opportunity.

 

Old Asset X (Quantity10) + New Product X (Quantity 5) = Old Asset X (Quantity 15).

 

Help please! :)

 

My Trigger:

trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
     for(Opportunity o: trigger.new){ 
      if(o.isWon == true && o.HasOpportunityLineItem == true && o.RecordTypeId == '012200000004fxZ'){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select Total_Price__c, Cost__c, Quantity, Revenue_Type__c, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_Asset__c  
                                      From OpportunityLineItem 
                                      where OpportunityId = :opptyId and Converted_to_Asset__c = false];
         Asset[] ast = new Asset[]{};
         Asset a = new Asset();
         for(OpportunityLineItem ol: OLI){
            a = new Asset();
            a.AccountId = o.AccountId;
            a.Product2Id = ol.PricebookEntry.Product2Id;
            a.Quantity = ol.Quantity;
            a.Price =  ol.Total_Price__c;
            a.PurchaseDate = o.CloseDate;
            a.Status = 'A6 - Closed Won';
            a.Description = ol.Description;
            a.Name = ol.PricebookEntry.Product2.Name;
            ast.add(a);
            ol.Converted_to_Asset__c = true;
       }
      update OLI; 
      insert ast;
     }
    }
}

 

Hi,

 

Could you please help me write a test class for my trigger? I managed to get 10% covered, but since I am not a programmer I am having a hard time understanding how to correct it to get more. Thank you in advance!

 

This is my Trigger:

trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
     for(Opportunity o: trigger.new){ 
      if(o.isWon == true && o.HasOpportunityLineItem == true && o.RecordTypeId == '012200000004fxZ'){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_Asset__c  
                                      From OpportunityLineItem 
                                      where OpportunityId = :opptyId and Converted_to_Asset__c = false];
         Asset[] ast = new Asset[]{};
         Asset a = new Asset();
         for(OpportunityLineItem ol: OLI){
            a = new Asset();
        a.AccountId = o.AccountId;
            a.Product2Id = ol.PricebookEntry.Product2Id;
            a.Quantity = ol.Quantity;
            a.Price =  ol.UnitPrice;
            a.PurchaseDate = o.CloseDate;
            a.Status = 'Purchased';
            a.Description = ol.Description;
            a.Name = ol.PricebookEntry.Product2.Name;
            ast.add(a);
            ol.Converted_to_Asset__c = true;
       }
      update OLI; 
      insert ast;
     }
    }
}

 

I have this Apex Trigger which works good. However I want it to only be valid for license opportunities (all other record types should be able to close deal without having to add Delivery Contact), so I want to add $RecordType.Name = "License Opportunity" somewhere, but don't know where or how.

 

Anyone who has a solution for this? :)

 

This is the trigger:

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

//map to keep track of the contact_required = 1
Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>();

//Trigger.new is an array of opportunities
//and adds any that have Contact_Required = 1 to the oppy_contact Map
for (Integer i = 0; i < Trigger.new.size(); i++) {
System.debug('*****Required? ' + Trigger.new[i].contact_required__c);
if (Trigger.new[i].contact_required__c == 1) {
oppy_contact.put(Trigger.new[i].id,Trigger.new[i]);
}
}

//map to keep track of the opportunity contact roles
map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>();

//select OpportunityContactRoles for the opportunities with contact role required

List<OpportunityContactRole> roles = [select OpportunityId, Role from OpportunityContactRole
where (OpportunityContactRole.Role ='Delivery Contact') and OpportunityContactRole.OpportunityId
in :oppy_contact.keySet()];


for (OpportunityContactRole ocr : roles) {
//puts the contact roles in the map with the Opportunity ID as the key
oppycontactroles.put(ocr.OpportunityId,ocr);
}

// Loop through the opportunities and check if they exists in the contact roles map or contact role isn't required
for (Opportunity oppy : system.trigger.new) {
//system.debug('List oppy Id - '+oppy.id);
if (oppy.contact_required__c ==1 && !oppycontactroles.containsKey(oppy.id))
{
oppy.addError('No Delivery Contact exists. Please go to the Contact Roles area and select a delivery contact before you can move on to stage "A6 - Closed Won".');
}
} //for
}

 

Hi,

 

Could you please help me write an IF statement (I think that's what I need?) for my Visualforce email template?

 

I have a VF email template that (among other things) pulls all information from the opportunity contact role related list. What I really would like is for it to just pull the information from one specific role = "Delivery Contact". So that if several roles are specified in the list the others will not show up in my email, and if the role "Delivery Contact" is not specified at all in the opportunity contact role related list  the table is left blank.

 

Is it an IF statement I need, and how would it look?

 

This is my code:

 

<p>
<table border="0" width="560">
<tr >
<th>Role</th><th>Name</th><th>Email</th><th>Phone</th><th>Primary Contact?</th>
</tr>
<apex:repeat var="ContactRole" value="{!relatedTo.OpportunityContactRoles}">
<tr>
<td>{!ContactRole.Role}</td>
<td>{!ContactRole.Contact.Name}</td>
<td>{!ContactRole.Contact.Email}</td>
<td>{!ContactRole.Contact.Phone}</td>
<td>{!ContactRole.IsPrimary}</td>
</tr>
</apex:repeat>
</table>
</p>

 

 Thanks in advance!

Hi!

 

I want to get the name, email address and phone number of the person marked as primary contact on the Contact Roles related list in the opportunity into my Visualforce email template.

 

I have created this code:

<apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
{!ContactRole.Contact.Name}, {!ContactRole.Contact.Title}, {!ContactRole.Contact.Email}, {!ContactRole.Contact.Phone},
</apex:repeat>

 

but it lists ALL people in the Contact roles related list, and I just want the primary contact. How can I accomplish this?