• Yeshi Mohammed 9
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 0
    Replies
Hello, 
We have a requiremet to have atleast one opportunity Contact role associated to an opportunity. I have proces to make sure contacts are assocaited to opportunity when they are created. But for existing opportunities, when users updates thier existing opportunities, I want to send them a reminder email alert to update with Contact role. I found this (https://salesforce.stackexchange.com/questions/25622/trigger-that-counts-how-many-contact-roles-have-a-specific-role-on-an-opportunit) Apex trigger code and updated to fit my requirement. here is my code. when there is Contact role associated to the opportunity my custom field get updated correctly but when there is no contact Role this code does not update my custom field to Zero. How do I get the code to update "Number_of_Contact_Roles__c" to 0 when no contact role ? I want to use this value for email alert. 
trigger countOpportunityContactRole on Opportunity (before insert, before update) {
  // Only need to enforce rule if opportunity is Open
Map<Id, Opportunity> oppsToCheckMap = new Map<Id, Opportunity>();
    for(Opportunity opp : trigger.new) {
        // Add the opp Id to a Map(Id to Opp) if it is an insert/Upgrade trigger with a Open Status 
        
        if(opp.ForecastCategoryName == 'Pipeline' || opp.ForecastCategoryName == 'Upside' || opp.ForecastCategoryName == 'Commit')
        { 
          oppsToCheckMap.put(opp.Id, opp); 
        }
    // For each Opportunity in the map keyset get the count of the
   List<AggregateResult> result = [
             select OpportunityID, count(Id)
             from OpportunityContactRole
             where OpportunityID in :oppsToCheckMap.keySet() group by OpportunityId];
        
    for(AggregateResult aggCount : result) {

        integer roleCount = (integer)aggCount.get('expr0');
        if(roleCount == 0) {
           // update cutom field to 0
            opp.Number_of_Contact_Roles__c = roleCount;          
        }
         // update cutom field to # of contact role
           opp.Number_of_Contact_Roles__c = roleCount;
    }
   }
}

Thank you 
​​​​​​​-Yeshi
Hello All,
I have Opportunity custom button called "Create New Opportuniy" to create new opportunity from Contact. we also associate the Contact as opportunity Contact Role

Here is the code 
(/setup/ui/recordtypeselect.jsp?ent=Opportunity
&retURL=/006/o
&save_new_url=%2F006%2Fe%3FretURL%3D{!Contact.Id}%26ent%3DOpportunityaccid%3D{!Account.Id}%26conid%3D{!Contact.Id}%2600N400000029iiN%3D{!Contact.Lead_Source_Detail__c}%26opp6%3D{!Contact.LeadSource}%26opp3%3D{!Account.Name}%2B-%26nooverride%3D1)

This code works fine for Salesforce Classic users. But since we have Classic and lightning users, when a user in lightning clicks on this button the default setup such as  AccountId , ContactID, LeadSource, AccountName ... does not get passed. this leads to Opportunity Contact Role not being Created. How Can I make a code that works for both Classic and lightning. any help will be appreciated. 
Thank you 
-Yeshi 
Hello,
I have process builder that updates custom field called "First Activity" when the a Task is created under Lead or Contact. It works fine when the activities are of "log a call" or "creating new task" Type. But when a user sends an Email from Lead or Contact my process builder is not updating "First Activity" field. 

I reached out to Salesforce support they said this is not achivable thru workflow or process builder. They said to try Apex Trigger .... Please help
Any sugestion will be apprciated
-Yeshi 
Hello All,
My manager requested if there is a way to add a flashing field or button of some kind on Salesforce Account record page when certain conditions are met. 
As an example , When A customer Account's license consumption is close to 90% , and when a Sales Rep goes to that customer's account page ,
1.) We would like to have that field or button flashing. 
2.) When they click on that button , we would like to direct the sales rep to a much detailed license info page.

I am an Admin , not much of a developer , any tips and/or tricks is appreciated in advance.
Yeshi
Hi All,
We create only allow our sales rep to create opportunity from contact, so that main contact role is associated. we have custom related list button , URL link that allows to create the opportunity , pre-populate record type , opp name, acct name ... . this works perfect in classic but not in lightning. 
since some of our users uses lightning , I want the same custom button or another button for creating new opportunity with some of the fields pre-populated. 

Thank you 
Yeshi