• raj sfdc 8
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 4
    Replies
trigger Raj_provider_detail_page on Provider_detail__c (Before Insert,Before Update) {

    //if (trigger.isBefore){
        //  Map to be checked against for the existence of a Custom Setting for a User

        map<string, Password__c> userToCustomSetting = new map<string, Password__c>();

        //  Lists for new, updated, and existing settings.

        list<Password__c >new set = new list<Password__c>();

        //list<Password__c> update2 = new list<Password__c>();

        list<Password__c> exsist3 = [SELECT  Id,Name,Password__c,ProviderID__c,MeterNumber__c,ProviderName__c,TransactionType__c
                                                       FROM   Password__c 
                                                       ORDER BY  CreatedDate
                                                       LIMIT   50];
        //  Notice the LIMIT above?  Without it, you'll probably receive a mark against you in your
        //  AppExchange Security Review findings report.  Queries need a WHERE or LIMIT

        //  Any triggered Provider_detail__c that meets the Password requirements will be added to this list
        list<Provider_detail__c> ApplicationSettings = new list<Provider_detail__c>();

        //  Populate the map based on the above query's results - keyed by the Username (name contains username)               
        if (!exsist3.isEmpty()){
            for (Password__c s : exsist3){
                userToCustomSetting.put(s.Name,s);
            }
        }

        for (Provider_detail__c to : trigger.new){
            if ((to.Password__c != null && to.Password__c  != '' )||(to.Transaction_Key != null && to.Transaction_Key != '')){
                //  Inserts are easier - as long as the Password was provided, we'll add it
                if (trigger.isInsert)
                    ApplicationSettings.add(to);
                //  We'll make sure the old and new Password values don't match and aren't udpated to the "masked" value
                else if (trigger.isUpdate)
                    if ((to.Password__c != '************' && to.Password__c != trigger.newMap.get(to.id).Password__c)||(to.Transaction_Key!='*************' && to.Transaction_Key != trigger.newMap.get(to.id).Transaction_Key))
                    ApplicationSettings.add(to);
            }
        }

        if (!ApplicationSettings.isEmpty()){
            for (Provider_detail__c to : ApplicationSettings){
                // if(to.Meter_Number__c != null){
                if( to.Meter_Number__c != null && to.Merchant_Id__c != null && to.Password__c != null ){
                    new set.add(new Password__c(Name = string.valueof(to.id), Password__c = to.Password__c,MeterNumber__c=to.Meter_Number__c,ProviderName__c = to.provider_Name__c,TransactionType__c = to.Transaction_Type__c,ProviderID__c = to.id));
                    //  Replace the Password
                    system.debug('id======>>>>>>>>>>>>>>>========='+to.id);
                    to.Password__c = '************';
                }
            }
            system.debug('ApplicationSettings===='+ApplicationSettings);
            //  Do inserts
            if (!new set.isEmpty() && ApplicationSettings[0].id != null){
                // if (!new set.isEmpty()){    
                system.debug('new set====='+new set);
                insert new set;
            }
        }

        if (!ApplicationSettings.isEmpty())
        { if(ApplicationSettings[0].get('Transaction_Key')!=null && ApplicationSettings[0].get('SysConct_Merchant_Id__c')!=null) /////
        {
            for (Provider_detail__c to : ApplicationSettings){
                //if(to.Transaction_Key != null){
                if(to.Transaction_Key != null && to.Merchant_Id__c != null){
                    string str1 = to.Transaction_Key;
                    if(str1.length()<256){
                        new set.add(new Password__c(Name = string.valueof(to.id),ProviderName__c = to.SysConct_Provider_Name__c,TransactionType__c = to.SysConct_Transaction_Type__c,ProviderID__c = to.id,AuthKey1__c = str1,MeterNumber__c = to.SysConct_Merchant_Id__c));
                        //  Replace the Password
                        to.Transaction_Key = '**************';
                    }
                    else{
                        string str2 = str1.substring(0,244);
                        string str3 = str1.remove(str2);

                        new set.add(new Password__c(Name = string.valueof(to.id),ProviderName__c = to.SysConct_Provider_Name__c,TransactionType__c = to.SysConct_Transaction_Type__c,ProviderID__c = to.id,AuthKey1__c = str2,AuthKey2__c = str3,MeterNumber__c = to.SysConct_Merchant_Id__c));
                        //  Replace the Password
                        to.Transaction_Key = '*************';

                    }
                }

            }
            system.debug('ApplicationSettings===='+ApplicationSettings);
            //  Do inserts 
            if (!new set.isEmpty() && ApplicationSettings[0].id != null){
                // if (!new set.isEmpty()){    
                system.debug('new set====='+new set);
                insert new set;
            }
        }
        } //////
   // }
}

 
am having two objects (details,password-it contains only the passwords entered in the detail page).if i create a record on deatils page and save it with some password , records are created on both detail and pasword object. if i update password in the detail page.i also have to update in password page.but it is throwing error   for my trigger(before insert,update).
On account detail page ,if the new contact is saved it has to redirect to the account detail page saving the contact . how can we acheive this
can please anyone help me.
Thanks in advance
when ever account type is changed form any value to 'Customer' need to 
send an email to account owner saying your account become customer 
and create a task and assign it to account owner.



Trigger:

trigger accouncustomertype on Account ( after update) {
     
    accountcustomer.email_send (Trigger.old);
    
     List <task> taskToInsert = new List <task> ();

   for (Account a : Trigger.old) {
       if(a.Type=='Customer'){
           
            Account ab =  (Account) Trigger.oldMap.get(a.Id);
             Boolean oldtypeiscustomer = ab.Type.equals('Customer');
             Boolean   oldtype = a.Type.equals('Customer');
    
    if (!oldtypeiscustomer && oldtype ) {
      a.awesome__c = true;        
    } 
           
           
   task t = new task ();
   t.Subject = 'please call me';
   t.OwnerId = a.OwnerId;
   t.WhatId = a.id;
   taskToInsert.add(t);
}
}
insert taskToInsert;
}


Class :
 
 public class accountcustomer {
    
    public static void email_send( List <Account> acclist)
        {
        List<Messaging.SingleEmailMessage > Email_list=new List<Messaging.SingleEmailMessage >();
             for(Account Acc : acclist ){
              if(Acc.Type=='Customer'){
                  
                   //trigger.oldmap.account.Type(Customer)== trigger.newmap.account.Type(Customer)
                
                  
             Account a =  (Account) Trigger.oldMap.get(Acc.Id);
             Boolean oldtypeiscustomer = a.Type.equals('Customer');
             Boolean   oldtype = Acc.Type.equals('Customer');
    
    if (!oldtypeiscustomer && oldtype ) {
      Acc.awesome__c = true;        
    } 
                
                System.debug('email send');
                Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                   message.toAddresses =new String[] {'rajasekhara.bhavanam@forsysinc.com','rajarede08@gmail.com'};
                message.setSubject('your account changed to customer');    
                String Body_data='';
                Body_data=Acc.Name;
                Body_data=Acc.Type;
                message.sethtmlBody(Body_data);
                Email_list.add(message);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {message});
                }
        }
        
        
    }
}


My trigger is firing but well,But i don't want my trigger to fire when am again edit the same picklist value with Type:Custommer.First time it has to fire when the account Type is customer but i don't have to fire when the am editing it with same account type with value customer.
am got stuck with this issue please can anyone help me
when ever account type is changed form any value to 'Customer' need to 
send an email to account owner saying your account become customer 
and create a task and assign it to account owner.
How you will make a class available to others for extension
when ever account type is changed form any value to 'Customer' need to 
send an email to account owner saying your account become customer 
and create a task and assign it to account owner.



Trigger:

trigger accouncustomertype on Account ( after update) {
     
    accountcustomer.email_send (Trigger.old);
    
     List <task> taskToInsert = new List <task> ();

   for (Account a : Trigger.old) {
       if(a.Type=='Customer'){
           
            Account ab =  (Account) Trigger.oldMap.get(a.Id);
             Boolean oldtypeiscustomer = ab.Type.equals('Customer');
             Boolean   oldtype = a.Type.equals('Customer');
    
    if (!oldtypeiscustomer && oldtype ) {
      a.awesome__c = true;        
    } 
           
           
   task t = new task ();
   t.Subject = 'please call me';
   t.OwnerId = a.OwnerId;
   t.WhatId = a.id;
   taskToInsert.add(t);
}
}
insert taskToInsert;
}


Class :
 
 public class accountcustomer {
    
    public static void email_send( List <Account> acclist)
        {
        List<Messaging.SingleEmailMessage > Email_list=new List<Messaging.SingleEmailMessage >();
             for(Account Acc : acclist ){
              if(Acc.Type=='Customer'){
                  
                   //trigger.oldmap.account.Type(Customer)== trigger.newmap.account.Type(Customer)
                
                  
             Account a =  (Account) Trigger.oldMap.get(Acc.Id);
             Boolean oldtypeiscustomer = a.Type.equals('Customer');
             Boolean   oldtype = Acc.Type.equals('Customer');
    
    if (!oldtypeiscustomer && oldtype ) {
      Acc.awesome__c = true;        
    } 
                
                System.debug('email send');
                Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                   message.toAddresses =new String[] {'rajasekhara.bhavanam@forsysinc.com','rajarede08@gmail.com'};
                message.setSubject('your account changed to customer');    
                String Body_data='';
                Body_data=Acc.Name;
                Body_data=Acc.Type;
                message.sethtmlBody(Body_data);
                Email_list.add(message);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {message});
                }
        }
        
        
    }
}


My trigger is firing but well,But i don't want my trigger to fire when am again edit the same picklist value with Type:Custommer.First time it has to fire when the account Type is customer but i don't have to fire when the am editing it with same account type with value customer.
am got stuck with this issue please can anyone help me
in a project how meny custom objects we have to create