• Ben Aebischer
  • NEWBIE
  • 0 Points
  • Member since 2015
  • CRM Analyst
  • X-Rite Europe GmbH


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hi,
I'm desperately looking for a workflow rule to automatically format the phone numbers for Contacts with Country = Switzerland as follows:
+41 xx xxx xx xx. I tried several workflow rules, but somehow didn't manage to accomplish this.
Thank you in advance for your input!
Hi everyone, 

I'm pretty new to Apex and I'm desperately looking for a test class for the following trigger:

Trigger QuoteTriggers on Quote (after insert, after update) { 
Public static boolean IsRun = False; 
for (Quote Q :[SELECT Id,Status, Opportunity.Account.Id, Opportunity.Approval_Status__c FROM Quote WHERE id IN :trigger.New]) { 
If(Trigger.IsInsert){ 
ID QID = Q.ID; 
If(Q.Opportunity.Approval_Status__c == 'Approved' && IsRun == False) { 
Quote ThisQuote = new Quote ( 
Id = QID, 
Status = 'Approved' 
); 
update ThisQuote; 
IsRun = True; 


If (Trigger.IsUpdate && IsRun == False && Q.Opportunity.Approval_Status__c == 'Approved') { 
if (!QuoteStatusUtil.hasQuoteUpdated()) { 
Q.Status = 'Approved'; 
QuoteStatusUtil.setQuoteUpdated(); 
update Q; 

Could anybody help me please?
Thanks : )
 
Hi, I'm new to coding. However, I modified some existing code from rjpalombo (thanks!) and created a prospecting counter for my leads.
Actually, the counting works - however, when I merge two leads (duplicates) all activities get merged but the counter doesn't get automatically updated. I then either first have to create a new activity or edit an existing activity on the lead, before the counter get updated. Is there a way how I can make sure that this is done automatically? Thank you in advance for your help! : )

Following the Trigger and the Apex Class:

Trigger:
trigger TotalActivityUpdateLeads on Task (after delete, after insert, after undelete, after update) {
//This trigger counts calls made against a Lead
Set<ID> leadIds = new Set<ID>();
//We only care about tasks linked to leads.
String prefix = TotalLeadActivityCount.oppPrefix;
//Add any lead ids coming from the new data
if (Trigger.new != null) {
for (Task t : Trigger.new) {
if (t.WhoId != null && String.valueOf(t.whoId).startsWith(prefix) ) {
leadIds.add(t.whoId);
}
}
}
//Also add any lead ids coming from the old data (deletes, moving an activity from one lead to another)
if (Trigger.old != null) {
for (Task t : Trigger.old) {
if (t.WhoId != null && String.valueOf(t.whoId).startsWith(prefix) ) {
leadIds.add(t.whoId);
}
}
}
if (leadIds.size() > 0)
TotalLeadActivityCount.updateLeadCounts(leadIds);
}

Apex Class:
public with sharing class TotalLeadActivityCount {
public static Boolean didRun = false;
public static String oppPrefix = Lead.sObjectType.getDescribe().getKeyPrefix();
/*
* Takes a set of opportunity IDs, queries those leads, and updates the activity count if appropriate
*/
public static void updateLeadCounts(Set<ID> leadIds) {
if (didRun == false) { //We only want this operation to run once per transaction.
didRun = true;
//Query all the leads, including the tasks child relationships
List<Lead> leads = [SELECT ID, Total_Lead_Activity_Count__c, (SELECT ID FROM Tasks where (RecordTypeId='01260000000JNHF' OR RecordTypeId='01260000000JMaa' OR RecordTypeId='01260000000JESu') AND Status='Completed'), (SELECT ID FROM Events) FROM Lead WHERE ID IN :leadIds];
List<Lead> updateLead = new List<Lead>();
for (Lead l : leads) {
Integer count = l.tasks.size();
if (l.Total_Lead_Activity_Count__c != count) {
l.Total_Lead_Activity_Count__c = count;
updatelead.add(l); //we're only doing updates to leads that have changed...no need to modify the others
}
}
//Update the appropriate lead
try {
update updateLead;
} catch (Exception e) {
//This is controversial. Anything could happen when updating the opportunity..validation rule, security, etc. The key is we don't
//want the event update to fail...so we put a try catch around the opp update to make sure we don't stop that from happening.
}
}
}
}
Hi,
I'm desperately looking for a workflow rule to automatically format the phone numbers for Contacts with Country = Switzerland as follows:
+41 xx xxx xx xx. I tried several workflow rules, but somehow didn't manage to accomplish this.
Thank you in advance for your input!