• veda shri
  • NEWBIE
  • 90 Points
  • Member since 2014
  • Trekbin Technologies Private Limited


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 29
    Replies
Hi,

I have created trigger with hardcoding.
i want that to work dynamically.
Because, Recordtype Ids are different in Production and sandbox.

Kindly help me where i have to make changes exactly.

Following is my trigger code.
=========================================================================

trigger APACLeadExactTargetEmails on xtma_Individual_Email_Result__c (after insert, after update)
{
    
     set<Id> LeadRts = new Set<Id>{'012200000005uXiAAI','0127E000000CgrLQAS','0127E000000CgqNQAS'};

//    Id rtID= [select Id,name from RecordType where name ='APAC - Open'OR name ='Global Abandoned Checkout' OR name = 'Global New Web Registrant' limit 1].Id;

    Set<String> setIDs = new Set<String>();

    for(xtma_Individual_Email_Result__c Emails : trigger.new){
        if(Emails.Lead__c!=null){
            setIDs.add(Emails.Lead__c);
        }
    }

    List<lead> listLead = [ Select Id FROM Lead where RecordTypeId in :LeadRts AND id in :setIDs ] ;
    Map<String,Lead> mapKeyWiseLead = new Map<String,Lead>();
        for(Lead obj :  listLead )
        {
            String key = obj.id;
            mapKeyWiseLead.put(key,obj);
        }
        
    List<Lead> listUpdatelead = new List<Lead>();
    Set<String> setLeadID = new Set<String>();
    
    String key;
    for(xtma_Individual_Email_Result__c Emails : trigger.new)
    {
        key='';
        if(Emails.Lead__c!=null){
            key=Emails.Lead__c;
            
            if( mapKeyWiseLead.containsKey(key) )
            {
                Lead checkLead = mapKeyWiseLead.get(Key) ;
                
               if(emails.name.contains('1st Newsletter - EDE')) 
                {
                    checkLead.X1st_Email_Date__c= Emails.Date_Time_Sent__c.Date();

                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==FALSE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X1st_Email_Outcome__c = 'Sent';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X1st_Email_Outcome__c = 'Opened';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c>0){
                        checkLead.X1st_Email_Outcome__c = 'Clicked';
                        }
                       if(emails.name=='1st Newsletter - EDE'){checkLead.X1st_Email_Name__c = '1st Newsletter - EDE';
                    }
                        listUpdatelead.add(checkLead);
                        setLeadID.add(checkLead.id);
                }
                if(emails.name.contains('2nd Newsletter - EDE'))
                {
                    checkLead.X2nd_Email_Date__c= Emails.Date_Time_Sent__c.Date();

                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==FALSE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X2nd_Email_Outcome__c = 'Sent';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X2nd_Email_Outcome__c = 'Opened';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c>0){
                        checkLead.X2nd_Email_Outcome__c = 'Clicked';
                        }
                       if(emails.name=='2nd Newsletter - EDE'){checkLead.X2nd_Email_Name__c = '2nd Newsletter - EDE';
                    }
                        listUpdatelead.add(checkLead);
                        setLeadID.add(checkLead.id);
                }
                if(emails.name.contains('3rd Newsletter - EDE')) 
                {
                    checkLead.X3rd_Email_Date__c= Emails.Date_Time_Sent__c.Date();

                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==FALSE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X3rd_Email_Outcome__c = 'Sent';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X3rd_Email_Outcome__c = 'Opened';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c>0){
                        checkLead.X3rd_Email_Outcome__c = 'Clicked';
                        }
                       if(emails.name=='3rd Newsletter - EDE'){checkLead.X3rd_Email_Name__c = '3rd Newsletter - EDE';
                    }
                        listUpdatelead.add(checkLead);
                        setLeadID.add(checkLead.id);
                }
                
            }
        }
    }
        if( listUpdatelead.size() > 0 )
        {
                try
                    {
                        update listUpdatelead;            
                    }
                catch(DMLException e)
                {  
                    System.debug('The following exception has occurred: ' + e.getMessage());
                }
        }
}

Regards,
Pranav
trigger defaultaction on Account(before insert,before update){
for(account acc : trigger.new){
acc.Phone='24243';

}

}
Hi,

I have one requirement to translate customer entered text from another language to English while displaying it to agents. And visa versa like agent can enter in English and customer should see it in another language in chat. 



 
Hi All,

I want to migrate data from dynamic 365/Pareto platform data to salesforce. What are the things I have to consider before migrating?

Anyone have data model for these?

Thanks,
Vedashri
TRIGGER ----



trigger NumberToWordFieldUpdate on Invoice__c (before insert, before update) {
    for (Invoice__c sc : Trigger.new) {
        if (sc.Total_GST_value_Rs__c != null && sc.Total_GST_value_Rs__c >= 0) {
            integer i = integer.valueOf(sc.Total_GST_value_Rs__c);
            NumberToWord ntw = new NumberToWord();
            sc.Total_GST_value_words__c = ntw.convert(i);
        } else {
            sc.Total_GST_value_words__c = null;
        }
    }
}



CLASS 


public class NumberToWord {
    public string wordText{set;get;}
    public string convert() {
        wordText=convert(numberval);
        return null;
    }
    public long numberval { get; set; }
    public String[] units = new String[]{' Zero ',' One ',' Two ',' Three ',' Four ',' Five ',' Six ',' Seven ',' Eight ',' Nine ',' Ten ','Eleven ','Twelve ','Thirteen ','Fourteen ','Fifteen ','Sixteen ','Seventeen ','Eighteen ','Nineteen '};
    public String[] tens = new String[]{'','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'};
    public  String convert(long i) {
        if( i < 20)  return units[integer.valueOf(i)];
        if( i < 100) return tens[integer.valueOf(i)/10] + ((math.mod(i , 10) > 0)? '' + convert(math.mod(i , 10)):'');
        if( i < 1000) return units[integer.valueOf(i)/100] + ' Hundred and' + ((math.mod(i , 100) > 0)?' ' + convert(math.mod(i , 100)):'');
        if( i < 10000) return units[integer.valueOf(i)/1000] + ' Thousand ' + ((math.mod(i , 1000) > 0)?' ' + convert(math.mod(i , 1000)):'');
        if( i < 100000) return convert(i / 1000) + ' Thousand ' + ((math.mod(i , 1000) > 0)? '' + convert(math.mod(i ,1000)):'') ;
        if( i < 1000000) return units[integer.valueOf(i)/100000] + ' Lakh ' + ((math.mod(i , 100000) > 0)? '' + convert(math.mod(i ,100000)):'') ;
        if( i < 10000000) return convert(i / 100000) + ' Lakh ' + ((math.mod(i , 100000) > 0)? '' + convert(math.mod(i ,100000)):'') ;
        if( i < 100000000) return units[integer.valueOf(i)/10000000] + ' Crore ' + ((math.mod(i , 10000000) > 0)? '' + convert(math.mod(i , 10000000)):'') ;
        if( i < 1000000000) return convert(i / 10000000) + 'Crore ' + ((math.mod(i , 10000000) > 0)? '' + convert(math.mod(i , 10000000)):'') ;
        return 'Sorry, Too Big';
    }
}


input  104400


expected op    One Lakh Four Thousand and Four Hundred


output One Lakh Four Thousand Four Hundred and

 
Hello all, 
Question: i want to create a custom field in lead object the lable would be Activity count (Number type & API Name: Activity_count__c).
(firstly i am dealing with the task only)For a Specific lead  Whenever task created with subject ='call' the count would be increase 0 or null to 1. if the subject is other then 'Call' the Activity count field Will remain same and it will not increase after the Activity count= 1 it will increase only once. Example= When Activity count= 1 and task created the  Activity count would be remain same as before.


Ans: I have Already implement this scenario. my trigger is working ( not working when the value of Activity count=null) . StilI have issue:
Why it is not working for null value that i have Discussed before?
The code coverage is still 35% after the creating test class I want atleast 75% 

​Trigger-
 
​trigger TaskUpdateLead on task (after delete, after insert,  after update) {
    
    Set<ID> LeadIds = new Set<ID>();
    String leadPrefix = Lead.SObjectType.getDescribe().getKeyPrefix();
    if(trigger.new!=null){
        for (Task t : Trigger.new) {
            if (t.WhoId!= null && string.valueof(t.WhoId).startsWith(leadPrefix) ) {
                if(!LeadIds.contains(t.WhoId)){
                    LeadIds.add(t.WhoId);
                }
            }
        }
    }
    
    if(trigger.old!=null){
        for (Task t2 : Trigger.old) {
            if (t2.WhoId!= null && string.valueof(t2.WhoId).startsWith(leadPrefix) )
            {
                if(!LeadIds.contains(t2.WhoId)){
                    LeadIds.add(t2.WhoId);
                }
            }
        }
    }
    if (LeadIds.size() > 0){
        List<Lead> leadsWithTasks = [select id,Activity_Count__c,(select id from Tasks where  Subject = 'Call'     LIMIT 1 ) from Lead where Id IN : Leadids   ];
        List<Lead> leadsUpdatable = new List<Lead>();
        for(Lead L : leadsWithTasks){
            L.Activity_Count__c = L.Tasks.size();
            leadsUpdatable.add(L);
        }
        if(leadsUpdatable.size()>0){
            
            update leadsUpdatable;
            
        }
        
    }
}



Test Class-
 
@istest
/** Test when subject is call**/
public Class TaskupdateLead
{
    Private static testMethod void TaskinsertLead()
    {
        Task t1 = new Task();
        t1.OwnerId = UserInfo.getUserId();
        t1.Subject = 'Call';
        t1.Status = 'Not Started';
        t1.Priority = 'Normal';
        insert t1;
    }
    private static testMethod void taskwidemail()
    {
        Task t2 = new Task();
        t2.OwnerId = UserInfo.getUserId();
        t2.Subject = 'Email';
        t2.Status = 'completed';
        t2.Priority = 'Normal';
        insert t2;
    } 
}
Hope some one will help me

Thanks And Regards
Bharat Sharma
 
Hi,
Need Help!!
trigger Update_modified_date on Task (after insert,after update) {      
     list<task> t=[SELECT LastModifiedDate FROM Task];
    list<lead> l=[select TaskLastModifiedDate__c from lead where Isconverted = false];
        for(task t1:t){
            //system.debug('this is ----------------------------------');
            for(lead l1:l){
                system.debug('this is ----------------------------------');
            l1.TaskLastModifiedDate__c=t1.LastModifiedDate;
            l.add(l1.TaskLastModifiedDate__c);  
                
            }
        }
    update l;
    }


Iam trying to copy last modified date of task in lead.But iam getting the following error.Please help.

Error: Incompatible element type Datetime for collection of Lead
Hi Guys
How to update account field when i am updating contact field uisng trigger.

For expamle:

account and contact object have mail _id__c custom field if i will update contact mail_id__c field then that will be updated in account object automatically..
trigger CONUP on Contact (after update,after insert) {
   
    Map<Id, Decimal> acctIdToAmount = new Map<Id, Decimal>();
    
    List<Account> accountsToUpdate = new List<Account>();
   
    Map<ID,RecordType> typeMap = New Map<ID,RecordType>([SELECT Id,name from RecordType where SobjectType='Contact' and Name LIKE'%CONTACT%']);
    
    for (CONTACT CON : trigger.new) {
          // If the Record Type = Intake Form
            if (CON.RecordTypeId =='01228000000Qjh3AAC' || CON.RecordTypeId =='01228000000QjgyAAC'){
            //    Get the Contact Amount into a temp variable
            Decimal sum = CON.PAID_AMOUNT__c == null ? 0 : CON.PAID_AMOUNT__c;

            //    Sum it up with the already collected Amount    
            if(acctIdToAmount.containsKey(CON.AccountId))
                sum += acctIdToAmount.get(CON.AccountId); 
            
            //    Make a map with AccountId as Key and Amount as value     
             acctIdToAmount.put(CON.AccountId, sum);
          }
  for(Id accId : acctIdToAmount.keyset()) {
        Account acc = new Account(Id = accId, TOTAL_AMOUNT__c = acctIdToAmount.get(accId));
        accountsToUpdate.add(acc);
    }

    if(!accountsToUpdate.isEmpty())
        update accountsToUpdate;
}
}

can anyone help to resolve the above error............
basically I want simple option to be displayed on sidebar as 'Expand' with '+' sign and when I click on that it will display 3 more options(lets say
1. A,
2. B &
3. C with '-' sign.
so when I click on lets say 1.A then it must display A objects field. so how can I achieve this functionality? What should be my controller should have? 
I think that we need to use wrapper class, but need your suggestion, please help.
We need the unit test to verify that a user that should not modify a Worker Status record is unable to Delete it, and then to verify that a user who IS supposed to modify a Worker Status record IS able to Delete it. How to get with trigger ?
Hello All,

I am getting below error while triggering the email template using Apex trigger update. Can someone help me out from the below issue

Error: Messaging.SendEmailResult[getErrors=(Messaging.SendEmailError[getMessage=common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object;getStatusCode=UNKNOWN_EXCEPTION;getTargetObjectId=00521000000Yr6GAAS;]);isSuccess=false;]
  • August 17, 2016
  • Like
  • 0
Hi,

I have created trigger with hardcoding.
i want that to work dynamically.
Because, Recordtype Ids are different in Production and sandbox.

Kindly help me where i have to make changes exactly.

Following is my trigger code.
=========================================================================

trigger APACLeadExactTargetEmails on xtma_Individual_Email_Result__c (after insert, after update)
{
    
     set<Id> LeadRts = new Set<Id>{'012200000005uXiAAI','0127E000000CgrLQAS','0127E000000CgqNQAS'};

//    Id rtID= [select Id,name from RecordType where name ='APAC - Open'OR name ='Global Abandoned Checkout' OR name = 'Global New Web Registrant' limit 1].Id;

    Set<String> setIDs = new Set<String>();

    for(xtma_Individual_Email_Result__c Emails : trigger.new){
        if(Emails.Lead__c!=null){
            setIDs.add(Emails.Lead__c);
        }
    }

    List<lead> listLead = [ Select Id FROM Lead where RecordTypeId in :LeadRts AND id in :setIDs ] ;
    Map<String,Lead> mapKeyWiseLead = new Map<String,Lead>();
        for(Lead obj :  listLead )
        {
            String key = obj.id;
            mapKeyWiseLead.put(key,obj);
        }
        
    List<Lead> listUpdatelead = new List<Lead>();
    Set<String> setLeadID = new Set<String>();
    
    String key;
    for(xtma_Individual_Email_Result__c Emails : trigger.new)
    {
        key='';
        if(Emails.Lead__c!=null){
            key=Emails.Lead__c;
            
            if( mapKeyWiseLead.containsKey(key) )
            {
                Lead checkLead = mapKeyWiseLead.get(Key) ;
                
               if(emails.name.contains('1st Newsletter - EDE')) 
                {
                    checkLead.X1st_Email_Date__c= Emails.Date_Time_Sent__c.Date();

                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==FALSE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X1st_Email_Outcome__c = 'Sent';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X1st_Email_Outcome__c = 'Opened';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c>0){
                        checkLead.X1st_Email_Outcome__c = 'Clicked';
                        }
                       if(emails.name=='1st Newsletter - EDE'){checkLead.X1st_Email_Name__c = '1st Newsletter - EDE';
                    }
                        listUpdatelead.add(checkLead);
                        setLeadID.add(checkLead.id);
                }
                if(emails.name.contains('2nd Newsletter - EDE'))
                {
                    checkLead.X2nd_Email_Date__c= Emails.Date_Time_Sent__c.Date();

                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==FALSE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X2nd_Email_Outcome__c = 'Sent';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X2nd_Email_Outcome__c = 'Opened';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c>0){
                        checkLead.X2nd_Email_Outcome__c = 'Clicked';
                        }
                       if(emails.name=='2nd Newsletter - EDE'){checkLead.X2nd_Email_Name__c = '2nd Newsletter - EDE';
                    }
                        listUpdatelead.add(checkLead);
                        setLeadID.add(checkLead.id);
                }
                if(emails.name.contains('3rd Newsletter - EDE')) 
                {
                    checkLead.X3rd_Email_Date__c= Emails.Date_Time_Sent__c.Date();

                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==FALSE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X3rd_Email_Outcome__c = 'Sent';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X3rd_Email_Outcome__c = 'Opened';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c>0){
                        checkLead.X3rd_Email_Outcome__c = 'Clicked';
                        }
                       if(emails.name=='3rd Newsletter - EDE'){checkLead.X3rd_Email_Name__c = '3rd Newsletter - EDE';
                    }
                        listUpdatelead.add(checkLead);
                        setLeadID.add(checkLead.id);
                }
                
            }
        }
    }
        if( listUpdatelead.size() > 0 )
        {
                try
                    {
                        update listUpdatelead;            
                    }
                catch(DMLException e)
                {  
                    System.debug('The following exception has occurred: ' + e.getMessage());
                }
        }
}

Regards,
Pranav