• Gustavo Bertolino
  • NEWBIE
  • 58 Points
  • Member since 2018
  • Salesforce Developer
  • Sottelli IT Consulting


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 4
    Likes Given
  • 0
    Questions
  • 28
    Replies
public class DedupeCasesHandler {
    public static void deDupeCases (List<Opportunity> Opps){
Set<String> setUnique            = New Set<String>();
Set<String> setUniqueDataBase    = New Set<String>();
Set<String> Field1               = New Set<String>();
Set<String> Field2               = New Set<String>();
        
        
        For (Opportunity objOpp : Opps){
If(objOpp.Oppty_Type__c !=Null && objOpp.Opport_Acct_SF_ID__c !=Null){
    Field1.add(objOpp.Oppty_Type__c);
	Field2.add(objOpp.Opport_Acct_SF_ID__c);
    
    String strKey = objOpp.Oppty_Type__c+ '_' +objOpp.Oppty_Type__c+ '_' +objOpp.Oppty_Type__c+ '_' +objOpp.Oppty_Type__c;
     if(strKey != null && strKey != '')
setUnique.add(strKey);
    system.debug('setUnique' +setUnique);
    }
}
if(!setUnique.isEmpty()){
	system.debug('Im here');
    For (Opportunity objOpp : [SELECT Id,Field1,Field2]){
String strKeyDataBase = objOpp.Oppty_Type__c+ '_' +objOpp.Opport_Acct_SF_ID__c;
        setUniqueDataBase.add(strKeyDataBase);
system.debug('setUniqueDataBase'+setUniqueDataBase);
        }
    }
        For(Opportunity objOpp : Opps){
 IF(objOpp.Oppty_Type__c !=Null && objOpp.Oppty_Type__c !=Null && objOpp.Oppty_Type__c != Null && objOpp.Oppty_Type__c !=Null){
     String strKey = objOpp.Oppty_Type__c+ '_' +objOpp.Opport_Acct_SF_ID__c;
     if(!setUniqueDataBase.isEmpty() && setUniqueDataBase.contains(strKey)){
objOpp.addError('Duplicate Opportunity Found Contact the Salesforce Administrator');
         }
     }
          }
}
}

This code states that there is an error at line 22.  The problem is: Expecting 'FROM' but was: ']'

Is it possible someone could explain this error to me and let me know if this code is good to go?
I am trying to call the class from trigger... getting the error 'Method does not exist or incorrect signature: void acctphoneupdate(List<Account>) from the type AccClass1'. Pls help in resolving this issue.

I have the following Class

public class AccClass1 {
           public static acctphoneupdate(List<Account> Acc) {
//        list<Account> Acct = [Select Phone from Account];
//            for ( Account Acc : Acct) {
                if (Acc.phone == '4001002000')
                {
                    Acc.phone = '4040404040';
                    insert Acc;
                }
//            }
    }
}

I have the trigger as below:

trigger Acctrigger1 on Account (before insert) {
    AccClass1 first = new AccClass1();
    first.acctphoneupdate(Trigger.new); <--- This is the line of code having issue. 
}
  • April 08, 2018
  • Like
  • 0
Hi Please help me out to solve this problem.
public class wrapperExample{

 
  public List<Wrapper> wrapAccountList {get; set;}

 public wrapperExample(){
  if(wrapAccountList == null) {
  wrapAccountList = new List<Wrapper>();
  for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 100]) {

          for(list<contact> r: [select Id, Name from Contact where AccountId = :a.Id]){

wrapAccountList.add(new Wrapper(a,r));
 
  }   
  }
  }
  }

 public class Wrapper{

 public Account acc {get; set;}
  public List<Contact> con {get; set;}

 public Wrapper(Account a, List<Contact> c) {
  acc = a;
  con = c;

 }
  }
 }
Hi,

I have recently started a new role heading up our tools here and I'm ready to deploy several new APEX features requested by my company.  However I've come across an Apex Test Failure from legacy code that my predecessor had created.  It's an important function for us as it is what calculates what sales territory the account should be a part of based on it's segment, territory and state/province, but we are getting the Too many SOQL queries on line 28 from the class and I can't for the life of me find out why, it's not part of a for loop from what I can see, i have even tried setting a limit on all the queries in the class to see if i can at least remove the error but no luck.  Am I missing something obvious? Any help with this would be greatly appreciated.

This is the class:
public class Account_TerritoryUpdate {
    public static void TerritoryUpdate(List<Account> newList, List<Account> oldList){
        
        Set<Id> accountIDs = new Set<Id>();
        Set<Id> parentIDs = new Set<Id>();
        
        for (Integer i=0; i<newList.size(); i++){
            // if the account is new, if Territory is Blank, or if Segment or State are changed.
            if(oldList==null || newList[i].Axonify_Sales_Territory__c==null
               || newList[i].Axonify_Segment_Model__c <> oldList[i].Axonify_Segment_Model__c
               || newList[i].BillingState <> oldList[i].BillingState){
                accountIDs.add(newList[i].Id);
            }
            if(newList[i].Ultimate_Parent__c<>null){
                parentIDs.add(newList[i].Ultimate_Parent__c);
            }
        }
        if (accountIDs.size()>0){
            List<Account> accountList = [Select Id, Axonify_Segment_Model__c, BillingState, Axonify_Sales_Territory__c, Ultimate_Parent__c from Account where ID in :accountIDs];
            Map<Id,Account> parentMap = new Map<Id,Account>([Select Id, Axonify_Sales_Territory__c from Account where ID in :parentIDs]);
            List<String> SegmentList = new List<String>();
            List<String> StateList = new List<String>();
            
            for(Account a:accountList){
                SegmentList.add(a.Axonify_Segment_Model__c);
                StateList.add(a.BillingState);
            }         
            List<Territory_Map__c> TerritoryMapList = [Select Id, Segment__c, State_Province__c, Territory__c from Territory_Map__c where Segment__c in :SegmentList or State_Province__c in :StateList]; /******************this is where the SOQL query error occurs**************/
            Map<String,String> tMap = new Map<String,String>();
            for (Territory_Map__c tm : TerritoryMapList){
                tMap.put(tm.Segment__c+tm.State_Province__c,tm.Territory__c);
            }
            List<Account> updateList = new List<Account>();
            for (Account a:accountList){
                if (parentMap.get(a.Ultimate_Parent__c)!=null && parentMap.get(a.Ultimate_Parent__c).Axonify_Sales_Territory__c<>a.Axonify_Sales_Territory__c){
                    a.Axonify_Sales_Territory__c = parentMap.get(a.Ultimate_Parent__c).Axonify_Sales_Territory__c;
                    updateList.add(a);
                }else if (a.Axonify_Sales_Territory__c <> tMap.get(a.Axonify_Segment_Model__c+a.BillingState)){
                    a.Axonify_Sales_Territory__c = tMap.get(a.Axonify_Segment_Model__c+a.BillingState);
                    updateList.add(a);
                }
            }
            
            update(updateList);        
        }
    }
}


Being called from this trigger:

trigger Account_Trigger on Account (after update, after insert, before delete) {
    
    if (Trigger.isAfter && (Trigger.isUpdate || Trigger.isInsert)){
        Account_TriggerHandler.ExcludeFromGainsight(Trigger.new,Trigger.old);
        Account_TerritoryUpdate.TerritoryUpdate(Trigger.new,Trigger.old); 
    }
    
    /******  Handle Child/Parent Account Stuff ******/
    if (Trigger.isBefore && Trigger.isDelete){
        // Prevent account from being deleted if there are any child accounts referencing it
        List<Id> parentIDs = new List<Id>();
        Map<Id,Account> parentMap = new Map<Id,Account>();
        for (Account a : Trigger.old){
            parentIDs.add(a.Id);
            parentMap.put(a.Id,a);
        }
        List<Account> childAccounts = [Select Id, ParentID, Ultimate_Parent__c from Account where ParentID in :parentIDs];
        if (childAccounts <> null){
            for(Account c : childAccounts){
                parentMap.get(c.ParentID).addError('An account cannot be deleted if it has child accounts.');
            }
        }
    }
    if (Trigger.isAfter && Trigger.isUpdate){
        // get accounts for which the parent has changed
        List<Id> accountIDs = new List<Id>();
        for (Integer i=0; i<Trigger.new.size(); i++){
            if (Trigger.new[i].ParentID <> Trigger.old[i].ParentID){
                accountIDs.add(Trigger.new[i].Id);
            }
        }
        if (accountIDs.size()>0){
            Account_ParentHandler.UpdateUltimateParent(accountIDs);
        }
    }else if (Trigger.isAfter && Trigger.isInsert){
        // get accounts which have a parent
        List<Id> accountIDs = new List<Id>();
        for (Account a : Trigger.new){
            if (a.ParentId <> null){
                accountIDs.add(a.Id);
            }
        }
        if (accountIDs.size()>0){
            Account_ParentHandler.UpdateUltimateParent(accountIDs);
        }
    }
    
}

Thanks in advance.

Hi all,

i am having trouble to figure out how to implement the following: 

- I have an Object, eg. Account, with one field that the user can update anytime. 
- Once a new Object, eg. AccountPlus__c, gets created I want the field from Account to switch to Read-Only, so that no User can edit it anymore.
- The same field also exists in AccountPlus__c and once a record of AccountPlus__c gets created you can change the field only via this record.
- The information of the same field though, shall be transfered to the Account Object an update it (allthough the field is read only, even for the same User that creates the record of AccountPlus__c)

Do you have any Ideas how that could look? I thought of something like a trigger (with/without a Validation Rule).

Thank you in advance!!!
Best regards, Staci

I would like to make pickupList field read-only ....I already tried  to  make iread only in paygeLayOut and field level security..... but still I cant do it...

Can anyone help this ? 

I've been trying to create a trigger for a while and it is not going well, but I was tackling it wrong.  I have now created a field called Trigger_Help__c on the Opportunity Object and I need it to be unique.  I have found the following code and I think it needs to be something similar.  Is it possible someone could help me change it to work how I need?
 
Trigger

trigger leadDuplicatePreventer on Lead
                               (before insert, before update) {

    Map<String, Lead> leadMap = new Map<String, Lead>();
    for (Lead lead : System.Trigger.new) {
       
        // Make sure we don't treat an email address that 
        // isn't changing during an update as a duplicate. 
   
        if ((lead.Email != null) &&
                (System.Trigger.isInsert ||
                (lead.Email !=
                    System.Trigger.oldMap.get(lead.Id).Email))) {
       
            // Make sure another new lead isn't also a duplicate 
   
            if (leadMap.containsKey(lead.Email)) {
                lead.Email.addError('Another new lead has the '
                                    + 'same email address.');
            } else {
                leadMap.put(lead.Email, lead);
            }
       }
    }
   
    // Using a single database query, find all the leads in 
   
    // the database that have the same email address as any 
   
    // of the leads being inserted or updated. 
   
    for (Lead lead : [SELECT Email FROM Lead
                      WHERE Email IN :leadMap.KeySet()]) {
        Lead newLead = leadMap.get(lead.Email);
        newLead.Email.addError('A lead with this email '
                               + 'address already exists.');
    }
}

 
Hello,
I have created a Visualforce email alert when a new event has been created. But the event time in the subject and email body don't match.

User-added image
I think it's because the time is in GMT in the email body and we are on BST in the UK now.

I have also created a custom field called 
Start Date Time Text that pulls through the date as text, formula below;

TEXT( DAY( ActivityDate ) ) & "/" & TEXT( MONTH( ActivityDate ) ) & "/" & TEXT( YEAR( ActivityDate ) ) & " " & MID( TEXT(ActivityDateTime), 12,5) 

This doesn't display correctly either, same issue?

User-added image

Anyone know how to resolve the time zone issue? Both company and user time zones are set to BST.

Thanks,

Paul
set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();
 
list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ]

now i want to check if mEmpId and hEmpId are blank and if it is blank i have to run this query? how to check the set is empty?
 
for (Opportunity objOpp : opportunities){
            if(objOpp.Owner.ProfileId == 'System Administrator') {
trigger OpportunityTrigger on Opportunity (before insert) {
    if(Trigger.isBefore && Trigger.isInsert){
DedupeCasesHandler.deDupeCases
    }
}

I have zero idea of what I am doing and I am recieving the eror message "Unexpected token 'for'"
public class DedupeCasesHandler {
    public static void deDupeCases (List<Opportunity> Opps){
Set<String> setUnique            = New Set<String>();
Set<String> setUniqueDataBase    = New Set<String>();
Set<String> Field1               = New Set<String>();
Set<String> Field2               = New Set<String>();
        
        
        For (Opportunity objOpp : Opps){
If(objOpp.Oppty_Type__c !=Null && objOpp.Opport_Acct_SF_ID__c !=Null){
    Field1.add(objOpp.Oppty_Type__c);
	Field2.add(objOpp.Opport_Acct_SF_ID__c);
    
    String strKey = objOpp.Oppty_Type__c+ '_' +objOpp.Oppty_Type__c+ '_' +objOpp.Oppty_Type__c+ '_' +objOpp.Oppty_Type__c;
     if(strKey != null && strKey != '')
setUnique.add(strKey);
    system.debug('setUnique' +setUnique);
    }
}
if(!setUnique.isEmpty()){
	system.debug('Im here');
    For (Opportunity objOpp : [SELECT Id,Field1,Field2]){
String strKeyDataBase = objOpp.Oppty_Type__c+ '_' +objOpp.Opport_Acct_SF_ID__c;
        setUniqueDataBase.add(strKeyDataBase);
system.debug('setUniqueDataBase'+setUniqueDataBase);
        }
    }
        For(Opportunity objOpp : Opps){
 IF(objOpp.Oppty_Type__c !=Null && objOpp.Oppty_Type__c !=Null && objOpp.Oppty_Type__c != Null && objOpp.Oppty_Type__c !=Null){
     String strKey = objOpp.Oppty_Type__c+ '_' +objOpp.Opport_Acct_SF_ID__c;
     if(!setUniqueDataBase.isEmpty() && setUniqueDataBase.contains(strKey)){
objOpp.addError('Duplicate Opportunity Found Contact the Salesforce Administrator');
         }
     }
          }
}
}

This code states that there is an error at line 22.  The problem is: Expecting 'FROM' but was: ']'

Is it possible someone could explain this error to me and let me know if this code is good to go?
Hello,

I want to add the custom values in the status field of CampaignMember object. I am not able to find the add button to add the values in this field.

I have tried with lightning as well as classic mode but unable to identify the add button in both.
On more analysis, I found a button named 'Advance Setup' (in classic mode) while editing particular Campaign, which allows to add the values in campaign members but it is specific to that Campaign only. So, those new status is not showing up while adding Campaign Members of other campaigns.

Can anyone please help me how to achieve this or is it possible or not?
Dear all,
We are trying to deploy in production a trigger that capitalize the first letter of a name and a last name of a contact (even when there is a compound given name) and that the last name is in capital letters (example: Jean-Pierre DEBOIS). We tested in Sandbox and everything worked. But when we tried to deploy in production, we get the following errors and the test class has 0% code coverage (please see image below). Could anyone please help us to resolve this problem? 
Thank you! 

Trigger that we are trying to implement: 
trigger CapitalizeName on Contact( before insert , before update)
{
for(Contact c : Trigger.new)
{
if(c.FirstName != null)
{
String prev='';
String response='';
for (Integer i=0;i<c.FirstName.length();i++)
{
String cur=c.FirstName.subString(i ,i+1);
if (prev=='' || prev==' ' || prev=='-')
response+=cur.toUpperCase();
else
response+=cur.toLowerCase();
prev=cur;
}
c.FirstName = response;
}
c.LastName = c.LastName.ToUpperCase() ;
}
}


User-added image

 
Hello All, I have trigger to create Revenueshare(child of opportunity) record if opportunity  stage=closewon and owner of opportunity and account is same, but trigger is not wrking.
trigger createRevenueShare on Opportunity (after insert, after update) {
   List<Revenue_Share__c> share= new List<Revenue_Share__c>();
   
   for(Opportunity opp:trigger.new)
   {
   if( opp.StageName== 'Close Won' && (opp.OwnerId == opp.Account.OwnerId))
   {
   Revenue_Share__c revShare= new Revenue_Share__c();
   revShare.Opportunity__c=opp.Id;
   share.add(revShare);
   }
   }
   insert share;
}
Hello All
I am trying to set a workflow trigger to send an outbound message for when any contact is changed. I could not find anything in criteria to let me set such a null condition so that I can select the "created, and any time it's edited to subsequently meet criteria" and leave the criteria blank. 

Essentially I would like to trigger a workflow message when any contact is created/modified.  
Thanks for your help.
Tanmay
Hi there everyone,

I have a set of custom objects. One called ‘Research task’ and another called ‘Correspondence’. The ‘Correspondence’ custom object is a child object to the ‘Research Task’ object, which is the parent.  The customer occasionally receives an e-mail that results in either the creation of a new custom object ‘Research Task’ object entry into Salesforce or a ‘Correspondence’ to an existing ‘Research Task’. If the e-mail that is received is something new that has never been researched, the customer would like to select an Assignee from drop down, as well as a priority, and then have the body of the e-mail placed in the initial ‘Correspondence’ entries text field for this new ‘Research Task’. If the e-mail is relating to an existing ‘Research Task’ the user would like to be able to select the Research Task from a drop down list and then have the context of the e-mail placed in a new ‘Correspondence’ entry.

My question is, ‘Does this functionality currently existing in the Outlook integration or, is this something we would need to create a custom solution for? (I am presuming the later.) 

If this is something that we would need to create a custom solution for, would this be done using something like ‘Visual Force’ that might give the user the ability to look at e-mails and give the user the ability to either create a new case, or add information to an existing case?
Does anyone have an example of something like this that they can at least share some guidance in regards this topic with me?

Thank you in advance for your assistance.

Respectfully,

Eric Anderson
 
I currently am working on creating an Apex Class that initiially pulls a specific set of Placements (jstcl__Placement__c) and puts them in a list. 
It then takes that list of Placement Ojects and edits a relevant field called TimecardEnddateAudit__c field. I keep getting errors saying that the field jstcl__Timesheet_Period__c that exists in some of my if logic does not exist. Logically it should edit fields according to the logic:" If the jstcl__Timesheet_Period__c field is equal to 'Weekly Split' then add .5, else add 1. 
public class CamstimecardEndDateAudit{
public static void auditTimeCards(){

List<sObject> placements = [SELECT jstcl__Placement__r.Name
                            FROM jstcl__TG_Timesheet__c 
                            WHERE jstcl__Placement__r.ts2__Status__c IN ('Active') 
                             AND jstcl__Week_Ending__c = LAST_N_DAYS:15
                             AND jstcl__Status__c = 'Pending'];
                             
    for(List<sObject> A : placements){

        if(A.jstcl__Timesheet_Period__c = 'Weekly Split'){
        
        TimecardEndDateAudit__c = TimecardEndDateAudit__c + 0.5;}
        
        else{
        
        TimecardEndDateAudit__c = TimecardEndDateAudit__c ++;
}
}
}}

 
Hi all, 

I am trying to create a auto populated field. We have a custom object, 'Engagement'. I want to create a new field under contacts that shows engagments that are starting soon. Ideally when an engagement has a confirmed start date that is greater than today it will be shown in this field. 

Does anyone have any advice how I could do this? 
Fairly new to Apex and I have a trigger that checks if a Task is on a Contact and pulls in 2 fields from the Contact record that will update the Task. 

It works fine for one record at a time but when trying to bulk if there are multiple tasks for the same Contact it will only fire for the last Activity in the Trigger.new list and not all that share the same WhoId.

Looks like the Map is only capturing the Contact Id once and then the SOQL query only returns one result. Just need help figuring out the solution so that each Task will get updated with the Contact fields.
 
trigger TaskTrigger on Task (before insert, before update) {

    Map<Id, List<Task>> conIdsMap = new Map<Id, List<Task>>();

    for (Task t : Trigger.new) {
            //Search for Contact on Task
        if (t.whoid != null && t.whoid.getsObjectType().getDescribe().getName() == 'Contact') {
                    List<Task> temp = new List<Task>();
                    temp.add(t);
                    conIdsMap.put(t.whoid, temp);
        }
    }

    if (conIdsMap.size() > 0) {
            for(Contact con : [Select Id, Name, Status__c, Corp_Lead_Score__c from Contact where Id in :conIdsMap.keySet()]) {
                for(Task t :conIdsMap.get(con.Id)){
                    t.Stage__c = con.Status__c;
                    t.Corp_Lead_Score__c = con.Corp_Lead_Score__c;
                }
            }  
        }
}