• sumit sharma 200
  • NEWBIE
  • 160 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 34
    Questions
  • 41
    Replies
User-added image

This is my detail page and when i click on skip to milestone it will open a visual force page which looks like below

User-added image

How can i remove the extra portions like setup in the head part?

the button code for skip to milestone is

{!REQUIRESCRIPT("/xdomain/xdomain.js")}
{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")}
{!REQUIRESCRIPT("/support/console/39.0/integration.js")}

var status='{!Program_Member_MVN__c.Status_MVN__c}';
var PmId='{!JSENCODE(Program_Member_MVN__c.Id)}'; 
var url;
if (sforce.console.isInConsole()) {
if(status == 'On Therapy')
{
url = "/apex/Milestone_skip?id="+PmId;
window.open(url,'_blank','toolbar=0,location=0,menubar=0'); 
}  
else
{
alert("Patient must be ‘On-Therapy’ before skipping to a milestone");
}
}

var showTabId = function showTabId(thisVal) {
  sforce.console.refreshPrimaryTabById(thisVal.id, true, '');
};
if (sforce.console != null && sforce.console.isInConsole()) {
    setTimeout(function(){ 
  sforce.console.getFocusedPrimaryTabId(showTabId);
},9500);
}

i am just referring the visual force page link in the button how can modify it show only my visual force part?
Hello friends, Iam getting error "Variable does not exist: RecursiveTriggerHandler" while deploying the apex trigger to production.
Please find the trigger below

trigger BD_AccountTrigger on Account (after insert, after update) {
  BD_ProcessSwitchSettings__c custSettings = BD_ProcessSwitchSettings__c.getInstance();
 
 System.debug('****************in BD_LeadTrigger');
 
 if(trigger.isInsert || trigger.isUpdate){
   System.debug('****************in BD_LeadTrigger, Trigger.old:'+trigger.old);
   System.debug('****************in BD_LeadTrigger, Trigger.new:'+trigger.new);
 } 
  
 // if(!custSettings.BD_AllTriggersDisabled__c && custSettings.BD_NotesTriggerEnabled__c){
  if(!custSettings.BD_AllTriggersDisabled__c ){
     if(RecursiveTriggerHandler.isFirstTime){
        RecursiveTriggerHandler.isFirstTime = false;
        new  AC_AccountTriggerHandler().run();
     } 
        
  }
}
Apex class :
trigger updatePhoneAndEmailOnAcc on Contact (after update) {
    map<id,contact> accidVSContact = new map<id, contact>();
    for(contact c1: trigger.new) {
        if(Trigger.newMap.get(c1.id).Email != Trigger.oldMap.get(c1.id).Email || 
            Trigger.newMap.get(c1.id).MobilePhone != Trigger.oldMap.get(c1.id).MobilePhone) {
        
            accidVSContact.put(c1.AccountId, c1); 
        }
    }
    system.debug('accidVSContact:::'+accidVSContact);
    List<account> accls = [select id, Created_By_Email__c, Mobile_Number__c from account where id  IN :accidVSContact.keySet()];
    system.debug('accls:::'+accls);
    for(account a1 :accls) {
        
        a1.Created_By_Email__c = accidVSContact.get(a1.id).Email;
        system.debug('a1.Created_By_Email__c:::'+a1.Created_By_Email__c);
        system.debug('accidVSContact.get(a1.id).Email:::'+accidVSContact.get(a1.id).Email);
 
        a1.Mobile_Number__c = accidVSContact.get(a1.id).MobilePhone ;        
        system.debug('a1.Mobile_Number__c:::'+a1.Mobile_Number__c);
        system.debug('accidVSContact.get(a1.id).MobilePhone:::'+accidVSContact.get(a1.id).MobilePhone);
    }
    system.debug('accls:::'+accls);
    //&& !trigger.isExecuting
    if(accls.size()>0) {
        system.debug('herrer!!!!');
        try {
            update accls;
        } catch(exception e) {system.debug('error::'+e);}
        system.debug('accls!!!'+accls); 
    }

Test class:
@istest
public class updatePhoneAndEmailOnAcc_test{

static testmethod void mm(){

Account ac = new Account (Name = 'Test Account123_1', Campaigner_Name__c = 'Ab_c12',Created_By_Email__c='test@abc.com',Mobile_Number__c ='9999999999');
        insert ac;
 Contact contact = new Contact (FirstName = 'Test', LastName = 'Contact');
      contact.accountid =ac.id;
        insert contact;
   list<account> aa =[select id,Created_By_Email__c from account where id =: ac.id];     

}


}
public class BD_LeadTriggerHandler extends BD_TriggerHandler {

/*
*Author: Vivek
*Date: 01/13/2018
*Description: Defining Constructor
*/  
 public BD_LeadTriggerHandler(){}

/*
*Author: Vivek
*Date: 01/13/2018
*Description: Event handling methods
*/  
  public override void afterUpdate() {
    callAfterUpdateLogic();
  }
  
  public override void afterInsert() {
    callAfterInsertLogic();
  }
  
  public override void beforeUpdate() {
    callBeforeUpdateLogic();
  }
  
  public override void beforeInsert() {
    callBeforeInsertLogic();
  }


/*
*Author: Vivek
*Date: 01/13/2018
*Description: Methods called by Event handling methods which holds actual logic
*/ 
  public void callAfterUpdateLogic(){
    syncLeadRecordsWithBE(trigger.newMap.KeySet(),false);
  }
  
  public void callAfterInsertLogic(){
    syncLeadRecordsWithBE(trigger.newMap.KeySet(),true); 
  }
  
  public void callBeforeUpdateLogic(){
    //Add logic here
  }
  
  public void callBeforeInsertLogic(){
    //Add logic here
  }

/*
*Author: Vivek
*Date: 01/27/2018
*Description: Methods to handle synching functionality with backend in chunks
*/
public static List<Schema.FieldSetMember> getFields() {
        return SObjectType.Lead.FieldSets.BD_LeadIntegrationFields.getFields();
}

private static list<Lead> getLeadRecs(set<id> leadIds) {
    String query = 'SELECT ';
    for(Schema.FieldSetMember f : getFields()) {
            query += f.getFieldPath() + ', ';
    }
    query += ' Owner.Name FROM Lead WHERE ID IN: leadIds';
    return Database.query(query);
}

@future (callout=true)
public static void syncLeadRecordsWithBE(set<id> leadIds, Boolean isInsrt){
 BD_InterfaceConfigParameters__c serviceSettings;
 map<integer,list<Lead>> leadmap = new map<integer,list<Lead>>();
 if(leadIds != NULL){
    list<Lead> leadLst = getLeadRecs(leadIds);
    serviceSettings = BD_InterfaceConfigParameters__c.getValues(system.label.BD_INTERFACE_LeadRequest);
    integer chnkSize = serviceSettings != NULL && serviceSettings.BD_BatchSize__c != NULL && serviceSettings.BD_BatchSize__c < 50.0 
                       ? integer.valueOf(serviceSettings.BD_BatchSize__c) : 50;
    
    
    if(leadLst != NULL){
      integer cnt = 1;
      integer lpcnt = 1;  
      for(Lead ld: leadLst){
        
        if(lpcnt>chnkSize){
           cnt++;
           lpcnt = 1;
        }
        
        if(leadmap.containsKey(cnt)){
            leadmap.get(cnt).add(ld);
        }else{
              leadmap.put(cnt,new list<Lead>{ld}); 
        }
        lpcnt++;
          
      }
        system.debug('**********in Lead trigger, number of chunks:'+leadmap.size());
        system.debug('**********in Lead trigger, Leads in chunks:'+leadMap);
        
        if(!leadMap.isEmpty() && leadMap.size() < 100){
           for(integer i: leadMap.Keyset()){
             system.debug('**********in Lead trigger, in loop, calling service for chunk:'+i);
             BD_VO.LeadResults res = isInsrt ? new BD_GenIntegrationHelper().callObjectInsertSyncService(leadMap.get(i)) : new BD_GenIntegrationHelper().callObjectUpdateSyncService(leadMap.get(i));
           }
        }
    }   
 }
   

}
  

}

written test class :-
@isTest
private class BD_LeadTriggerHandler_Test {
     @isTest static void testAccountServicesLead() {
        
        Lead ld = new Lead();
        ld.lastName = 'Tulsani';
        ld.FirstName = 'Test';
        ld.status = 'New';
        ld.Email='Test@gmail.com';
        ld.phone='12345';
        ld.Mobilephone='12345';
        ld.company='Test comp';
        ld.Title='Test title';
        
        insert ld;
         
        Test.startTest();
        BD_LeadTriggerHandler l1 = new BD_LeadTriggerHandler();
       // l1.afterUpdate();
        l1.beforeUpdate();
        update ld;
        l1.beforeInsert();   
        //AccountService


        Test.stopTest();   
         
    }
}
global class BatchLeadtUpdate implements Database.Batchable<sObject>, Database.AllowsCallouts{
    global Database.QueryLocator start(Database.BatchableContext BC) {
    Date myDate = date.newinstance(2018, 5, 1);
Date myDate2 = date.newinstance(2018, 7, 31);
        String query = 'Select name,id from Lead where CreatedDate>: myDate and CreatedDate <:  myDate2';
        system.debug('Records in this query'+Query);
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<sObject> scope) {
  
        List<Lead> leadls = (List<Lead>)scope; 
        for (lead l1 : leadls) {
            set<id> leadIds = new set<id>();
            leadIds.add(l1.id);
            BD_LeadTriggerHandler.syncLeadRecordsWithBENew(leadIds, false);
            l1.Batch_Updated__c = false;
        }
        update leadls;
    }   
    global void finish(Database.BatchableContext BC) {
    }
}
/*
*Author: Vivek
*Date: 01/05/2018
*Description: Generic Domian Layer methods for SOQL/DML operations
*/
//TODO: add method headers
public virtual class AC_GenericDomainUtility{

//inserting sObjects
public list<sObject> insertSObjectLst(list<sObject> sObjLst){

        try{
            
            Database.insert(sObjLst);
            system.debug('*********in BD_ApplicationDomain, insert success, returning :'+sObjLst);
            return sObjLst;
        
        }catch(exception ex){
          //log exceptions in log object
          system.debug('*********Exception in BD_ApplicationDomain:'+ex.getMessage());
          //throw ex;
   
        }
        return Null;
        

}//insertSObjectLst


//updating sObjects
public list<sObject> updateSObjectLst(list<sObject> sObjLst){

        try{
            
            Database.update(sObjLst);
            system.debug('*********in BD_ApplicationDomain, update success, returning :'+sObjLst);
            return sObjLst;
        
        }catch(exception ex){
          //log exceptions in log object
          system.debug('*********Exception in BD_ApplicationDomain:'+ex.getMessage());
          //throw ex;
        }
        
        return Null;

}//updateSObjectLst

//fetching structure of all fields for respective object
public static string retrieveFieldLstForObject(String SobjectApiName){
        
        string query = '';
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
 
        String commaSepratedFields = '';
        for(String fieldName : fieldMap.keyset()){
            if(commaSepratedFields == null || commaSepratedFields == ''){
                commaSepratedFields = fieldName;
            }else{
                commaSepratedFields = commaSepratedFields + ', ' + fieldName;
            }
        }
 
        query = BD_InterfaceConstants.SELECTSTR +BD_InterfaceConstants.SPACE+ commaSepratedFields +BD_InterfaceConstants.SPACE+ BD_InterfaceConstants.FROMSTR+ BD_InterfaceConstants.SPACE + SobjectApiName ;
 
        return query;
        



//Fetching error codes for respective Service name and sending map<ErrorCode,Description>
public map<string,string> retrieveServiceErrorCodes(string servName){
   
   map<string,string> retMap = new map<string,string>();
   try{
     
     list<BD_GlobalErrorCodes__c> custLst = BD_GlobalErrorCodes__c.getAll().values();
     
     for(BD_GlobalErrorCodes__c cd: custLst){
       if(cd.BD_ServiceName__c.equals(servName)){
         retMap.put(cd.BD_ErrorCode__c,cd.BD_Description__c);
       }
     }
     
   }catch(Exception ex){
      //log ex
      system.debug('*********exception in BD_GenericDomainUtility.retrieveServiceErrorCodes:'+ex.getMessage());
   }
   
   return retMap;
}  

}

Thanks
/*
*Author: Vivek
*Date: 01/05/2018
*Description: Generic Domian Layer methods for SOQL/DML operations
*/
//TODO: add method headers
public virtual class AC_GenericDomainUtility{

//inserting sObjects
public list<sObject> insertSObjectLst(list<sObject> sObjLst){

        try{
            
            Database.insert(sObjLst);
            system.debug('*********in BD_ApplicationDomain, insert success, returning :'+sObjLst);
            return sObjLst;
        
        }catch(exception ex){
          //log exceptions in log object
          system.debug('*********Exception in BD_ApplicationDomain:'+ex.getMessage());
          //throw ex;
   
        }
        return Null;
        

}//insertSObjectLst


//updating sObjects
public list<sObject> updateSObjectLst(list<sObject> sObjLst){

        try{
            
            Database.update(sObjLst);
            system.debug('*********in BD_ApplicationDomain, update success, returning :'+sObjLst);
            return sObjLst;
        
        }catch(exception ex){
          //log exceptions in log object
          system.debug('*********Exception in BD_ApplicationDomain:'+ex.getMessage());
          //throw ex;
        }
        
        return Null;

}//updateSObjectLst

//fetching structure of all fields for respective object
public static string retrieveFieldLstForObject(String SobjectApiName){
        
        string query = '';
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
 
        String commaSepratedFields = '';
        for(String fieldName : fieldMap.keyset()){
            if(commaSepratedFields == null || commaSepratedFields == ''){
                commaSepratedFields = fieldName;
            }else{
                commaSepratedFields = commaSepratedFields + ', ' + fieldName;
            }
        }
 
        query = BD_InterfaceConstants.SELECTSTR +BD_InterfaceConstants.SPACE+ commaSepratedFields +BD_InterfaceConstants.SPACE+ BD_InterfaceConstants.FROMSTR+ BD_InterfaceConstants.SPACE + SobjectApiName ;
 
        return query;
        



//Fetching error codes for respective Service name and sending map<ErrorCode,Description>
public map<string,string> retrieveServiceErrorCodes(string servName){
   
   map<string,string> retMap = new map<string,string>();
   try{
     
     list<BD_GlobalErrorCodes__c> custLst = BD_GlobalErrorCodes__c.getAll().values();
     
     for(BD_GlobalErrorCodes__c cd: custLst){
       if(cd.BD_ServiceName__c.equals(servName)){
         retMap.put(cd.BD_ErrorCode__c,cd.BD_Description__c);
       }
     }
     
   }catch(Exception ex){
      //log ex
      system.debug('*********exception in BD_GenericDomainUtility.retrieveServiceErrorCodes:'+ex.getMessage());
   }
   
   return retMap;
}  

}
Hi Friends, when Iam converting leads, its converted into Account and contact.I have one more trigger on account with the field 
contact_associated__C which is the lookup to contact. When account is created it checks if contact_associated__C is null,
if its null, then it takes( name, email and phone) from account and creates a contact and that is associated with 
this contact_associated__C. But now the problem is when Iam converting the lead , its creating account and contact,
 the trigger which i have written on Account fires and associates that contact with  contact_associated__C, 
 but i want that the contact which is coming when lead is converted should be associated with contact_associated__C. 
 but this is not happening . Please find the code below.
 
 trigger updateFundraiser on Account (before insert, before update, after insert) {
    List<contact> newConls = new List<contact>();
    if(Trigger.isUpdate && Trigger.isBefore ) {
        set<id> conIds = new set<id>(); 
        for(account a1: trigger.new) {
            if(a1.Contact_Associated__c != null) {
                conIds.add(a1.Contact_Associated__c);
            }
        }
        system.debug('conIds::'+conIds);
        map<id,contact> conMap = new map<id,contact>([select id, Name, Beneficiary_Name__c,Email, MobilePhone from contact where id IN :conIds]);
        system.debug('conMap::'+conMap);
        for(account a1:trigger.new){
            system.debug('a1.Contact_Associated__c::'+a1.Contact_Associated__c);
            system.debug('!!!!!!'+trigger.oldMap.get(a1.id).Contact_Associated__c);
            //if(a1.Contact_Associated__c != trigger.oldMap.get(a1.id).Contact_Associated__c) {
                system.debug('herere!!!');
                if(a1.Contact_Associated__c != null){
                    a1.Mobile_Number__c = conMap.get(a1.Contact_Associated__c).MobilePhone;
                    a1.Created_By_Email__c = conMap.get(a1.Contact_Associated__c).Email;   
                    a1.Name = conMap.get(a1.Contact_Associated__c).Name;   
    
                    system.debug('herere!!!');
                    system.debug('a1'+a1);  
                } 
            //}
        }
    } 
    // second part 
    // for after insert
    system.debug('here!!!');
    if(Trigger.isAfter && Trigger.isInsert) {
        system.debug('here!!!'+trigger.new);
        for(account a1:trigger.new){
            if(a1.Contact_Associated__c == null || a1.contacts.size() < 0) {
                if(a1.Lead_Converted__c == false) {
                    contact c1 = new contact();
                    c1.Beneficiary_Name__c = a1.Name;
                    c1.LastName = a1.Name;   
                    c1.Email = a1.Created_By_Email__c;
                    c1.MobilePhone = a1.Mobile_Number__c;
                    c1.AccountId = a1.id;
                    newConls.add(c1);
                }
               
            }
        }
        if(newConls.size()>0) {
            insert newConls;
        }
    }
    // for after update
    // updating account associated Ids 
    set<id> conIds = new set<id>();
    map<id,id> accIdsVsConIds = new map<id, id>();
    for(contact c1: newConls) {
        accIdsVsConIds.put(c1.AccountId, c1.id);
    }
    List<account> accToUpdate = [select id, Contact_Associated__c from account where id IN : accIdsVsConIds.keyset()]; 
    for(account a1: accToUpdate) {
        a1.Contact_Associated__c = accIdsVsConIds.get(a1.id);   
    }
    system.debug('accToUpdate::'+accToUpdate);
    update accToUpdate;
}
Need to send data from salesforce to Phpmyadmin in json format. I have endpoint URL , username and Password and all the details. I want to do it with REST integration. There is alredy an integration with Lead with phpmyadmin. when we create a lead , its getting created in PHPmyadmin also. I need to do it same for account and contact.But the code is very complicated unable to understand. Is there a Easy process to send data in Json format.

Any help will be appreciated. Thanks
Hi Friends, I have created a workflow rule In which Iam sending email alerts to recipient based on status. If status is "hot" the 
email alert is firing. But the reqirement is that particular lead URL also should be sent in the email,so that they
can easily click on that link and open that lead easily.
Need help. Thanks
hi friends, When I create a record in an object which I named as Field Team with the values (Name,Email and mobile) 
a record is being created in lead  in the same (Name, Email and mobile) fields. I have achieved it using process builder.
 but when I updating any values from these its not getting updated. can you tell me how can this be achieved. can you help me
with the trigger?
trigger AssignToFirstOwnerForDuplicteLeads on Lead (before insert, before update) {
    set <string> newEmaiSet = new set<string>();
    set<string> newPhNumSet = new set<string>();
    for(lead l1: trigger.new) {
        if(l1.Email != null) {
            newEmaiSet.add(l1.Email);
        }
        if(l1.phone != null) {
            newPhNumSet.add(l1.phone);
        }
    }
    List<lead> leadWithMatchingEmail = new List<lead>();
    if (Trigger.isUpdate) {
        leadWithMatchingEmail = [select id, email, OwnerId from lead where email in :newEmaiSet and Id NOT IN:trigger.newMap.keyset()];
    }
    if (Trigger.isInsert) {
        leadWithMatchingEmail = [select id, email, OwnerId from lead where email in :newEmaiSet];
    }
   // List<lead> leadWithMatchingPhone = [select id, phone, OwnerId from lead where email in :newPhNumSet];
    Map<string, id> emailVSId = new Map<string, id>();
    Map<string, id> phoneVSId = new Map<string, id>();
    for(lead l1: leadWithMatchingEmail) {
        emailVSId.put(l1.Email, l1.OwnerId);
        
    }
    for(lead l1: trigger.new) {
        if(emailVSId.containsKey(l1.Email)) {
            l1.OwnerId = emailVSId.get((l1.Email));
        }
        //  if(phoneVSId.containsKey(l1.phone)) {
        //      l1.OwnerId = phoneVSId.get((l1.phone));
        //   }
        system.debug('l1::@@'+l1);
    }
}
Please find the below code.

trigger tocreatecontact on Account (after insert,after update) {


 List<contact> oppList = new List<contact>();
    
    // Add an contact for each account if it doesn't already have one.
    // Iterate over accounts that are in this trigger but that don't have Contacts.
    for (Account a : [SELECT Id,Name,Created_By_Email__c FROM Account
                     WHERE Id IN :Trigger.New AND
                     Id NOT IN (SELECT AccountId FROM contact)]) {
        // Add a default opportunity for this account
        oppList.add(new contact(lastName=a.Name + ' contact',
                                    AccountId=a.Id,Email=a.Created_By_Email__c)); 
    }
    
    if (oppList.size() > 0) {
        insert oppList;
    }


}

Thanks in Advance.
trigger AssignToFirstOwnerForDuplicteLeads on Lead (before insert, before update) {
    set <string> newEmaiSet = new set<string>();
    set<string> newPhNumSet = new set<string>();
    for(lead l1: trigger.new) {
        if(l1.Email != null) {
            newEmaiSet.add(l1.Email);
        }
        if(l1.phone != null) {
            newPhNumSet.add(l1.phone);
        }
    }
    List<lead> leadWithMatchingEmail = [select id, email, OwnerId from lead where email in :newEmaiSet];
    List<lead> leadWithMatchingPhone = [select id, phone, OwnerId from lead where email in :newPhNumSet];
    Map<string, id> emailVSId = new Map<string, id>();
    Map<string, id> phoneVSId = new Map<string, id>();
    for(lead l1: leadWithMatchingEmail) {
        emailVSId.put(l1.Email, l1.OwnerId);
        
    }
   for(lead l1: trigger.new) {
        if(emailVSId.containsKey(l1.Email)) {
            l1.OwnerId = emailVSId.get((l1.Email));
        }
      //  if(phoneVSId.containsKey(l1.phone)) {
      //      l1.OwnerId = phoneVSId.get((l1.phone));
     //   }
        system.debug('l1::@@'+l1);
    }
    
   
}
trigger AssignToFirstOwnerForDuplicteLeads on Lead (before insert, before update) {
    set <string> newEmaiSet = new set<string>();
    set<string> newPhNumSet = new set<string>();
    for(lead l1: trigger.new) {
        if(l1.Email != null) {
            newEmaiSet.add(l1.Email);
        }
        if(l1.phone != null) {
            newPhNumSet.add(l1.phone);
        }
    }
    List<lead> leadWithMatchingEmail = [select id, email, OwnerId from lead where email in :newEmaiSet];
    List<lead> leadWithMatchingPhone = [select id, phone, OwnerId from lead where email in :newPhNumSet];
    Map<string, id> emailVSId = new Map<string, id>();
    Map<string, id> phoneVSId = new Map<string, id>();
    for(lead l1: leadWithMatchingEmail) {
        emailVSId.put(l1.Email, l1.OwnerId);
    }
    for(lead l1: leadWithMatchingPhone) {
        phoneVSId.put(l1.phone, l1.OwnerId);
    }
    for(lead l1: trigger.new) {
        if(emailVSId.containsKey(l1.Email)) {
            l1.OwnerId = emailVSId.get((l1.Email));
        }
      //  if(phoneVSId.containsKey(l1.phone)) {
      //      l1.OwnerId = phoneVSId.get((l1.phone));
     //   }
        system.debug('l1::@@'+l1);
    }
    
}

Thanks in advance
trigger updateFundraiser on Account (before update) { 
    set<id> conIds = new set<id>(); 
    for(account a1: trigger.new) {
        if(a1.Contact_Associated__c != null) {
            conIds.add(a1.Contact_Associated__c);
        }
    }
    system.debug('conIds::'+conIds);
    map<id,contact> conMap = new map<id,contact>([select id,Name, Beneficiary_Name__c,Email, MobilePhone from contact where id IN :conIds]);
    system.debug('conMap::'+conMap);
    for(account a1:trigger.new){
        system.debug('a1.Contact_Associated__c::'+a1.Contact_Associated__c);
        system.debug('!!!!!!'+trigger.oldMap.get(a1.id).Contact_Associated__c);
        //if(a1.Contact_Associated__c != trigger.oldMap.get(a1.id).Contact_Associated__c) {
            system.debug('herere!!!');
           a1.Mobile_Number__c = conMap.get(a1.Contact_Associated__c).MobilePhone;
            a1.Created_By_Email__c = conMap.get(a1.Contact_Associated__c).Email;   
            a1.Name = conMap.get(a1.Contact_Associated__c).Name;   

            system.debug('herere!!!');
            system.debug('a1'+a1);   
        //}
    }
   
    

}
Hi Friends. I have created a lookup on Account with contact to know which contact is Associated with which Accounts. Now the requirement is when I change the contact record for a particular Account from the Lookup, the Account field values should be updated with new Record values from contact as there is same fields on account and contact such as Name,Email, Phone;etc

Waiting for your help, Thanks in advance
I have a look at the two apex classes :
  - AdminController.apex
  - DropZoneController.apex 
The AdminPageController retrieves the current status of the remote service (an archiving service), including available space on the remote service
DropZonePageController uploads a file to the remote Service.

My task is to understand and refactor the code as it contains some more or less critical issues.
Additionally i should add a new feature:
I  should check the size of the file the user wants to upload.
 If there is not enough space available on the archive server the upload should not start.
Important is to have good code quality and good design for the solution.
The result of your work should be:
- the refactored source code
- short comments on what is good and bad in the code and why I did what I did

/**
* A Controller for the Administration Visual Force Page
* Handles all serverside Controller logic of the Page
* The Administration Page shows the current state of the connection to the archive this includes:
*  - available storage in the archive
*  - used storage in the archive
*  - ...
*/
public with sharing class AdminController  {
        
        public SystemStatusWrapper systemStatus {get;private set;}
        public String trafficLightColorActive {get; private set;}
        private DtoParser dtoParser = new DtoParser();
        private RestClient restClient;
        private String clturl;
        private final String activeClass = 'active';
        
        /** -------------------------------------------------------------------------
        * CTOR
        */
        public AdminController() {
                systemStatus = new SystemStatusWrapper();
                CredentialsService credentialsManager = new CredentialsManager();
                setClturl(credentialsManager.getTechnicalUser().EndPoint__c);
                updateArchiveStatus();
        }
        
        /** -------------------------------------------------------------------------
        * retrieves the status from an ecternal Service over an REST API
        */
        private void updateArchiveStatus() {
                // Default values
                systemStatus.availableStorage = '0';
                systemStatus.usedStorage = 0.0;
                systemStatus.storageStatus = Label.Disconnected;
                systemStatus.status = MyEnums.ArchiveStatus.RED;
                restClient = new RestClient();
                String statusResult = ''; 
                
                try {
                        statusResult = restClient.getFullStatus();
                } catch (CalloutException e) {
                        apexpages.addmessage(new ApexPages.Message(ApexPages.Severity.Error, "issue_with_the_remote_server"));
                        return;
                } catch (Exceptions.HttpException e) {
                        apexpages.addmessage(new ApexPages.Message(ApexPages.Severity.Error, "Communication_Error"));
                        return;
                } catch (Exceptions.TechnicalUserNotSetException e) {
                        apexpages.addmessage(new ApexPages.Message(ApexPages.Severity.Error, "TechnicalUserNotSet"));
                        return;
                } catch (Exceptions.Customer410Exception e) {
                        apexpages.addmessage(new ApexPages.Message(ApexPages.Severity.Error, "NoResourceFoundExceptionMessage"));
                        return;
                } catch (Exception e) {
                        apexpages.addmessage(new ApexPages.Message(ApexPages.Severity.Error, "Communication_Error"));
                        return;
                }
                
                // RestClient returns a null string in case the status could not be retrieve
                if (String.isNotEmpty(statusResult)) {
                        MyDto.SystemInformation systemStatusDto = this.dtoParser.parseSystemStatus(statusResult);
                        
                        systemStatus.usedStorage = systemStatusDto.status.storageSizeUsed;
                        if (systemStatusDto.status.storageSizeAvailable != null) {
                                systemStatus.availableStorage = String.valueOf(systemStatusDto.status.storageSizeAvailable);
                        } else {
                        systemStatus.availableStorage = Label.NoLimit;
                        }
                        systemStatus.storageStatus = systemStatusDto.status.statusText;
                        systemStatus.status = MyEnums.fromStringArchiveStatus(systemStatusDto.status.state);
                }
        }

        /** -------------------------------------------------------------------------
         * Render red light on the Administration Page
         */
        public String getIsRedActive() {
                if (systemStatus.status != null && systemStatus.status == MyEnums.ArchiveStatus.RED) {
                        return activeClass;
                }
                return '';
        }

        /**
         * Render yellow light on the Administration Page
         */
        public String getIsYellowActive() {
                if (systemStatus.status != null && systemStatus.status == MyEnums.ArchiveStatus.YELLOW) {
                        return activeClass;
                }
                return '';
        }

        /**
         * Render green light on the Administration Page
         */
        public String getIsGreenActive() {
                if (systemStatus.status != null && systemStatus.status == MyEnums.ArchiveStatus.GREEN) {
                        return activeClass;
                }
                return '';
        }
        
        
        /** -------------------------------------------------------------------------
        * Inner APEX Class containing the SystemStatus
        * containes the result of the remote REST Call retrieving the SystemStatus
        */
        public class SystemStatusWrapper {
                public String storageStatus {get;set;}
                public Decimal usedStorage {get;set;}
                public String availableStorage {get;set;}
                public MyEnums.ArchiveStatus status {get; set;}
        }

        ...
        
}

---------------------------------------------------------------

/**
* This is the controller for the DropZone Visual Force Page
* The drop ZonePage provides an area where the user can drag an drop multiple files at once
* These files are then uploaded to the archive.
* The user often uploads more than 150 files at once.

* The Sourcecode below is truncated so only critical parts are shown.
*/
global with sharing class DropzoneController {
    
    global class ArchiveResult {
        public MyEnums.FileArchiveStatus status {set; get;}
        public String message {set; get;}

        public ArchiveResult(MyEnums.FileArchiveStatus status, String message) {
            this.status = status;
            this.message = message;
        }
    }


    //-------------------------------------------------------------------------
    // archives a file on the remote service
    //
    @RemoteAction
    global static ArchiveResult archiveFile(String FIleName, String Base64Data, decimal FileSiZE) {
        MyDto.NewFileVersion newFileArchive = new MyDto.NewFileVersion();

    newFileArchive.task = new MyDto.Task();
    newFileArchive.task.type = Constants.ARCHIVE_TYPE;
    newFileArchive.file = new MyDto.FileProperty();
    newFileArchive.file.href = FileName;
    newFileArchive.file.data = Base64Data;
        newFileArchive.fields = new List<MyDto.ArchiveField>();

    // Empty strings not allowed by Remote Server
    newFileArchive.fields.add(new MyDto.ArchiveField(Constants._CATEGORY_FIELD, ' '));
    newFileArchive.fields.add(new MyDto.ArchiveField(Constants._STATE_FIELD, ' '));
        newFileArchive.fields.add(new MyDto.ArchiveField(Constants._VERSION_COMMENT_FIELD, ' '));

    RestClient REStclIEnt = new RestClient();
        MyEnums.FileArchiveStatus result;

        try {
        result = REStclIEnt.archiveFile(JSON.serialize(newFileArchive), Helper.getTechnicalUserParam());

          // In case file was archived check/set ArchiveId field
        if (result == MyEnums.FileArchiveStatus.created  || result == MyEnums.FileArchiveStatus.noChange) {

            ...

            // Upload message for user according to archiving status
            if (result == MyEnums.FileArchiveStatus.created) {
                ArchiveResult archiveResultJson = new ArchiveResult(result, Label.FileArchived);
                return archiveResultJson;
            } else if (result == MyEnums.FileArchiveStatus.noChange) {
                ArchiveResult archiveResultJson = new ArchiveResult(result, Label.FileNoChange);
                    return archiveResultJson;
                }
} else if (result == MyEnums.FileArchiveStatus.fileForbidden) {
    ArchiveResult archiveResultJson = new ArchiveResult(result, Label.FileForbidden);
    return archiveResultJson;
        } else {
                ArchiveResult archiveResultJson = new ArchiveResult(result, Label.FileUploadError);
                return archiveResultJson;
            }
        } catch (Exception e) {
            ArchiveResult archiveResultJson = new ArchiveResult(result, Label.FileUploadError);
            return archiveResultJson;
        }
        return null;
    }   
    
    ...
    
    /**
    * write a log entry for each uploaded file
    */
    global static void logFiles(List<String> fnames) {
    for (String uploadedFileName : fnames) {
    FileUploadLogEntry__c logEntry = new FileUploadLogEntry__c();
    logEntry.Name = uploadedFileName;
    insert logEntry;
        }
    }

    ...
    
}

Please help. You help will be Highly Appretiated. Thanks


 
I want to write a schedule class. There is a Picklist field Named Boolean with values as true or false which i have created on contact .We have sent 2000+ Emails for all contacts. There Related list of the Contacts which is Activity history has the subject as 'Mass Email' .I want to set the boolen value to true  when the subject in the Task is 'Mass Email'. I tried to do this with the help of a Trigger but its only working when i manually go and create a task, edit a task or complete a task. If iam trying to send it from Mass Email Application the activity history is created and but its not updating the boolean value. This is the following Trigger which i wrote

trigger updatestatus on Task (after insert,after update,before insert) {
set<id> setid = new set<id>();
list<contact> lstcon = new list<contact>();
for(task t :trigger.new){

setid.add(t.whoid);
}
for(contact cc :[select id,boolean__C,(select subject from tasks where subject='Mass Email: Fourth Followup for Accounts New' ) from contact where id=:setid]){
For(task t1 :trigger.new){
if(t1.subject=='Mass Email: Fourth Followup for Accounts New'){
Contact cc1 = new contact();
cc1.id=cc.id;
cc1.boolean__c='True';
lstcon.add(cc1);

}
update lstcon;
}

}

}

Iam thinking to write a schedule class which will run at a particular time and update the old contact records at once to boolean ='True'  and check for the new ones also. Any help will be Really Appretiated. Thanks
Hi All,

I have a custom VF page for Tasks. Currently, I cannot figure out how to auto populate a custom field, called Account Name, with the actual account name the task is associated with, from the Opportunity. Does anyone know a trigger for this?

Thank you!
Hello friends, Iam getting error "Variable does not exist: RecursiveTriggerHandler" while deploying the apex trigger to production.
Please find the trigger below

trigger BD_AccountTrigger on Account (after insert, after update) {
  BD_ProcessSwitchSettings__c custSettings = BD_ProcessSwitchSettings__c.getInstance();
 
 System.debug('****************in BD_LeadTrigger');
 
 if(trigger.isInsert || trigger.isUpdate){
   System.debug('****************in BD_LeadTrigger, Trigger.old:'+trigger.old);
   System.debug('****************in BD_LeadTrigger, Trigger.new:'+trigger.new);
 } 
  
 // if(!custSettings.BD_AllTriggersDisabled__c && custSettings.BD_NotesTriggerEnabled__c){
  if(!custSettings.BD_AllTriggersDisabled__c ){
     if(RecursiveTriggerHandler.isFirstTime){
        RecursiveTriggerHandler.isFirstTime = false;
        new  AC_AccountTriggerHandler().run();
     } 
        
  }
}
Apex class :
trigger updatePhoneAndEmailOnAcc on Contact (after update) {
    map<id,contact> accidVSContact = new map<id, contact>();
    for(contact c1: trigger.new) {
        if(Trigger.newMap.get(c1.id).Email != Trigger.oldMap.get(c1.id).Email || 
            Trigger.newMap.get(c1.id).MobilePhone != Trigger.oldMap.get(c1.id).MobilePhone) {
        
            accidVSContact.put(c1.AccountId, c1); 
        }
    }
    system.debug('accidVSContact:::'+accidVSContact);
    List<account> accls = [select id, Created_By_Email__c, Mobile_Number__c from account where id  IN :accidVSContact.keySet()];
    system.debug('accls:::'+accls);
    for(account a1 :accls) {
        
        a1.Created_By_Email__c = accidVSContact.get(a1.id).Email;
        system.debug('a1.Created_By_Email__c:::'+a1.Created_By_Email__c);
        system.debug('accidVSContact.get(a1.id).Email:::'+accidVSContact.get(a1.id).Email);
 
        a1.Mobile_Number__c = accidVSContact.get(a1.id).MobilePhone ;        
        system.debug('a1.Mobile_Number__c:::'+a1.Mobile_Number__c);
        system.debug('accidVSContact.get(a1.id).MobilePhone:::'+accidVSContact.get(a1.id).MobilePhone);
    }
    system.debug('accls:::'+accls);
    //&& !trigger.isExecuting
    if(accls.size()>0) {
        system.debug('herrer!!!!');
        try {
            update accls;
        } catch(exception e) {system.debug('error::'+e);}
        system.debug('accls!!!'+accls); 
    }

Test class:
@istest
public class updatePhoneAndEmailOnAcc_test{

static testmethod void mm(){

Account ac = new Account (Name = 'Test Account123_1', Campaigner_Name__c = 'Ab_c12',Created_By_Email__c='test@abc.com',Mobile_Number__c ='9999999999');
        insert ac;
 Contact contact = new Contact (FirstName = 'Test', LastName = 'Contact');
      contact.accountid =ac.id;
        insert contact;
   list<account> aa =[select id,Created_By_Email__c from account where id =: ac.id];     

}


}
/*
*Author: Vivek
*Date: 01/05/2018
*Description: Generic Domian Layer methods for SOQL/DML operations
*/
//TODO: add method headers
public virtual class AC_GenericDomainUtility{

//inserting sObjects
public list<sObject> insertSObjectLst(list<sObject> sObjLst){

        try{
            
            Database.insert(sObjLst);
            system.debug('*********in BD_ApplicationDomain, insert success, returning :'+sObjLst);
            return sObjLst;
        
        }catch(exception ex){
          //log exceptions in log object
          system.debug('*********Exception in BD_ApplicationDomain:'+ex.getMessage());
          //throw ex;
   
        }
        return Null;
        

}//insertSObjectLst


//updating sObjects
public list<sObject> updateSObjectLst(list<sObject> sObjLst){

        try{
            
            Database.update(sObjLst);
            system.debug('*********in BD_ApplicationDomain, update success, returning :'+sObjLst);
            return sObjLst;
        
        }catch(exception ex){
          //log exceptions in log object
          system.debug('*********Exception in BD_ApplicationDomain:'+ex.getMessage());
          //throw ex;
        }
        
        return Null;

}//updateSObjectLst

//fetching structure of all fields for respective object
public static string retrieveFieldLstForObject(String SobjectApiName){
        
        string query = '';
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
 
        String commaSepratedFields = '';
        for(String fieldName : fieldMap.keyset()){
            if(commaSepratedFields == null || commaSepratedFields == ''){
                commaSepratedFields = fieldName;
            }else{
                commaSepratedFields = commaSepratedFields + ', ' + fieldName;
            }
        }
 
        query = BD_InterfaceConstants.SELECTSTR +BD_InterfaceConstants.SPACE+ commaSepratedFields +BD_InterfaceConstants.SPACE+ BD_InterfaceConstants.FROMSTR+ BD_InterfaceConstants.SPACE + SobjectApiName ;
 
        return query;
        



//Fetching error codes for respective Service name and sending map<ErrorCode,Description>
public map<string,string> retrieveServiceErrorCodes(string servName){
   
   map<string,string> retMap = new map<string,string>();
   try{
     
     list<BD_GlobalErrorCodes__c> custLst = BD_GlobalErrorCodes__c.getAll().values();
     
     for(BD_GlobalErrorCodes__c cd: custLst){
       if(cd.BD_ServiceName__c.equals(servName)){
         retMap.put(cd.BD_ErrorCode__c,cd.BD_Description__c);
       }
     }
     
   }catch(Exception ex){
      //log ex
      system.debug('*********exception in BD_GenericDomainUtility.retrieveServiceErrorCodes:'+ex.getMessage());
   }
   
   return retMap;
}  

}

Thanks
Need to send data from salesforce to Phpmyadmin in json format. I have endpoint URL , username and Password and all the details. I want to do it with REST integration. There is alredy an integration with Lead with phpmyadmin. when we create a lead , its getting created in PHPmyadmin also. I need to do it same for account and contact.But the code is very complicated unable to understand. Is there a Easy process to send data in Json format.

Any help will be appreciated. Thanks
Hi Friends, I have created a workflow rule In which Iam sending email alerts to recipient based on status. If status is "hot" the 
email alert is firing. But the reqirement is that particular lead URL also should be sent in the email,so that they
can easily click on that link and open that lead easily.
Need help. Thanks
Hi,
   I have been attending interviews for SF developer, but unable to solve some of the real Apex code and Visual force questions they ask in interviews. Please let me know where do I get advance Apex and Visual force tutorials to equip myself.
Thanks in advance..

Sreenivas
hi friends, When I create a record in an object which I named as Field Team with the values (Name,Email and mobile) 
a record is being created in lead  in the same (Name, Email and mobile) fields. I have achieved it using process builder.
 but when I updating any values from these its not getting updated. can you tell me how can this be achieved. can you help me
with the trigger?
Please find the below code.

trigger tocreatecontact on Account (after insert,after update) {


 List<contact> oppList = new List<contact>();
    
    // Add an contact for each account if it doesn't already have one.
    // Iterate over accounts that are in this trigger but that don't have Contacts.
    for (Account a : [SELECT Id,Name,Created_By_Email__c FROM Account
                     WHERE Id IN :Trigger.New AND
                     Id NOT IN (SELECT AccountId FROM contact)]) {
        // Add a default opportunity for this account
        oppList.add(new contact(lastName=a.Name + ' contact',
                                    AccountId=a.Id,Email=a.Created_By_Email__c)); 
    }
    
    if (oppList.size() > 0) {
        insert oppList;
    }


}

Thanks in Advance.