• RaoS
  • NEWBIE
  • 70 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 26
    Replies
Hello Friends,
Currently the "Log a Call" button exists on the Open Activities related list.  The user is wanting to have this on the "Highlights Panel" of the Contact object as shown below.

User-added image

Kindly let me know if we can do this and how to do this.

Any help is greatly appreciated.

Thanks
Rao
  • January 23, 2020
  • Like
  • 0
Hi Gurus,
I have a trigger which inturn calls a apex method to make a API call to the third party.  After the third party returns the response, I should he updating the values on the record which called the API.

I am able to capture the response but while updating the record I am getting the error.  I am sure, the way I am calling the update method is causing the issue.  

Here is the trigger code:
-------------------------------------------

trigger updateSEToTR on Service_Entity__c (after insert, after update) { 
    //instead of calling the method directly, first iterate over all records and collects Ids of all records to be processed.
    //synchSEDeptSitesToTR.syncSEToTR();
       List<Id> lstSEToUpdate=new List<Id>(); 
        system.debug('---Inside---');
        if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isUpdate && Trigger.isAfter))
        //if((Trigger.isInsert && Trigger.isAfter))
        {
            for(Service_Entity__c se : (List<Service_Entity__c>)trigger.new)
            {   
                If (se.Sync_Status__c<>'Error' && se.Send_To_TR__c==True)
                {
                    lstSEToUpdate.add(se.Id);
                }
            }
        system.debug('---lstSEToUpdate.size()---'+lstSEToUpdate.size());    
        //if there are records to update, call future method for callout, future method can only take list of Ids and can't take objects. Also Trigger.New and Trigger.IsInsert etc will not work in future method.
         If (lstSEToUpdate.size()> 0){
            synchSEDeptSitesToTR.syncSEToTR(lstSEToUpdate);
            synchSEDeptSitesToTR.LockSERecord(lstSEToUpdate);
         }

    }system.debug('-At the End--lstSEToUpdate.size()---'+lstSEToUpdate.size());        
}
-------------------------------------------
Here is the Apex code:
--------------------------------------------
public class synchSEDeptSitesToTR {
   @Future(callout=true) //needed to change the annotation
    public static void syncSEToTR(List<String> serviceEntityIds) {
        String trCustomerCode,trCustomerId,syncStatus,syncErrorMessage;
        List<Id> lstServiceEntitiesToUpdate=new List<Id>();
        system.debug('--serviceEntityIds--'+serviceEntityIds);
        List<Service_Entity__c> recordsToProcess=[Select Name, Id,Sync_Status__c,Send_To_TR__c, TR_Customer_Code__c,TR_Customer_Id__c,GP_Customer_Accounting_Code__c,CurrencyISOCode,
                                                  AcquisitionDB__c,Customer_Name__c,Legal_Entity__c,Sub_Branch__c,Accountrep__c,
                                                  NextRateIncrease__c,LeadSource__c,Account_Industry__c,DiscontinueService__c,
                                                  Taxable__c,TaxCode__c,Delivery_Contact__c,Delivery_Address__c,Delivery_Address_2__c,
                                                  Delivery_Contact_Phone__c,Delivery_Contact_Email__c,Delivery_State__c,Delivery_City__c,
                                                  Delivery_Postal__c,Billing_Contact__c,Billing_Address__c,Billing_Address_2__c,Billing_Contact_Phone__c,
                                                  Billing_Contact_Email__c,Billing_State__c,Billing_City__c,Billing_Postal__c,PO_Number__c,
                                                  Billing_Group__c,Breach_Reporting_Services__c,Admin_Fee_V4__c,Online_Tools__c,Billing_Dept__c,
                                                  Information__c,Customer_Notes__c,Operations_Note__c,Display_as_a_pop_up_note__c,Conversion_Services__c,
                                                  HC_Storage__c,Shredding__c,Software__c,Media_Vault__c,AcctPrefixCode__c,TR_Account_Status__c,TR_NextRateIncrease__c,
                                                  Sub_Branch__r.Sub_Branch_Code__c
                                                  from Service_Entity__c where id in : serviceEntityIds and Send_To_TR__c=True and Sync_Status__c!='Error'];
        system.debug('--Before Try--');
        try{
        //get the records, added couple of more fields which are being used down
        system.debug('--Before For--');
        for (Service_Entity__c se1 : recordsToProcess)
        {
        system.debug('--Inside For--');
            string reqXML=createXMLforServiceEntity(se1);
            system.debug('--ServiceEntity--reqXML--' +reqXML);    
            
            HttpResponse response;
            //LockSERecord(recordsToProcess);
            if ((se1.TR_Customer_Id__c==null || se1.TR_Customer_Id__c=='0') && se1.Send_To_TR__c==True)
            { 
                system.debug('------before insertTR is called');
            response=insertTR(reqXML,'E'); 
                system.debug('------after insertTR is called');
            }
            else if ((se1.TR_Customer_Id__c<>null || se1.TR_Customer_Id__c<>'0') && se1.Send_To_TR__c==True)
            {
            system.debug('------before updateTR is called');    
            system.debug('--Userinfo.getName()---'+Userinfo.getName());    
            response=updateTR(reqXML,'E'); 
            system.debug('after updateTR is called');
            }    
            
            // Parse the JSON response
            // 400 bad request
            // 200 success
            String respText=response.getBody();
            if (response.getStatusCode() != 200) {
                syncStatus='Error';
                syncErrorMessage=respText.substringBetween('<ErrorMessage>','</ErrorMessage>');
                System.debug('The status code returned was not expected: ' +
                             response.getStatusCode() + ' ' + response.getStatus());
                system.debug('syncStatus:'+syncStatus); 
            } else {
                System.debug(response.getBody());
                if (response.getStatusCode() == 200){
                    system.debug('---' + response.getStatusCode() + ' ' + response.getStatus());
                    trCustomerCode=respText.substringBetween('<TRCustomerCode>', '</TRCustomerCode>');
                    trCustomerId=respText.substringBetween('<TRCustomerId>', '</TRCustomerId>');
                    syncErrorMessage='';
                    syncStatus='Synced';
                    system.debug('trCustomerCode:'+trCustomerCode);
                    system.debug(' trCustomerId:'+ trCustomerId);
                    system.debug('syncStatus:'+syncStatus); 
                    se1.TR_Customer_Code__c=trCustomerCode;
                    se1.TR_Customer_Id__c=trCustomerId;
                    se1.Sync_Status__c=syncStatus;
                    
                  //lstServiceEntitiesToUpdate.add(se1.Id);  
                }
                //Method to update this record with the values from the response
                updateSERecord(se1.Id,trCustomerCode,trCustomerId,syncStatus);
                
            }
            
        }

        }
        catch(Exception e){ 
            System.debug('Exception:'+e.getMessage());
        } 
          
         UnLockSERecord(recordsToProcess);
    }
    //method to get token
    public static string getToken()
    {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(tokenUrl);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        String jsonBody ='username=' + 'user1' + '&password=' + '12345';
        request.setBody(jsonBody);
        request.setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
        HttpResponse response = http.send(request);  

        String respText=response.getBody();
        String respToken=respText.substringAfter('access_token');
        
        //System.debug('---respToken---' + respToken);
        String respToken1=respText.substringBetween('access_token', 'token_type');
        String respToken2=respToken1.replace('":"','');
        String respToken3=respToken2.replace('","','');
   
        System.debug('--respToken3--' +respToken3);  
        
        return respToken3;    
    }
    //new method to create XML for Service entity
    public static string createXMLforServiceEntity(Service_Entity__c se1){
        String ZeroOne='';
        string seReq='';
        seReq=seReq+'<ServiceEntity>';
        seReq=seReq+'<ServiceEntityID>' + se1.Id+'</ServiceEntityID>';
        seReq=seReq+'<ServiceEntityCode>' + se1.Name+'</ServiceEntityCode>';
        seReq=seReq+'<TRCustomerCode>' + se1.TR_Customer_Code__c+'</TRCustomerCode>';
        //seReq = seReq.replace('null','');
        seReq=seReq+'<TRCustomerId>' + se1.TR_Customer_Id__c+'</TRCustomerId>';
        seReq=seReq+'<CustomerName>' + se1.Customer_Name__c+'</CustomerName>';
        //seReq=seReq+'<SubBranch>' + se1.Sub_Branch__c+'</SubBranch>';
        //seReq = seReq.replace('null','');
        seReq=seReq+'<SubBranchCode>'+se1.Sub_Branch__r.Sub_Branch_Code__c+'</SubBranchCode>';
        If (se1.AcctPrefixCode__c<>'-')
        {
        seReq=seReq+'<AccountPrefixCode>' + se1.AcctPrefixCode__c+'</AccountPrefixCode>';
        }
        else
        {
        seReq=seReq+'<AccountPrefixCode>MA-8</AccountPrefixCode>';
        }    
        //seReq = seReq.replace('-','MA-8');
        seReq=seReq+'<GPCustomerAccountingCode>' + se1.GP_Customer_Accounting_Code__c+'</GPCustomerAccountingCode>';
        seReq=seReq+'<Currency>' + se1.CurrencyISOCode+'</Currency>';
        //List<acquisition__c> a; //acquisition__c a;
        List<acquisition__c> a=[select name from acquisition__c where id=:se1.AcquisitionDB__c Limit 1];        
        If (a.size()==0)
        {
        seReq=seReq+'<Acquisition></Acquisition>';     
        }
        else{
            seReq=seReq+'<Acquisition>' + a[0].Name+'</Acquisition>';}
  
        string LineOfBusiness='';
               
        seReq=seReq+'<LinesofBusiness>' + LineOfBusiness+'</LinesofBusiness>';
        seReq=seReq+'<LegalEntity>' + se1.Legal_Entity__c+'</LegalEntity>';
        
        List<User> c3=[select name from User where id=:se1.Accountrep__c Limit 1];

        If (c3.size()==0){
        seReq=seReq+'<AccountRep></AccountRep>';
        }
        Else
        {seReq=seReq+'<AccountRep>' + c3[0].Name+'</AccountRep>';
        }
        //seReq=seReq+'<AccountRep>' + se1.Accountrep__c+'</AccountRep>';
        seReq=seReq+'<AccountStatus>' +se1.TR_Account_Status__c+'</AccountStatus>';

        seReq=seReq+'</ServiceEntity>';    
        seReq = seReq.replace('null',''); 
        return seReq;
    }
        //method to make the call to TR and submit the request
    public static httpresponse insertTR(String Reqxml, String Type)
    {
              String token=getToken();  
            system.debug('token---'+token);
            String header1='Bearer '+token;
            Http http1 = new Http();
            HttpRequest request1 = new HttpRequest();
        If (Type=='E')
        {system.debug('before create Account///');
            request1.setEndpoint(url1);
        system.debug('after create Account///');}
        else If (Type=='D')
                    {system.debug('before create Department////');
            request1.setEndpoint(url12);
        system.debug('after create Department////');}
         else If (Type=='S')        {system.debug('before create Site///');
            request1.setEndpoint(url13);
        system.debug('after create Site///');}
            request1.setMethod('POST');
            //request1.setHeader('Content-Type', 'application/json;charset=UTF-8');
            
            request1.setHeader('Authorization',header1);
            request1.setHeader('Accept', 'application/xml');
            request1.setHeader('Content-Type', 'application/xml');
            
            //string reqXML=createXMLforServiceEntity(se1);
            system.debug('---reqXML--' +ReqXML);
            request1.setBody(ReqXML);
            request1.setTimeout(60000);
            If (test.isRunningTest())
            {
                //write the code for response
                
            }
        Else{//once u generate the fake response uncomment the 238 and comment 240
            //HttpResponse response1 = http1.send(request1);  
            }   
            HttpResponse response1 = http1.send(request1);
        
            System.debug('--response1.getStatusCode() + -- + response1.getStatus()'+response1.getStatusCode() + ' ' + response1.getStatus());
            System.debug('---response1.getBody--' +response1.getBody());
            return response1;
    }
    public static httpresponse updateTR(String Reqxml,String Type)
    {
              String token=getToken();  
            //system.debug('token---'+token);
            String header1='Bearer '+token;
            Http http1 = new Http();
            HttpRequest request1 = new HttpRequest();
        If (Type=='E')
        {   system.debug('before update Account'); 
            request1.setEndpoint(url14);//?_HttpMethod=PATCH');
        system.debug('after update Account');}
        else If (Type=='D')
                    {system.debug('before update Department');
            request1.setEndpoint(url15);
        system.debug('after update Department');}
         else If (Type=='S')        {system.debug('before update Site');
            request1.setEndpoint(url16);
        system.debug('after update Site');}    
        //request1.setHeader('X-HTTP-Method-Override','PATCH');
        request1.setMethod('PUT');
       //request1.setMethod('PATCH');
            //request1.setHeader('Content-Type', 'application/json;charset=UTF-8');
            
            request1.setHeader('Authorization',header1);
            request1.setHeader('Accept', 'application/xml');
            request1.setHeader('Content-Type', 'application/xml');
            
            //string reqXML=createXMLforServiceEntity(se1);
            system.debug('---reqXML--' +ReqXML);
            request1.setBody(ReqXML);
            //request1.setTimeout(10000);
            HttpResponse response1 = http1.send(request1);  
            System.debug('--response1.getStatusCode() + -- + response1.getStatus()'+response1.getStatusCode() + ' ' + response1.getStatus());
            System.debug('---response1.getBody--' +response1.getBody());
            return response1;
    }
    //Lock the submitted record so that no one can edit.
    public static void LockSERecord(List<Id> recordsToProcess1)
    {
                //Lock the record from editing
        Approval.LockResult[] lrList = Approval.lock(recordsToProcess1, false);
        for(Approval.LockResult lr : lrList) { 

           if (lr.isSuccess()) 
        { 
         // Operation was successful, so get the ID of the record that was processed 
         System.debug('Successfully locked SE with ID: ' + lr.getId()); 
           } 
           else { 
         // Operation failed, so get all errors         
         for(Database.Error err : lr.getErrors()) { 
               System.debug('The following error has occurred.');           
               System.debug(err.getStatusCode() + ': ' + err.getMessage()); 
               System.debug('SE fields that affected this error: ' + err.getFields()); 
             } //for end
           } // else end
         } // main for end
        
        //End Locking process
    }
//unLock the submitted record after successful response code.
    public static void UnLockSERecord(List<Service_Entity__c> recordsToProcess1)
    {
                //Lock the record from editing
        Approval.unLockResult[] lrList = Approval.unlock(recordsToProcess1, false);
        for(Approval.unLockResult lr : lrList) { 

           if (lr.isSuccess()) 
        { 
         // Operation was successful, so get the ID of the record that was processed 
         System.debug('Successfully unlocked SE with ID: ' + lr.getId()); 
           } 
           else { 
         // Operation failed, so get all errors         
         for(Database.Error err : lr.getErrors()) { 
               System.debug('The following error has occurred.');           
               System.debug(err.getStatusCode() + ': ' + err.getMessage()); 
               System.debug('SE fields that affected this error: ' + err.getFields()); 
             } //for end
           } // else end
         } // main for end
        
        //End unLocking process
    }
    
    //method to update the SE record that got the response from API call
    @future
    public static void updateSERecord(Id ids,string trCustCode, string trCustId, string syncstatus)
    {
      List<Service_Entity__c> se2=[Select id from Service_Entity__c where id = :ids];  
      for (Service_Entity__c se3 : se2 )
        {  
      se3.TR_Customer_Code__c=trCustCode;
      se3.TR_Customer_Id__c=trCustId;
      se3.Sync_Status__c=syncstatus;
      update se3;      
        }
        
    }

--------------------------------------------
Here is the error i am getting
---------------------------------------------
Future method cannot be called from a future or batch method: synchSEDeptSitesToTR.syncSEToTR(List<String>)
---------------------------------------------

Kindly guide me in fixing this issue.

Thanks
Rao
  • July 20, 2019
  • Like
  • 0
Helo Gurus,
Our customer would like to disable attachments functionality in Chatter.

Kindly let us know if anyone has implemented this and how we can ahieve this.

Thanks
  • July 15, 2019
  • Like
  • 0
Hi ,
I have to create a new web service using REST API to update third party.  Whenever an account gets created/updated in SF it should get created/updated in third party application.  

I am planning to create an after save trigger which will call an apex class.  This apex class will be having all the logic related to API call.

I am new to API's and would like to have sample API code that pulls the data related to the account created and then sends over to the third party.

Thanks in advance for the help.

Thanks,
Rao
  • May 30, 2019
  • Like
  • 0
Hello Gurus,
I had a trigger(generates an email on department name change) and a test class related to this trigger.  The coverage was 100%. I changed the trigger to fire only when the profile is <> System Administrator.  The trigger is working fine as expected but the Test class is failing.  Here is the trigger code and followed by Test class code.
--------------------------------------------------------------
trigger SendEmailAfterDeptCodeUpdate on Department__c (after update) {
Profile p = [ Select Id, Name from Profile where Id =: UserInfo.getProfileId() ];
        if( !p.Name.equalsIgnoreCase( 'System Administrator' ) ) 
        {
  List<Id> lstdeptsToUpdate=new List<Id>(); 
for(Department__c dept : trigger.new)
{
    If (dept.Name !=trigger.oldMap.get(dept.Id).Name)
    {
    lstdeptsToUpdate.add(dept.Id);
    }
}
    
    If(lstdeptsToUpdate.size()>0)
    {
    Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
    
   // string header = '*TR Customer Code, *Customer Name,*TR Department ID,*Original Department Code,*New Department Code,*SubBranchCode,TR Customer Id \n';
 string header = 'SubBranchCode,TRCustomerId,TRDepartmentID,OriginalDepartmentCode,NewDepartmentCode,TRCustomerCode \n';

    string finalstr = header ;
    String Emailbody;
        
    
    string csvname= 'template_to_update_WO_inv_dept.txt';
    csvAttc.setFileName(csvname);
    
    system.debug('header:' + header);
     String messageBody,priorvalue;   
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    //email.setSubject('Department Code change in Salesforce');     
   for (Department__c dep1 : [Select id, Name,Service_Entity__r.Customer_Name__c,TR_Customer_Code__c,trDepartmentID__c,Service_Entity__r.Sub_Branch__c,Service_Entity__r.Sub_Branch__r.Sub_Branch_Code__c,Service_Entity__r.TR_Customer_Id__c from Department__c where id in : lstdeptsToUpdate and Service_Entity__r.Send_To_TR__c=True])
        {
     priorvalue=trigger.oldMap.get(dep1.Id).Name; 
     //string recordString = dep1.TR_Customer_Code__c + ','+ dep1.Service_Entity__r.Customer_Name__c+','+dep1.trDepartmentID__c +','+priorvalue+','+dep1.Name+','+dep1.Service_Entity__r.Sub_Branch__r.Sub_Branch_Code__c +','+dep1.Service_Entity__r.TR_Customer_Id__c +'\n';
     string recordString = dep1.Service_Entity__r.Sub_Branch__r.Sub_Branch_Code__c+','+dep1.Service_Entity__r.TR_Customer_Id__c+','+dep1.trDepartmentID__c +','+priorvalue+','+dep1.Name +','+ dep1.TR_Customer_Code__c  +'\n';

          finalstr = finalstr +recordString;
      
         messageBody = '<html><body>';
         messageBody = messageBody + 'Here are the details for the change in Department Code in Salesforce ';
         messageBody = messageBody + '<br>';
         messageBody = messageBody + '<br>';            
         messageBody = messageBody + 'TR Customer Code: '+ dep1.TR_Customer_Code__c;
         messageBody = messageBody + '<br>';
         messageBody = messageBody + 'TR Department ID: ' + dep1.trDepartmentID__c;
         messageBody = messageBody + '<br>';
               
         messageBody = messageBody + 'Original Department Code: ' + priorvalue;
         messageBody = messageBody + '<br>';
         messageBody = messageBody + 'New Department Code: ' + dep1.Name;
         messageBody = messageBody + '<br>';
         messageBody = messageBody + '<br>';            
         messageBody = messageBody + 'Additional details are available in the attached excel. Please update the Work Order and Invoicing details with the new department code.';
         messageBody = messageBody + '<br>';
         messageBody = messageBody + '<br>';            
         messageBody = messageBody + 'Assign ticket to - Data Management Backend group';
    
         messageBody = messageBody + '</body></html>';       
    
    blob csvBlob = Blob.valueOf(finalstr);    
    csvAttc.setBody(csvBlob);

    system.debug('----');    
    email.setSubject('Department Code change in Salesforce updated to ' + dep1.Name ); 
    email.setHtmlBody(messageBody);

    email.setToAddresses(new String[]{'raos@gmail.com'});
    email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
    system.debug('email...' + email );
    if(email != null)
      {
       Messaging.sendEmail(new Messaging.singleEmailMessage[] {email}); 
       //   system.debug('Inside send email');
      } 
    }        
}
        }
}
--------------------------------------------------------------
@IsTest
public class SendEmailAfterDeptCodeUpdateTest {
static testMethod void SendEmailAfterDeptCodeUpdateTest()
    {
        Profile p = [ Select Id, Name from Profile where name='System Administrator' limit 1 ];
        //Profile p = [ Select Id, Name from Profile where name='Standard Sales User' limit 1 ];
        User standardSales = new User(profileId = p.id, username ='standarduserAdmin@peak.com', email = 'standarduser123@peak.com', 
                                     emailencodingkey = 'UTF-8', localesidkey ='en_US', languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                    alias='nuser123', lastname='lastname123');
        insert standardSales;
        system.runAs(standardSales)
        {   /*Account a=new Account(Name='Test1',BillingCountry='United States',BillingState='Indiana');
            insert a;
         
            Acquisition__c ac= new Acquisition__c(Name='Test Ac');
            insert ac;
         
            Service_Entity__c Se1=new Service_Entity__c(Customer_Name__c='Testa',Legal_Entity__c='Archive Systems Inc.',Account__c=a.id,AcquisitionDB__c=ac.id);
            insert Se1;*/
            
            Department__c dept1= new Department__c(Name='Test Dept',Department_Name__c='Sample Dept',  CurrencyIsoCode='USD',Service_Entity__c='a0t1W00000Un1kR'); //Se1.Id);
            test.startTest();
            insert dept1;
            test.stopTest();
        }


    }
    static testMethod void updateDepartmentTest1(){
                
        Profile p2 = [ Select Id, Name from Profile where name='Onboarding Team' limit 1 ];
        User standardSales2 = new User(profileId = p2.id, username ='standarduserAdmin123@peak.com', email = 'standarduseranc@peak.com', 
                                     emailencodingkey = 'UTF-8', localesidkey ='en_US', languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                    alias='nuser123', lastname='lastname1231');
        insert standardSales2;

       system.runAs(standardSales2)
        {   Department__c dept11= new Department__c(Name='Test Dept123',Department_Name__c='Sample Dept123',  CurrencyIsoCode='USD',Service_Entity__c='a0t1W00000Un1qH'); //Se1.Id);
            insert dept11  ;   
            test.startTest();
            dept11.Name='Test Dept1243';
            Update dept11;
            test.stopTest();
        }   
    }
    static testMethod void updateDepartmentTest(){
        Profile p = [ Select Id, Name from Profile where name='System Administrator' limit 1 ];
        User standardSales = new User(profileId = p.id, username ='standarduserAdmin@peak.com', email = 'standarduser123@peak.com', 
                                     emailencodingkey = 'UTF-8', localesidkey ='en_US', languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                    alias='nuser123', lastname='lastname123');
        insert standardSales;
        system.runAs(standardSales){
            Department__c dept2= new Department__c(Name='Test Dept2',Department_Name__c='Sample Dept2',  CurrencyIsoCode='USD',Service_Entity__c='a0t1W00000Un4UM'); //Se1.Id);
            insert dept2;
            
            test.startTest();
            dept2.Name='Test Dept3';
            Update dept2;
            test.stopTest();
        }
    }
}
--------------------------------------------------------------

I am getting the following error message

System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

Stack trace is showing this message:
Class.SendEmailAfterDeptCodeUpdateTest.updateDepartmentTest1: line 39, column 1

I have highlighted the line 39.  The new method that i have include is updateDepartmentTest1().

Let me know the mistake I am doing.

Thanks
Rao
  • May 21, 2019
  • Like
  • 0
Hi Gurus,
I am working on a requirement for generating all the distributors from commerce cloud.  The user will select a radius and my API should get back distributors within that distance.

Any code or steps that I need to follow in developing this request is highly appreciated.

Thanks.
Rao
  • May 02, 2019
  • Like
  • 0
Hello Gurus ,
I have a custom field(PrimKey) which is type character on Contact. 

1.)I would like to update this field to a unique key combination value for all the existing Contacts using some script.

The value for the first contact processed should be something like 2019ABC00001
The next contact should be updated to 2019ABC00002
The script should generate this unique key in this way for all the contacts.

2.) Generate the same key combination but with different characters (to differentiate from existing contact) for the new contacts using Apex code
This should be a combination of current year followed by ABD followed by 00001
Ex: 2019ABD00001
When the next contact is created it should generate 2019ABD00002.

Let me know how I can achieve these.

Thanks.
Rao
  • May 02, 2019
  • Like
  • 0
Hi,
I need to calculate number of days an opportunity is in a particular stage. Once the stage is changed this field should reset to zero.

I have created a custom number field and the following trigger to do the same.

trigger updateNoofDaysInOppStage on Opportunity (before insert) {
 integer i=0; integer j;
    for(Opportunity p : Trigger.new)
    {
        if(Trigger.old[i].StageName != Trigger.new[i].StageName){

        Trigger.new[i].No_of_Days_in_this_Stage__c = 0;
    }
     else
     {
      j=Integer.ValueOf(Trigger.old[i].No_of_Days_in_this_Stage__c);
      j++;
      Trigger.old[i].No_of_Days_in_this_Stage__c = j;

      }
i=i+1;
    }

}

I am getting an error "Illegal assignment from Decimal to Integer" at the line which is in bold.  

Instead I tried to do 
Trigger.old[i].No_of_Days_in_this_Stage__c = Trigger.old[i].No_of_Days_in_this_Stage__c + 1;

Then it is throwing error saying "Expression cannot be assigned".

Let me know where I am going wrong.

Thanks
Rao
  • April 09, 2019
  • Like
  • 0
Hi ,
I have a requirement to calculate number of days an opportunity is in particular stage.  IF the stage changes then the variable should reset to zero.  If it is in the same stage then it should increment. 

For this I have written the following trigger but it is giving me "Expression cannot be assigned" error.

trigger updateNoofDaysInOppStage on Opportunity (before insert) {
 integer i=0;
integer j;
    for(Opportunity p : Trigger.new)
    {
        if(Trigger.old[i].StageName != Trigger.new[i].StageName){

        Trigger.new[i].No_of_Days_in_this_Stage__c = 0;
    }
     else
     {
      j=Integer.ValueOf(Trigger.old[i].No_of_Days_in_this_Stage__c);
      j++;
      Trigger.old[i].No_of_Days_in_this_Stage__c = j;

      }
i=i+1;
    }

}

I tried different ways to overcome this but could not.

Let me know.

Thanks.

Rao
  • April 08, 2019
  • Like
  • 0
Hi Gurus,
I am facing an issue while creating a case.

I am creating a case based on service object with no value for Account. When I am creating the new case I would like to update the Account on Case object with the Account from the Service object. 

Here is my code.

trigger UpdateAccountOnCaseForSE on Case (before insert) {
  List<Id> lstcasesToUpdate=new List<Id>(); 
for(Case c : trigger.new)
{
    If ((c.Account == NULL) && ((c.RecordTypeId =='01240000000codw') || (c.RecordTypeId =='01240000000cohe')) )    
    {
    lstcasesToUpdate.add(c.Id);
    }
}

    If(lstcasesToUpdate.size()>0)
    {
     for (Case c1 : [Select id, Service_Entity__r.Account__c from Case where id in : lstcasesToUpdate])
        {
            C1.AccountId=c1.Service_Entity__r.Account__c;
        }
    }
}

I have no errors but the Case is not getting created saying Account is required.

Thank you for any guidance in this regard.

Rao
  • March 20, 2019
  • Like
  • 0
Hi ,
I have written a trigger on Account to get the highest parent.  The trigger should also get few fieldvalues from highest parent and update the child record.

Ex1:  P1-->P2-->P3
P2 & P3 should get details of P1.  This is working fine.

Ex2: When I create another parent P11 and restructure it as below
P11-->P2-->P3
P2 & P3 should get updated with details of P11.  Only P2 is getting updated but not P3. P3 is still having the old parent(P1) details.

Ex3:P11-->P2-->p3 
When I delete a parent P11, P3 should get updated to P2 details.  This is not happening. P3 is still having the old parent(P1) details.

Here is my trigger code

trigger UpdateHighestParent on Account (before insert, before update) {
    
    Map<Id, Id> accountParentIdMap=new Map<Id, Id>();
     Map<Id, Id> parentIdMasterIdMap=new Map<Id, Id>();
       List<Account> nonParentAccounts=[select id, parentId from Account where parentId!=null];
    for(Account acc: nonParentAccounts){
        accountParentIdMap.put(acc.Id, acc.ParentId);
    }
    List<Id> masterAccountIds=new List<Id>();
    //iterate over all accounts in trigger
    for(Account curAccount: Trigger.New){
        if(curAccount.ParentId!=null){
            Id parentId=curAccount.ParentId;
            while(accountParentIdMap.get(parentId)!=null){ //find master account
                parentId=accountParentIdMap.get(parentId);
            }
            parentIdMasterIdMap.put(curAccount.ParentId, parentId);
            masterAccountIds.add(parentId);
        }
    }  
    
     //get global Master Accounts information
     Map<Id, Account> globalMasterAccountsMap=new Map<Id, Account>([select id, Name, Account_ID__c, DunsNumber, parentId from Account where parentId=null and id in:masterAccountIds ]);
  
     //iterate over all accounts in trigger
    for(Account curAccount: Trigger.New){
        if(curAccount.ParentId!=null){
            Id masterId=parentIdMasterIdMap.get(curAccount.ParentId);
            if(globalMasterAccountsMap.get(masterId)!=null){
                Account masterAccount= globalMasterAccountsMap.get(masterId);
                curAccount.Global_Master_Name__c=masterAccount.Name;
                curAccount.Global_Master_ID__c=masterAccount.Account_ID__c;
                curAccount.Global_Master_D_B__c=masterAccount.DunsNumber;
            }
        }
            Else
            {   //system.debug('Else..' + curAccount.Name +'-curAccount.Account_ID__c-' + curAccount.Account_ID__c + '-curAccount.DunsNumber-' + curAccount.DunsNumber);
                curAccount.Global_Master_Name__c=curAccount.Name;
                curAccount.Global_Master_ID__c=curAccount.Account_ID__c;
                curAccount.Global_Master_D_B__c=curAccount.DunsNumber;
            }
                
        //}
    }
    
}

Let me know what I have to change in my code.

Thanks
Rao
  • January 31, 2019
  • Like
  • 0
Hi ,
I got a requirement to create a case in Salesforce whenever an incident is created in ServiceNow with Assignment group as "Salesforce".

Let me know if you have any ideas or if anyone has implemented this.

Thanks in advance.

Rao.
  • January 30, 2019
  • Like
  • 0
Hi ,
I am trying to create a trigger to update two custom fields on Lead object with two values from a Custom object. The trigger is getting executed but it is not working as expected i.e. Branch Name and Distance to Branch are not getting populated. 

Here is the Trigger code
trigger UpdateBranchAndDistanceToBranch on Lead (before insert) {
Set<Id> lstLeadsToUpdate = new Set<Id>();    
    for( Lead l : trigger.new )
    {  system.debug('l.PostalCode....' + l.PostalCode);
        //Get the list of all leads that need an update
        If(l.PostalCode != null && l.Branch_Name__C == null )
        {    
            lstLeadsToUpdate.add(l.Id);
        }
    }
    if(lstLeadsToUpdate.isEmpty() == false)
    {
     List<Lead> finallstLeadsToUpdate=new List<Lead>();
     List<Lead> listLeads = [SELECT id,Branch_Name__c,Distance_To_Branch__c, PostalCode  from Lead WHERE Id in :lstLeadsToUpdate];
       system.debug('listLeads ...' + listLeads);
     For (Lead oLead : listLeads) 
        {   
         Serviced_Postal_Code__c sp=[select Sub_Branch__c,Distance_From_Branch_mi__c from Serviced_Postal_Code__c where Postal_Code__c= : oLead.PostalCode];
         Lead c=new Lead(Id=oLead.Id);
       
         system.debug('sp.Sub_Branch__c..' + sp.Sub_Branch__c);
         system.debug('sp.Distance_From_Branch_mi__c..' + sp.Distance_From_Branch_mi__c);
       
         c.Branch_Name__c =  sp.Sub_Branch__c;
         c.Distance_To_Branch__c  =  sp.Distance_From_Branch_mi__c; 
         finallstLeadsToUpdate.add(c);   
         }  
      
        if (finallstLeadsToUpdate.size()>0)
           {
                update finallstLeadsToUpdate;
            }  
    }               

}
First debug statement(system.debug('l.PostalCode....' + l.PostalCode);) is displaying the postal code that i am keying in for the lead.
The debug log is showing zero rows for "SELECT id,Branch_Name__c,Distance_To_Branch__c, PostalCode  from Lead WHERE Id in :lstLeadsToUpdate"

I am unable to figure out what am I missing in the code that is causing the issue.

Kindly let me know where am I going wrong.

Thanks
Rao

 
  • January 11, 2019
  • Like
  • 0
Hi ,
I have created a trigger on Task that updates last activity date whenever a task is created on a Lead / contact / Opp. 

The trigger works fine when I create a single task or recurrence when the recurrence date is only for one day(Recurrence Start & Recurrence End are on same day). But when the recurrence is created for two or more days (Recurrence Start & Recurrence End are on different days Ex: Start = 01/01/2019 & End=01/02/2019) then it is throwing an error.  

Here is the error message

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger UpdateLastActivityDate caused an unexpected exception, contact your administrator: UpdateLastActivityDate: execution of AfterInsert caused by: System.ListException: Duplicate id in list: 003c000001G7hkTAAR: Trigger.UpdateLastActivityDate: line 37, column 1

Here is the Trigger Code along with lines mentioned error in bold
trigger UpdateLastActivityDate on Task (after insert) {

    //updating Last_sales_activity__c on lead, contact and opportunity for new activities
    
     if( trigger.isAfter && trigger.isInsert  )
    {
        List<Contact> lstContactsToUpdate=new List<contact>();
        List<Lead> lstLeadsToUpdate=new List<Lead>();
        List<Opportunity> lstOpportunitiesToUpdate=new List<Opportunity>();
        
        Profile p = [ Select Id, Name from Profile where Id =: UserInfo.getProfileId() ];
        if( p.Name.equalsIgnoreCase( 'Standard Sales User' ) )
        {    
            for( Task t : trigger.new )
        {    system.debug('t whatId..'+t.WhatId);
             system.debug('t whoId..'+t.WhoId);
              if( t.WhoId != null && String.valueOf( t.WhoId ).startsWith( '003' ))//003 =contact
                {
                    contact c=new contact(Id=t.WhoId);
                    c.Last_sales_activity__c=system.today();
                    lstContactsToUpdate.add(c);
                }else if( t.WhatId != null && String.valueOf( t.WhatId ).startsWith( '006' ))//006 =opportunity
                {system.debug('t----006---');
                    Opportunity c=new Opportunity(Id=t.WhatId);
                    c.Last_sales_activity__c=system.today();
                    lstOpportunitiesToUpdate.add(c);
                }else if( t.WhoId != null && String.valueOf( t.WhoId ).startsWith( '00Q' ))//00Q =Lead
                {
                    Lead c=new Lead(Id=t.WhoId);
                    c.Last_sales_activity__c=system.today();
                    lstLeadsToUpdate.add(c); 
                }
            
            
        }
            if(lstContactsToUpdate.size()>0){
                update lstContactsToUpdate;
            }
            if(lstOpportunitiesToUpdate.size()>0){
                update lstOpportunitiesToUpdate;
            }
            if(lstLeadsToUpdate.size()>0){
                update lstLeadsToUpdate;
            }
            
        }
        
   }

 }

I could not figure what I am missing here.

Let me know what changes I need to do to overcome this error.

Thanks
Rao
  • January 10, 2019
  • Like
  • 0
//Here is my Apex class
trigger updateContactStatusToRecycle on Opportunity (After update) {
    //If a Contact is attached to an opportunity that then gets closed, Change status to Recycled only if there are no other open opportunities related to that same contact. 
    List<Id> lstOpportunityIdsToUpdate=new List<Id>();  
    
    //Select the list of opportunities
    for(Opportunity optyObj : Trigger.new)
    {
        if ((optyObj.Stagename=='Closed Won' || optyObj.Stagename=='Closed Lost') && 
            (optyObj.Stagename !=trigger.oldMap.get(optyObj.Id).Stagename)){
                lstOpportunityIdsToUpdate.add(optyObj.Id);
            }
    }
    //select the list of contact Ids that needs update
    List<Id> contactIds=new List<Id>();
    for (OpportunityContactRole ocrObj : [select Id, ContactId,Contact.Status__c, opportunityId from OpportunityContactRole where OpportunityId in :lstOpportunityIdsToUpdate ])
    {    if(ocrObj.Contact.Status__c!='Recycle'){
        contactIds.add(ocrObj.ContactId);

    }   
    }
    //seect the list of opportunities that are in '' stage
    Map<string, List<OpportunityContactRole>> oppToContactRoleMap=new Map<string, List<OpportunityContactRole>>();
    for (OpportunityContactRole ocrObj : [SELECT Id,OpportunityId,Opportunity.Id,Opportunity.StageName,  ContactId FROM OpportunityContactRole where ContactId in :contactIds and Opportunity.StageName = 'Prospecting'])
    {
        if(oppToContactRoleMap.get(ocrObj.ContactId)!=null){
            List<OpportunityContactRole> existingRecords=  oppToContactRoleMap.get(ocrObj.ContactId);
            existingRecords.add(ocrObj);
            oppToContactRoleMap.put(ocrObj.ContactId, existingRecords);
        }else{
            oppToContactRoleMap.put(ocrObj.ContactId, new List<OpportunityContactRole>{ocrObj});
        }

    }
    //Identify the Contacts whose status needs to be updated
    List<contact> lstContactsToUpdate=new List<contact>();
    for(string contactId: contactIds){
        if(oppToContactRoleMap.get(contactId)==null || oppToContactRoleMap.get(contactId).size()==0){
            lstContactsToUpdate.add(new contact(Id=contactId, Status__c = 'Recycle',Recycle_Reason__c='Cleanup'));
        }

    }
    //update the Contact status
    if(lstContactsToUpdate.size()>0){
        update lstContactsToUpdate;
    }

}

//---------------------------------------------------------------------------------
//The lines that are marked in bold are not covered by the test class
//My test class code is :
@IsTest
public class updateContactStatusToRecycleTest {
   static testMethod void updateContactStatusToRecycleTest()
    {   
        Profile p = [ Select Id, Name from Profile where name='Sales Ops Admin' limit 1 ];
        User standardSales = new User(profileId = p.id, username ='standarduserAdmin@peak.com', email = 'standarduser123@peak.com', 
                                     emailencodingkey = 'UTF-8', localesidkey ='en_US', languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                    alias='nuser123', lastname='lastname123');
        insert standardSales;
        system.runAs(standardSales)
        {
            Account a=new Account(Name='Test',BillingCountry='United States',BillingState='Indiana');
            insert a;
            
            Contact c=new Contact(LastName='Test',FirstName='Test', Status__c='Prospect',AccountId=a.Id, MailingCountry='United States',MailingState='Indiana');
            insert c;
            
            Opportunity op=new Opportunity(Name = 'testOpp', AccountId=a.Id,Primary_Servicing_Branch1__c='a0840000005X9TH', StageName = 'Prospecting',CloseDate = System.today(), CurrencyIsoCode = 'USD');
            insert op;
            
            op.StageName = 'Closed Won';
            Update op;
            //lstOpportunityIdsToUpdate.add(op.Id);            
            OpportunityContactRole oc=new OpportunityContactRole();
            oc.OpportunityId=op.Id;
            oc.ContactId=c.Id;
            oc.IsPrimary = TRUE;
            oc.Role = 'Decision Maker';

            insert oc;
            
            c.Status__c='Recycle';
            c.Recycle_Reason__c='Cleanup';
            Update c;
            
            Account a1=new Account(Name='Test1',BillingCountry='United States',BillingState='Indiana');
            insert a1;
            
            Contact c1=new Contact(LastName='Test1',FirstName='Test',Status__c='Prospect', AccountId=a1.Id, MailingCountry='United States',MailingState='Indiana');
            insert c1;
            
            //c1.Status__c='Recycle';
            //c1.Recycle_Reason__c='Cleanup';
            //Update c1;
            
            Opportunity op1=new Opportunity(Name = 'testOpp1', AccountId=a1.Id,Primary_Servicing_Branch1__c='a0840000005X9TH', StageName = 'Prospecting',CloseDate = System.today(), CurrencyIsoCode = 'USD');
            insert op1;
            
            op1.StageName = 'Closed Lost';
            op1.Competitor_lost_to__c='Test';
            op1.Reason_Lost__c='Pricing';
            op1.NextStep='test';
            op1.Forecast_Category2__c='Closed Lost';
            op1.Reason_Detail__c='test';
            Update op1;
            
            OpportunityContactRole oc1=new OpportunityContactRole();
            
            oc1.OpportunityId=op1.Id;
            oc1.ContactId=c1.Id;
            oc1.IsPrimary = FALSE;
            oc1.Role = 'Decision Maker';
            insert oc1;
            //lstOpportunityIdsToUpdate.add(op1.Id);            
  
            //update lstOpportunityIdsToUpdate;
        }
        
    }
}

Let me know what else am I missing which is causing the coverage to be only 54%.

Thanks
Rao
  • November 13, 2018
  • Like
  • 0
If a Contact is attached to an opportunity that then gets closed, Change status to Recycled only if there are no other open opportunities related to that same contact.  I have written the following trigger on Opportunity but it is giving error.  Kindly let me know what I am missing here.

trigger updateContactStatusToRecycle on Opportunity (After update) {

    Id optyId,contactId;
    string vstatusField,optyStatus;

    List<Opportunity> lstOpportunitiesToUpdate=new List<Opportunity>();        
    List<Contact> contactObj= new List<Contact>();
    for(Opportunity optyObj : Trigger.new)
    {
        optyId         = optyObj.Id; 
        optyStatus    = optyObj.Stagename;
        
        // get Contact Id for the opportunity
        for (OpportunityContactRole ocrObj : [select Id, ContactId,Contact.Status__c from OpportunityContactRole where OpportunityId = :optyId ])
        {
           // optyStatus    = ocrObj.Opportunity.Stagename ;
            contactId = ocrObj.ContactId;
        } 
        //Get the contact status and the other opportunities tied to this contact
        Contact conObj =  [select Id, Status__c from contact where Id = :contactId];

            vstatusField = conObj.Status__c;
            
            //Get all the opportunities related to this contact.
           contactObj = [SELECT Id,(SELECT Id,OpportunityId,Opportunity.StageName,  ContactId FROM OpportunityContactRoles) FROM Contact];

            for(Contact contactObj1 : contactObj)
            {   
                If(contactObj1.Opportunity.StageName == 'Open')
                {
                    lstOpportunitiesToUpdate.add(contactObj1.OpportunityId);
                }
            }  
            //If there are no open opportunities then update contact status
            If (lstOpportunitiesToUpdate.size()==0)
            {
                if (optyStatus=='Closed Won' || optyStatus=='Closed Lost')
                {
                    if (conObj.Status__c <>'Recycle')
                    {
                        conObj.Status__c = 'Recycle';
                         update(conObj);
                    }
                    }
            }    
    }

    
}
  • October 30, 2018
  • Like
  • 0
Hi ,
I have a input text field to type in a input value and a custom button "Add" to add these records to a custom object.  After adding the record the record should be displayed immediately on the same page.
If I add 5 records all the 5 records should be displayed after the Add button.  If I add a 6th record now this record should be visible after the 5th record.

How to accomplish this?

Thanks
Rao
 
  • April 15, 2018
  • Like
  • 0
Currently after selecting the opportunity type and save it, the application is displaying me all the list of products available which is time consuming for the sales people to select from all the products instead of selecting only from the related products.

Ex: If I select opportunity type A then it is displaying all products from 1-10.  Even when I select opportunity type B then also i am displayed with all the products from 1-10 instead of displaying only those related to B.

I would like to display products 1-5 when i select opportunity type A and display products 6-10 when I select opportunity type B.
Let me know how to address this issue.

Thanks.
  • January 11, 2018
  • Like
  • 0
Hello Friends,
Currently the "Log a Call" button exists on the Open Activities related list.  The user is wanting to have this on the "Highlights Panel" of the Contact object as shown below.

User-added image

Kindly let me know if we can do this and how to do this.

Any help is greatly appreciated.

Thanks
Rao
  • January 23, 2020
  • Like
  • 0
Hi Gurus,
I have a trigger which inturn calls a apex method to make a API call to the third party.  After the third party returns the response, I should he updating the values on the record which called the API.

I am able to capture the response but while updating the record I am getting the error.  I am sure, the way I am calling the update method is causing the issue.  

Here is the trigger code:
-------------------------------------------

trigger updateSEToTR on Service_Entity__c (after insert, after update) { 
    //instead of calling the method directly, first iterate over all records and collects Ids of all records to be processed.
    //synchSEDeptSitesToTR.syncSEToTR();
       List<Id> lstSEToUpdate=new List<Id>(); 
        system.debug('---Inside---');
        if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isUpdate && Trigger.isAfter))
        //if((Trigger.isInsert && Trigger.isAfter))
        {
            for(Service_Entity__c se : (List<Service_Entity__c>)trigger.new)
            {   
                If (se.Sync_Status__c<>'Error' && se.Send_To_TR__c==True)
                {
                    lstSEToUpdate.add(se.Id);
                }
            }
        system.debug('---lstSEToUpdate.size()---'+lstSEToUpdate.size());    
        //if there are records to update, call future method for callout, future method can only take list of Ids and can't take objects. Also Trigger.New and Trigger.IsInsert etc will not work in future method.
         If (lstSEToUpdate.size()> 0){
            synchSEDeptSitesToTR.syncSEToTR(lstSEToUpdate);
            synchSEDeptSitesToTR.LockSERecord(lstSEToUpdate);
         }

    }system.debug('-At the End--lstSEToUpdate.size()---'+lstSEToUpdate.size());        
}
-------------------------------------------
Here is the Apex code:
--------------------------------------------
public class synchSEDeptSitesToTR {
   @Future(callout=true) //needed to change the annotation
    public static void syncSEToTR(List<String> serviceEntityIds) {
        String trCustomerCode,trCustomerId,syncStatus,syncErrorMessage;
        List<Id> lstServiceEntitiesToUpdate=new List<Id>();
        system.debug('--serviceEntityIds--'+serviceEntityIds);
        List<Service_Entity__c> recordsToProcess=[Select Name, Id,Sync_Status__c,Send_To_TR__c, TR_Customer_Code__c,TR_Customer_Id__c,GP_Customer_Accounting_Code__c,CurrencyISOCode,
                                                  AcquisitionDB__c,Customer_Name__c,Legal_Entity__c,Sub_Branch__c,Accountrep__c,
                                                  NextRateIncrease__c,LeadSource__c,Account_Industry__c,DiscontinueService__c,
                                                  Taxable__c,TaxCode__c,Delivery_Contact__c,Delivery_Address__c,Delivery_Address_2__c,
                                                  Delivery_Contact_Phone__c,Delivery_Contact_Email__c,Delivery_State__c,Delivery_City__c,
                                                  Delivery_Postal__c,Billing_Contact__c,Billing_Address__c,Billing_Address_2__c,Billing_Contact_Phone__c,
                                                  Billing_Contact_Email__c,Billing_State__c,Billing_City__c,Billing_Postal__c,PO_Number__c,
                                                  Billing_Group__c,Breach_Reporting_Services__c,Admin_Fee_V4__c,Online_Tools__c,Billing_Dept__c,
                                                  Information__c,Customer_Notes__c,Operations_Note__c,Display_as_a_pop_up_note__c,Conversion_Services__c,
                                                  HC_Storage__c,Shredding__c,Software__c,Media_Vault__c,AcctPrefixCode__c,TR_Account_Status__c,TR_NextRateIncrease__c,
                                                  Sub_Branch__r.Sub_Branch_Code__c
                                                  from Service_Entity__c where id in : serviceEntityIds and Send_To_TR__c=True and Sync_Status__c!='Error'];
        system.debug('--Before Try--');
        try{
        //get the records, added couple of more fields which are being used down
        system.debug('--Before For--');
        for (Service_Entity__c se1 : recordsToProcess)
        {
        system.debug('--Inside For--');
            string reqXML=createXMLforServiceEntity(se1);
            system.debug('--ServiceEntity--reqXML--' +reqXML);    
            
            HttpResponse response;
            //LockSERecord(recordsToProcess);
            if ((se1.TR_Customer_Id__c==null || se1.TR_Customer_Id__c=='0') && se1.Send_To_TR__c==True)
            { 
                system.debug('------before insertTR is called');
            response=insertTR(reqXML,'E'); 
                system.debug('------after insertTR is called');
            }
            else if ((se1.TR_Customer_Id__c<>null || se1.TR_Customer_Id__c<>'0') && se1.Send_To_TR__c==True)
            {
            system.debug('------before updateTR is called');    
            system.debug('--Userinfo.getName()---'+Userinfo.getName());    
            response=updateTR(reqXML,'E'); 
            system.debug('after updateTR is called');
            }    
            
            // Parse the JSON response
            // 400 bad request
            // 200 success
            String respText=response.getBody();
            if (response.getStatusCode() != 200) {
                syncStatus='Error';
                syncErrorMessage=respText.substringBetween('<ErrorMessage>','</ErrorMessage>');
                System.debug('The status code returned was not expected: ' +
                             response.getStatusCode() + ' ' + response.getStatus());
                system.debug('syncStatus:'+syncStatus); 
            } else {
                System.debug(response.getBody());
                if (response.getStatusCode() == 200){
                    system.debug('---' + response.getStatusCode() + ' ' + response.getStatus());
                    trCustomerCode=respText.substringBetween('<TRCustomerCode>', '</TRCustomerCode>');
                    trCustomerId=respText.substringBetween('<TRCustomerId>', '</TRCustomerId>');
                    syncErrorMessage='';
                    syncStatus='Synced';
                    system.debug('trCustomerCode:'+trCustomerCode);
                    system.debug(' trCustomerId:'+ trCustomerId);
                    system.debug('syncStatus:'+syncStatus); 
                    se1.TR_Customer_Code__c=trCustomerCode;
                    se1.TR_Customer_Id__c=trCustomerId;
                    se1.Sync_Status__c=syncStatus;
                    
                  //lstServiceEntitiesToUpdate.add(se1.Id);  
                }
                //Method to update this record with the values from the response
                updateSERecord(se1.Id,trCustomerCode,trCustomerId,syncStatus);
                
            }
            
        }

        }
        catch(Exception e){ 
            System.debug('Exception:'+e.getMessage());
        } 
          
         UnLockSERecord(recordsToProcess);
    }
    //method to get token
    public static string getToken()
    {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(tokenUrl);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        String jsonBody ='username=' + 'user1' + '&password=' + '12345';
        request.setBody(jsonBody);
        request.setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
        HttpResponse response = http.send(request);  

        String respText=response.getBody();
        String respToken=respText.substringAfter('access_token');
        
        //System.debug('---respToken---' + respToken);
        String respToken1=respText.substringBetween('access_token', 'token_type');
        String respToken2=respToken1.replace('":"','');
        String respToken3=respToken2.replace('","','');
   
        System.debug('--respToken3--' +respToken3);  
        
        return respToken3;    
    }
    //new method to create XML for Service entity
    public static string createXMLforServiceEntity(Service_Entity__c se1){
        String ZeroOne='';
        string seReq='';
        seReq=seReq+'<ServiceEntity>';
        seReq=seReq+'<ServiceEntityID>' + se1.Id+'</ServiceEntityID>';
        seReq=seReq+'<ServiceEntityCode>' + se1.Name+'</ServiceEntityCode>';
        seReq=seReq+'<TRCustomerCode>' + se1.TR_Customer_Code__c+'</TRCustomerCode>';
        //seReq = seReq.replace('null','');
        seReq=seReq+'<TRCustomerId>' + se1.TR_Customer_Id__c+'</TRCustomerId>';
        seReq=seReq+'<CustomerName>' + se1.Customer_Name__c+'</CustomerName>';
        //seReq=seReq+'<SubBranch>' + se1.Sub_Branch__c+'</SubBranch>';
        //seReq = seReq.replace('null','');
        seReq=seReq+'<SubBranchCode>'+se1.Sub_Branch__r.Sub_Branch_Code__c+'</SubBranchCode>';
        If (se1.AcctPrefixCode__c<>'-')
        {
        seReq=seReq+'<AccountPrefixCode>' + se1.AcctPrefixCode__c+'</AccountPrefixCode>';
        }
        else
        {
        seReq=seReq+'<AccountPrefixCode>MA-8</AccountPrefixCode>';
        }    
        //seReq = seReq.replace('-','MA-8');
        seReq=seReq+'<GPCustomerAccountingCode>' + se1.GP_Customer_Accounting_Code__c+'</GPCustomerAccountingCode>';
        seReq=seReq+'<Currency>' + se1.CurrencyISOCode+'</Currency>';
        //List<acquisition__c> a; //acquisition__c a;
        List<acquisition__c> a=[select name from acquisition__c where id=:se1.AcquisitionDB__c Limit 1];        
        If (a.size()==0)
        {
        seReq=seReq+'<Acquisition></Acquisition>';     
        }
        else{
            seReq=seReq+'<Acquisition>' + a[0].Name+'</Acquisition>';}
  
        string LineOfBusiness='';
               
        seReq=seReq+'<LinesofBusiness>' + LineOfBusiness+'</LinesofBusiness>';
        seReq=seReq+'<LegalEntity>' + se1.Legal_Entity__c+'</LegalEntity>';
        
        List<User> c3=[select name from User where id=:se1.Accountrep__c Limit 1];

        If (c3.size()==0){
        seReq=seReq+'<AccountRep></AccountRep>';
        }
        Else
        {seReq=seReq+'<AccountRep>' + c3[0].Name+'</AccountRep>';
        }
        //seReq=seReq+'<AccountRep>' + se1.Accountrep__c+'</AccountRep>';
        seReq=seReq+'<AccountStatus>' +se1.TR_Account_Status__c+'</AccountStatus>';

        seReq=seReq+'</ServiceEntity>';    
        seReq = seReq.replace('null',''); 
        return seReq;
    }
        //method to make the call to TR and submit the request
    public static httpresponse insertTR(String Reqxml, String Type)
    {
              String token=getToken();  
            system.debug('token---'+token);
            String header1='Bearer '+token;
            Http http1 = new Http();
            HttpRequest request1 = new HttpRequest();
        If (Type=='E')
        {system.debug('before create Account///');
            request1.setEndpoint(url1);
        system.debug('after create Account///');}
        else If (Type=='D')
                    {system.debug('before create Department////');
            request1.setEndpoint(url12);
        system.debug('after create Department////');}
         else If (Type=='S')        {system.debug('before create Site///');
            request1.setEndpoint(url13);
        system.debug('after create Site///');}
            request1.setMethod('POST');
            //request1.setHeader('Content-Type', 'application/json;charset=UTF-8');
            
            request1.setHeader('Authorization',header1);
            request1.setHeader('Accept', 'application/xml');
            request1.setHeader('Content-Type', 'application/xml');
            
            //string reqXML=createXMLforServiceEntity(se1);
            system.debug('---reqXML--' +ReqXML);
            request1.setBody(ReqXML);
            request1.setTimeout(60000);
            If (test.isRunningTest())
            {
                //write the code for response
                
            }
        Else{//once u generate the fake response uncomment the 238 and comment 240
            //HttpResponse response1 = http1.send(request1);  
            }   
            HttpResponse response1 = http1.send(request1);
        
            System.debug('--response1.getStatusCode() + -- + response1.getStatus()'+response1.getStatusCode() + ' ' + response1.getStatus());
            System.debug('---response1.getBody--' +response1.getBody());
            return response1;
    }
    public static httpresponse updateTR(String Reqxml,String Type)
    {
              String token=getToken();  
            //system.debug('token---'+token);
            String header1='Bearer '+token;
            Http http1 = new Http();
            HttpRequest request1 = new HttpRequest();
        If (Type=='E')
        {   system.debug('before update Account'); 
            request1.setEndpoint(url14);//?_HttpMethod=PATCH');
        system.debug('after update Account');}
        else If (Type=='D')
                    {system.debug('before update Department');
            request1.setEndpoint(url15);
        system.debug('after update Department');}
         else If (Type=='S')        {system.debug('before update Site');
            request1.setEndpoint(url16);
        system.debug('after update Site');}    
        //request1.setHeader('X-HTTP-Method-Override','PATCH');
        request1.setMethod('PUT');
       //request1.setMethod('PATCH');
            //request1.setHeader('Content-Type', 'application/json;charset=UTF-8');
            
            request1.setHeader('Authorization',header1);
            request1.setHeader('Accept', 'application/xml');
            request1.setHeader('Content-Type', 'application/xml');
            
            //string reqXML=createXMLforServiceEntity(se1);
            system.debug('---reqXML--' +ReqXML);
            request1.setBody(ReqXML);
            //request1.setTimeout(10000);
            HttpResponse response1 = http1.send(request1);  
            System.debug('--response1.getStatusCode() + -- + response1.getStatus()'+response1.getStatusCode() + ' ' + response1.getStatus());
            System.debug('---response1.getBody--' +response1.getBody());
            return response1;
    }
    //Lock the submitted record so that no one can edit.
    public static void LockSERecord(List<Id> recordsToProcess1)
    {
                //Lock the record from editing
        Approval.LockResult[] lrList = Approval.lock(recordsToProcess1, false);
        for(Approval.LockResult lr : lrList) { 

           if (lr.isSuccess()) 
        { 
         // Operation was successful, so get the ID of the record that was processed 
         System.debug('Successfully locked SE with ID: ' + lr.getId()); 
           } 
           else { 
         // Operation failed, so get all errors         
         for(Database.Error err : lr.getErrors()) { 
               System.debug('The following error has occurred.');           
               System.debug(err.getStatusCode() + ': ' + err.getMessage()); 
               System.debug('SE fields that affected this error: ' + err.getFields()); 
             } //for end
           } // else end
         } // main for end
        
        //End Locking process
    }
//unLock the submitted record after successful response code.
    public static void UnLockSERecord(List<Service_Entity__c> recordsToProcess1)
    {
                //Lock the record from editing
        Approval.unLockResult[] lrList = Approval.unlock(recordsToProcess1, false);
        for(Approval.unLockResult lr : lrList) { 

           if (lr.isSuccess()) 
        { 
         // Operation was successful, so get the ID of the record that was processed 
         System.debug('Successfully unlocked SE with ID: ' + lr.getId()); 
           } 
           else { 
         // Operation failed, so get all errors         
         for(Database.Error err : lr.getErrors()) { 
               System.debug('The following error has occurred.');           
               System.debug(err.getStatusCode() + ': ' + err.getMessage()); 
               System.debug('SE fields that affected this error: ' + err.getFields()); 
             } //for end
           } // else end
         } // main for end
        
        //End unLocking process
    }
    
    //method to update the SE record that got the response from API call
    @future
    public static void updateSERecord(Id ids,string trCustCode, string trCustId, string syncstatus)
    {
      List<Service_Entity__c> se2=[Select id from Service_Entity__c where id = :ids];  
      for (Service_Entity__c se3 : se2 )
        {  
      se3.TR_Customer_Code__c=trCustCode;
      se3.TR_Customer_Id__c=trCustId;
      se3.Sync_Status__c=syncstatus;
      update se3;      
        }
        
    }

--------------------------------------------
Here is the error i am getting
---------------------------------------------
Future method cannot be called from a future or batch method: synchSEDeptSitesToTR.syncSEToTR(List<String>)
---------------------------------------------

Kindly guide me in fixing this issue.

Thanks
Rao
  • July 20, 2019
  • Like
  • 0
Hello Gurus,
I had a trigger(generates an email on department name change) and a test class related to this trigger.  The coverage was 100%. I changed the trigger to fire only when the profile is <> System Administrator.  The trigger is working fine as expected but the Test class is failing.  Here is the trigger code and followed by Test class code.
--------------------------------------------------------------
trigger SendEmailAfterDeptCodeUpdate on Department__c (after update) {
Profile p = [ Select Id, Name from Profile where Id =: UserInfo.getProfileId() ];
        if( !p.Name.equalsIgnoreCase( 'System Administrator' ) ) 
        {
  List<Id> lstdeptsToUpdate=new List<Id>(); 
for(Department__c dept : trigger.new)
{
    If (dept.Name !=trigger.oldMap.get(dept.Id).Name)
    {
    lstdeptsToUpdate.add(dept.Id);
    }
}
    
    If(lstdeptsToUpdate.size()>0)
    {
    Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
    
   // string header = '*TR Customer Code, *Customer Name,*TR Department ID,*Original Department Code,*New Department Code,*SubBranchCode,TR Customer Id \n';
 string header = 'SubBranchCode,TRCustomerId,TRDepartmentID,OriginalDepartmentCode,NewDepartmentCode,TRCustomerCode \n';

    string finalstr = header ;
    String Emailbody;
        
    
    string csvname= 'template_to_update_WO_inv_dept.txt';
    csvAttc.setFileName(csvname);
    
    system.debug('header:' + header);
     String messageBody,priorvalue;   
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    //email.setSubject('Department Code change in Salesforce');     
   for (Department__c dep1 : [Select id, Name,Service_Entity__r.Customer_Name__c,TR_Customer_Code__c,trDepartmentID__c,Service_Entity__r.Sub_Branch__c,Service_Entity__r.Sub_Branch__r.Sub_Branch_Code__c,Service_Entity__r.TR_Customer_Id__c from Department__c where id in : lstdeptsToUpdate and Service_Entity__r.Send_To_TR__c=True])
        {
     priorvalue=trigger.oldMap.get(dep1.Id).Name; 
     //string recordString = dep1.TR_Customer_Code__c + ','+ dep1.Service_Entity__r.Customer_Name__c+','+dep1.trDepartmentID__c +','+priorvalue+','+dep1.Name+','+dep1.Service_Entity__r.Sub_Branch__r.Sub_Branch_Code__c +','+dep1.Service_Entity__r.TR_Customer_Id__c +'\n';
     string recordString = dep1.Service_Entity__r.Sub_Branch__r.Sub_Branch_Code__c+','+dep1.Service_Entity__r.TR_Customer_Id__c+','+dep1.trDepartmentID__c +','+priorvalue+','+dep1.Name +','+ dep1.TR_Customer_Code__c  +'\n';

          finalstr = finalstr +recordString;
      
         messageBody = '<html><body>';
         messageBody = messageBody + 'Here are the details for the change in Department Code in Salesforce ';
         messageBody = messageBody + '<br>';
         messageBody = messageBody + '<br>';            
         messageBody = messageBody + 'TR Customer Code: '+ dep1.TR_Customer_Code__c;
         messageBody = messageBody + '<br>';
         messageBody = messageBody + 'TR Department ID: ' + dep1.trDepartmentID__c;
         messageBody = messageBody + '<br>';
               
         messageBody = messageBody + 'Original Department Code: ' + priorvalue;
         messageBody = messageBody + '<br>';
         messageBody = messageBody + 'New Department Code: ' + dep1.Name;
         messageBody = messageBody + '<br>';
         messageBody = messageBody + '<br>';            
         messageBody = messageBody + 'Additional details are available in the attached excel. Please update the Work Order and Invoicing details with the new department code.';
         messageBody = messageBody + '<br>';
         messageBody = messageBody + '<br>';            
         messageBody = messageBody + 'Assign ticket to - Data Management Backend group';
    
         messageBody = messageBody + '</body></html>';       
    
    blob csvBlob = Blob.valueOf(finalstr);    
    csvAttc.setBody(csvBlob);

    system.debug('----');    
    email.setSubject('Department Code change in Salesforce updated to ' + dep1.Name ); 
    email.setHtmlBody(messageBody);

    email.setToAddresses(new String[]{'raos@gmail.com'});
    email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
    system.debug('email...' + email );
    if(email != null)
      {
       Messaging.sendEmail(new Messaging.singleEmailMessage[] {email}); 
       //   system.debug('Inside send email');
      } 
    }        
}
        }
}
--------------------------------------------------------------
@IsTest
public class SendEmailAfterDeptCodeUpdateTest {
static testMethod void SendEmailAfterDeptCodeUpdateTest()
    {
        Profile p = [ Select Id, Name from Profile where name='System Administrator' limit 1 ];
        //Profile p = [ Select Id, Name from Profile where name='Standard Sales User' limit 1 ];
        User standardSales = new User(profileId = p.id, username ='standarduserAdmin@peak.com', email = 'standarduser123@peak.com', 
                                     emailencodingkey = 'UTF-8', localesidkey ='en_US', languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                    alias='nuser123', lastname='lastname123');
        insert standardSales;
        system.runAs(standardSales)
        {   /*Account a=new Account(Name='Test1',BillingCountry='United States',BillingState='Indiana');
            insert a;
         
            Acquisition__c ac= new Acquisition__c(Name='Test Ac');
            insert ac;
         
            Service_Entity__c Se1=new Service_Entity__c(Customer_Name__c='Testa',Legal_Entity__c='Archive Systems Inc.',Account__c=a.id,AcquisitionDB__c=ac.id);
            insert Se1;*/
            
            Department__c dept1= new Department__c(Name='Test Dept',Department_Name__c='Sample Dept',  CurrencyIsoCode='USD',Service_Entity__c='a0t1W00000Un1kR'); //Se1.Id);
            test.startTest();
            insert dept1;
            test.stopTest();
        }


    }
    static testMethod void updateDepartmentTest1(){
                
        Profile p2 = [ Select Id, Name from Profile where name='Onboarding Team' limit 1 ];
        User standardSales2 = new User(profileId = p2.id, username ='standarduserAdmin123@peak.com', email = 'standarduseranc@peak.com', 
                                     emailencodingkey = 'UTF-8', localesidkey ='en_US', languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                    alias='nuser123', lastname='lastname1231');
        insert standardSales2;

       system.runAs(standardSales2)
        {   Department__c dept11= new Department__c(Name='Test Dept123',Department_Name__c='Sample Dept123',  CurrencyIsoCode='USD',Service_Entity__c='a0t1W00000Un1qH'); //Se1.Id);
            insert dept11  ;   
            test.startTest();
            dept11.Name='Test Dept1243';
            Update dept11;
            test.stopTest();
        }   
    }
    static testMethod void updateDepartmentTest(){
        Profile p = [ Select Id, Name from Profile where name='System Administrator' limit 1 ];
        User standardSales = new User(profileId = p.id, username ='standarduserAdmin@peak.com', email = 'standarduser123@peak.com', 
                                     emailencodingkey = 'UTF-8', localesidkey ='en_US', languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                    alias='nuser123', lastname='lastname123');
        insert standardSales;
        system.runAs(standardSales){
            Department__c dept2= new Department__c(Name='Test Dept2',Department_Name__c='Sample Dept2',  CurrencyIsoCode='USD',Service_Entity__c='a0t1W00000Un4UM'); //Se1.Id);
            insert dept2;
            
            test.startTest();
            dept2.Name='Test Dept3';
            Update dept2;
            test.stopTest();
        }
    }
}
--------------------------------------------------------------

I am getting the following error message

System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

Stack trace is showing this message:
Class.SendEmailAfterDeptCodeUpdateTest.updateDepartmentTest1: line 39, column 1

I have highlighted the line 39.  The new method that i have include is updateDepartmentTest1().

Let me know the mistake I am doing.

Thanks
Rao
  • May 21, 2019
  • Like
  • 0
Hello Gurus ,
I have a custom field(PrimKey) which is type character on Contact. 

1.)I would like to update this field to a unique key combination value for all the existing Contacts using some script.

The value for the first contact processed should be something like 2019ABC00001
The next contact should be updated to 2019ABC00002
The script should generate this unique key in this way for all the contacts.

2.) Generate the same key combination but with different characters (to differentiate from existing contact) for the new contacts using Apex code
This should be a combination of current year followed by ABD followed by 00001
Ex: 2019ABD00001
When the next contact is created it should generate 2019ABD00002.

Let me know how I can achieve these.

Thanks.
Rao
  • May 02, 2019
  • Like
  • 0
Hi Gurus,
I am facing an issue while creating a case.

I am creating a case based on service object with no value for Account. When I am creating the new case I would like to update the Account on Case object with the Account from the Service object. 

Here is my code.

trigger UpdateAccountOnCaseForSE on Case (before insert) {
  List<Id> lstcasesToUpdate=new List<Id>(); 
for(Case c : trigger.new)
{
    If ((c.Account == NULL) && ((c.RecordTypeId =='01240000000codw') || (c.RecordTypeId =='01240000000cohe')) )    
    {
    lstcasesToUpdate.add(c.Id);
    }
}

    If(lstcasesToUpdate.size()>0)
    {
     for (Case c1 : [Select id, Service_Entity__r.Account__c from Case where id in : lstcasesToUpdate])
        {
            C1.AccountId=c1.Service_Entity__r.Account__c;
        }
    }
}

I have no errors but the Case is not getting created saying Account is required.

Thank you for any guidance in this regard.

Rao
  • March 20, 2019
  • Like
  • 0
Hi ,
I got a requirement to create a case in Salesforce whenever an incident is created in ServiceNow with Assignment group as "Salesforce".

Let me know if you have any ideas or if anyone has implemented this.

Thanks in advance.

Rao.
  • January 30, 2019
  • Like
  • 0
Hi ,
I am trying to create a trigger to update two custom fields on Lead object with two values from a Custom object. The trigger is getting executed but it is not working as expected i.e. Branch Name and Distance to Branch are not getting populated. 

Here is the Trigger code
trigger UpdateBranchAndDistanceToBranch on Lead (before insert) {
Set<Id> lstLeadsToUpdate = new Set<Id>();    
    for( Lead l : trigger.new )
    {  system.debug('l.PostalCode....' + l.PostalCode);
        //Get the list of all leads that need an update
        If(l.PostalCode != null && l.Branch_Name__C == null )
        {    
            lstLeadsToUpdate.add(l.Id);
        }
    }
    if(lstLeadsToUpdate.isEmpty() == false)
    {
     List<Lead> finallstLeadsToUpdate=new List<Lead>();
     List<Lead> listLeads = [SELECT id,Branch_Name__c,Distance_To_Branch__c, PostalCode  from Lead WHERE Id in :lstLeadsToUpdate];
       system.debug('listLeads ...' + listLeads);
     For (Lead oLead : listLeads) 
        {   
         Serviced_Postal_Code__c sp=[select Sub_Branch__c,Distance_From_Branch_mi__c from Serviced_Postal_Code__c where Postal_Code__c= : oLead.PostalCode];
         Lead c=new Lead(Id=oLead.Id);
       
         system.debug('sp.Sub_Branch__c..' + sp.Sub_Branch__c);
         system.debug('sp.Distance_From_Branch_mi__c..' + sp.Distance_From_Branch_mi__c);
       
         c.Branch_Name__c =  sp.Sub_Branch__c;
         c.Distance_To_Branch__c  =  sp.Distance_From_Branch_mi__c; 
         finallstLeadsToUpdate.add(c);   
         }  
      
        if (finallstLeadsToUpdate.size()>0)
           {
                update finallstLeadsToUpdate;
            }  
    }               

}
First debug statement(system.debug('l.PostalCode....' + l.PostalCode);) is displaying the postal code that i am keying in for the lead.
The debug log is showing zero rows for "SELECT id,Branch_Name__c,Distance_To_Branch__c, PostalCode  from Lead WHERE Id in :lstLeadsToUpdate"

I am unable to figure out what am I missing in the code that is causing the issue.

Kindly let me know where am I going wrong.

Thanks
Rao

 
  • January 11, 2019
  • Like
  • 0