• Ayyagari Ramesh
  • NEWBIE
  • 50 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 6
    Replies
An email has to be triggered based on below code to but its not working. Something to do with last condition which I am going wrong.
Can anyone point out the approach to define multiple conditions
trigger CreditMemoTrigger on Credit_Memo__c (after update) 
{
    
    for(Credit_Memo__c SC : trigger.new)
    {
        Credit_Memo__c oldSC = Trigger.oldMap.get(SC.Id);
        if(SC.Send_Attachment__c == true &&
        (SC.Record_Approval__c == true || SC.Auto_Approved__c == true) &&
        (SC.Reason_Code_1__c == '1-Invoice Correction - Pricing Error - No impact on inventory'||
        SC.Reason_Code_2__c == '1-Invoice Correction - Pricing Error - No impact on inventory'||
        SC.Reason_Code_3__c == '1-Invoice Correction - Pricing Error - No impact on inventory'||
        SC.Reason_Code_4__c == '1-Invoice Correction - Pricing Error - No impact on inventory'||
        SC.Reason_Code_5__c == '1-Invoice Correction - Pricing Error - No impact on inventory'))
        {
            
            EmailTemplate et=[Select id,subject,body from EmailTemplate where name='KHI Credit Memo VF temp'];
            system.debug('et '+et);
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            
            //add template
            singlemail.setTargetObjectId(SC.Id);
            singlemail.setTemplateId(et.Id);
            singlemail.setWhatId(SC.Id);
         
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
             
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(Label.KHI_Pricing_Email);
            sendTo.add(owneremail);
            // Step 4. Set email contents - you can use variables!
            //singlemail.setSubject('Attachments of Service Complaint-'+SC.Name+' Request by ');
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
         List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
         // List<Attachment> attList = [select Id, Name, Body, BodyLength, ContentType from Attachment where ParentId = : SC.Id];
         for (ContentDocumentLink a : [select Id, LinkedEntityId, ContentDocumentId from ContentDocumentLink where LinkedEntityId = : SC.Id])
          
     
         {
              for (ContentVersion b : [select id,FileType,FileExtension,contentBodyId,ContentLocation,PathOnClient,versionData, ContentUrl,Title from ContentVersion where ContentDocumentId= :a.ContentDocumentId])
              {
         // Add to attachment file list
         Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
         efa.setFileName(b.Title+ '.' + b.FileExtension);
         blob WOCFbody = b.versiondata;
         efa.setBody(WOCFbody);
         // efa.setContentType(b.PathOnClient);
         fileAttachments.add(efa);
              system.debug('SC.Attachment '+fileAttachments);
         }
         }
         singlemail.setFileAttachments(fileAttachments);

         //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
        } 
        
        Else if(SC.Send_Attachment__c == true &&
        (SC.Record_Approval__c == true || SC.Auto_Approved__c == true) &&
        (SC.Reason_Code_1__c == '6-Other'||
        SC.Reason_Code_2__c == '6-Other'||
        SC.Reason_Code_3__c == '6-Other'||
        SC.Reason_Code_4__c == '6-Other'||
        SC.Reason_Code_5__c == '6-Other'))
        {
            
            EmailTemplate et=[Select id,subject,body from EmailTemplate where name='KHI Credit Memo VF temp'];
            system.debug('et '+et);
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            
            //add template
            singlemail.setTargetObjectId(SC.Id);
            singlemail.setTemplateId(et.Id);
            singlemail.setWhatId(SC.Id);
         
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
             
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(Label.KFI_Credit_Email);
            system.debug('KFI_Credit_Email ');
            sendTo.add(owneremail);
            // Step 4. Set email contents - you can use variables!
            //singlemail.setSubject('Attachments of Service Complaint-'+SC.Name+' Request by ');
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
         List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
         // List<Attachment> attList = [select Id, Name, Body, BodyLength, ContentType from Attachment where ParentId = : SC.Id];
         for (ContentDocumentLink a : [select Id, LinkedEntityId, ContentDocumentId from ContentDocumentLink where LinkedEntityId = : SC.Id])
          
     
         {
              for (ContentVersion b : [select id,FileType,FileExtension,contentBodyId,ContentLocation,PathOnClient,versionData, ContentUrl,Title from ContentVersion where ContentDocumentId= :a.ContentDocumentId])
              {
         // Add to attachment file list
         Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
         efa.setFileName(b.Title+ '.' + b.FileExtension);
         blob WOCFbody = b.versiondata;
         efa.setBody(WOCFbody);
         // efa.setContentType(b.PathOnClient);
         fileAttachments.add(efa);
              system.debug('SC.Attachment '+fileAttachments);
         }
         }
         singlemail.setFileAttachments(fileAttachments);

         //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
        }
        
        Else if(SC.Send_Attachment__c == true &&
        (SC.Record_Approval__c == true || SC.Auto_Approved__c == true) &&
        (SC.reason_check__c == true ))      
        {
            
            EmailTemplate et=[Select id,subject,body from EmailTemplate where name='KHI Credit Memo VF temp'];
            system.debug('et '+et);
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            
            //add template
            singlemail.setTargetObjectId(SC.Id);
            singlemail.setTemplateId(et.Id);
            singlemail.setWhatId(SC.Id);
         
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
             
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(Label.KHI_Claims_Email);
            sendTo.add(owneremail);
            // Step 4. Set email contents - you can use variables!
            //singlemail.setSubject('Attachments of Service Complaint-'+SC.Name+' Request by ');
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
         List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
         // List<Attachment> attList = [select Id, Name, Body, BodyLength, ContentType from Attachment where ParentId = : SC.Id];
         for (ContentDocumentLink a : [select Id, LinkedEntityId, ContentDocumentId from ContentDocumentLink where LinkedEntityId = : SC.Id])
          
     
         {
              for (ContentVersion b : [select id,FileType,FileExtension,contentBodyId,ContentLocation,PathOnClient,versionData, ContentUrl,Title from ContentVersion where ContentDocumentId= :a.ContentDocumentId])
              {
         // Add to attachment file list
         Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
         efa.setFileName(b.Title+ '.' + b.FileExtension);
         blob WOCFbody = b.versiondata;
         efa.setBody(WOCFbody);
         // efa.setContentType(b.PathOnClient);
         fileAttachments.add(efa);
              system.debug('SC.Attachment '+fileAttachments);
         }
         }
         singlemail.setFileAttachments(fileAttachments);

         //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
        }
    
    }
}
I have a picklist field  Z and its value are like A,B,C. I want to create formulae field and mark it true when the picklist field contains values A and B only. Tried multiple and unable to acheive it. please help
one example as below tried as well but not working:
IF(OR(TEXT(Z__c) = 'A',TEXT(Reason_Code_1__c) = 'B'),true,false)
In Salesforce CPQ I have updated the Ship To name,address,city,zip in quote detail page and saved and  got updated  and reflecting but when checking PDF document the Ship to name is showing the old name and and not updated to new name but the address, city, zip is showing the updated values. What must be reason can anyone share the path to troubleshoot the issue.
Class:
global class ContractRenewalBatchJob implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        Date endDateContract = system.today() + Integer.valueOf(Label.KHCPQ_RenewalEmailDuration);
        Date endDateContract1 = system.today() + Integer.valueOf(Label.KHCPQ_RenewalEmailDuration1);
        Date endDateContract2 = system.today() + Integer.valueOf(Label.KHCPQ_RenewalEmailDuration2);
        Date endDateContract3 = system.today() + Integer.valueOf(Label.KHCPQ_RenewalEmailDuration3);
        
        String query = 'select id,Account.Name,Owner.Email,Owner.Name,Ownerid,EndDate,ContractNumber,CustomerSigned.id from Contract where (enddate=:endDateContract OR enddate=:endDateContract1 OR enddate=:endDateContract2 OR enddate=:endDateContract3) and (SBQQ__RenewalForecast__c=false and SBQQ__RenewalQuoted__c=false)';
        List<sObject> sobjList = Database.query(query);
        system.debug('ttt'+sobjList);
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Contract> scope)
    {
        try
        {
            List<Messaging.SingleEmailMessage>  myEmails = new List<Messaging.SingleEmailMessage>();
            for(Contract c:scope)
            {
                system.debug('Contract : ' + c);
                String body;
                body = 'Hi ' + c.Owner.Name + ',<br/><br/>';
                body = body + 'Contract ' + c.ContractNumber + ' is expiring on ' + c.EndDate.month() + '/' + c.EndDate.day() + '/' + c.EndDate.year() + '.<br/>';
                body = body + '<br/>Please renew the Contract ASAP. You can access the contract in the URL below:<br/><br/>';
                body = body + Label.WebsiteURL + '/' + c.id + '<br/><br/>';
                body = body + 'Regards,<br/>AFH Sales Ops Team';
                
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setHTMLBody(body);
                mail.setToAddresses(new String[]{c.owner.email});
                mail.setSubject('ACTION REQUIRED: Your \"' + c.Account.Name + '\" Contract Requires Renewal');
                myEmails.add(mail);
            }
            if(myEmails.size() > 0)
            {
                Messaging.sendEmail(myEmails,false);
            }
        }
        catch(Exception ex)
        {
            system.debug('Exception : ' + ex.getMessage());
        }
    }
    global void finish(Database.BatchableContext BC)
    {
    }
}
test class:
@isTest
public class ContractRenewalBatchJobTest 
{
    static testMethod void testMethod1()
    {
        User us = [Select id from User where Id = :UserInfo.getUserId()];
        Date startDateWithinRange =  system.today();   
        Date endDateWithinRange = system.today() + 29;
        Date endDateWithinRange1 = system.today() + 59;
        Date endDateWithinRange2 = system.today() + 89;
        Date endDateWithinRange3 = system.today() + 119;
        Account acc1 = KHCPQ_Test_DataFactory.createAccount('Parent Account','Active','Street 1','123');
        Contract contract1 = KHCPQ_Test_DataFactory.createContract(acc1.Id,'Draft',startDateWithinRange,endDateWithinRange);
        Contract contract2 = KHCPQ_Test_DataFactory.createContract(acc1.Id,'Draft',startDateWithinRange,endDateWithinRange1);
        Contract contract3 = KHCPQ_Test_DataFactory.createContract(acc1.Id,'Draft',startDateWithinRange,endDateWithinRange2);
        Contract contract4 = KHCPQ_Test_DataFactory.createContract(acc1.Id,'Draft',startDateWithinRange,endDateWithinRange3);
        System.runAs(us)
        Test.startTest();
        ContractRenewalBatchJob obj = new ContractRenewalBatchJob();
        DataBase.executeBatch(obj);
        ContractRenewSchedule sch = new ContractRenewSchedule();
        String cronStr = '0 0 0,12 * * ?';
        system.schedule('testJob', cronStr, sch);
        Test.stopTest();
    }
}
Hi All,  
there is a integration happening into salesforce from SAP end and when the load happens the records created in custom object Product staging and from there using trigger the new record gets created in standard object product..Now the records are not getting created from source file when load is happening. when tried out through manual load by taking one records using workbench and set the debug logs and exception error got captured as below:
field_integrity_exception, product hierarchy: id value of incorrect type: a041h00000lj99fqas: [product_node_id__c]

note - product_node_id__c is a lookup field.
I have written an invocable apex class for process builder to update th owner change of accounts and related Opportunity, contracts and quotes on custom object and its working fine. Now i need to bulkify the code. what are the changes required in below code ?
below code :
public class RequestPortalRecords
{
    @InvocableMethod
    public static void ReqChange(List<Request_Portal__c> rp)
    {
        system.debug('entered raghav' +rp);
        Set<Id> accountIds=new Set<Id>();
        Id ownerid;
        list<Account> updateAccOwnerList = new list<Account>();
        list<Opportunity> updateoppList = new list<Opportunity>();
        list<SBQQ__Quote__c> updateqsList = new list<SBQQ__Quote__c>();
        list<contract> updatecrList=new list<contract>();
        
        
        for(Request_Portal__c r : rp)
        {
            accountIds.add(r.Account_Name__c);
            ownerid=r.New_Owner__c;
            system.debug('accountIds'+accountIds+' ownerid'+ ownerid);
            
        }
        
        //updaTE ACCOUNT
        List<Account> accList=[Select id,ownerid from account where id=:accountIds];
        system.debug('accList'+accList.size());
        
        for(Account acc:accList){
            acc.ownerid=ownerid;
            updateAccOwnerList.add(acc);
        }
        
        system.debug('updateAccOwnerList'+updateAccOwnerList.size());
        if(updateAccOwnerList.size()>0){
            update updateAccOwnerList;
        }
        
        //update opportunities
        List<Opportunity> oppList=[Select id,Ownerid,AccountId from Opportunity Where AccountId = :accountIds ];
        system.debug('opplist'+oppList.size());
        
        
        
        for(Opportunity op: opplist){
            op.ownerid=ownerid;
            updateoppList.add(op);
            
        }
        
        system.debug('updateoppList'+updateoppList);  
        
        if(!updateoppList.isEmpty())
            update updateoppList;  
    
    //update Quote
    List<SBQQ__Quote__c> qsList=[Select id,Ownerid from SBQQ__Quote__c where SBQQ__Account__c = :accountIds];
     for(SBQQ__Quote__c qs: qsList){
            qs.ownerid=ownerid;
           updateqsList.add(qs);
            
      }
        system.debug('updateqsList'+updateqsList);  
        
        if(!updateqsList.isEmpty())
            update updateqsList; 
        
        //contract
        List<Contract> crList=[Select id,Ownerid from Contract where AccountId = :accountIds];
     for(Contract qs: crList){
            qs.ownerid=ownerid;
           updatecrList.add(qs);
            
      }
        system.debug('updatecrList'+updatecrList);  
        
        if(!updatecrList.isEmpty())
            update updatecrList;  
    }    
}
Hi All, 

I have written a batch class and the scenerio is to delete the unused reports which are 6 months old. User-added imageI am getting repeated errors, not sure where i am going wrong
Please find the below code  and do let me know if  any changes required to be made.

Batch Class :

global class BatchMassDeleteReports implements Database.Batchable<sObject>{
    

    public Database.QueryLocator start(Database.BatchableContext context)
    {
        return Database.getQueryLocator('Select ID from Report where LastRunDate <= LAST_N_DAYS:180');
    }

    public void execute(Database.BatchableContext context, List<Report> records)
    {
        delete records;
    }
   public void finish(Database.BatchableContext){
        
    }
}  


Also find the schedule class below :


public DeleteReportSchedulerClass() {
    }
    
    global void execute(SchedulableContext sc){
        try{
            //Executing batch class (size:50).
            BatchMassDeleteReports batchApexSchd = new BatchMassDeleteReports();   
            database.executebatch(batchApexSchd, 50);
            
            }catch(exception ex){
             //Catching any exception that occurs.
            System.Debug('There was an error ' + ex.getMessage());
            }
    }




Thanks, 
Ramesh
Hi all,

I have written batch class  which will be sheduled to delete reports which were created 6 months and are not used. I am not sure if this is correct or is there anything required please need suggestion for this.
Global class BatchMassDeleteReports Implements Database.batchable<sobject>{
    
     global Database.QueryLocator start(Database.BatchableContext BC){
        
     return Database.getQueryLocator([SELECT Id from Report where CreatedDate <= LAST_N_DAYS:180 AND LastModifiedDate <= LAST_N_DAYS:180]);
     }
     global  void execute(Database.BatchableContext BC,List<Report> scope){
         list<Report> delReports = (list<Report>)scope;
         if(delReports.CreatedDate <= LAST_N_DAYS:180 && delReports.LastModifiedDate <= LAST_N_DAYS:180)
         {
         delete delReports;
         }   
    }
    global void finish(Database.BatchableContext BC){
        
    }

 } 
connected Application crashes when user login to Application through single sign on, after that Application logo wont appears  instead directed to salesforce login and unable to login using his federation id and password.what may be the reason? 
In VF page i have a picklist field contains 5 picklist values. and for all the 4 picklist values the placholder will be same but for one picklist value the placholder should be different, how to implement this 
As i want to make certain fields read only, and i am facing the issue when i m trying to genarate the pdf. As the values are not coming in pdf output, and when i am removing html-disable = true, the values are coming in pdf
I have a picklist field  Z and its value are like A,B,C. I want to create formulae field and mark it true when the picklist field contains values A and B only. Tried multiple and unable to acheive it. please help
one example as below tried as well but not working:
IF(OR(TEXT(Z__c) = 'A',TEXT(Reason_Code_1__c) = 'B'),true,false)
In Salesforce CPQ I have updated the Ship To name,address,city,zip in quote detail page and saved and  got updated  and reflecting but when checking PDF document the Ship to name is showing the old name and and not updated to new name but the address, city, zip is showing the updated values. What must be reason can anyone share the path to troubleshoot the issue.
I have written an invocable apex class for process builder to update th owner change of accounts and related Opportunity, contracts and quotes on custom object and its working fine. Now i need to bulkify the code. what are the changes required in below code ?
below code :
public class RequestPortalRecords
{
    @InvocableMethod
    public static void ReqChange(List<Request_Portal__c> rp)
    {
        system.debug('entered raghav' +rp);
        Set<Id> accountIds=new Set<Id>();
        Id ownerid;
        list<Account> updateAccOwnerList = new list<Account>();
        list<Opportunity> updateoppList = new list<Opportunity>();
        list<SBQQ__Quote__c> updateqsList = new list<SBQQ__Quote__c>();
        list<contract> updatecrList=new list<contract>();
        
        
        for(Request_Portal__c r : rp)
        {
            accountIds.add(r.Account_Name__c);
            ownerid=r.New_Owner__c;
            system.debug('accountIds'+accountIds+' ownerid'+ ownerid);
            
        }
        
        //updaTE ACCOUNT
        List<Account> accList=[Select id,ownerid from account where id=:accountIds];
        system.debug('accList'+accList.size());
        
        for(Account acc:accList){
            acc.ownerid=ownerid;
            updateAccOwnerList.add(acc);
        }
        
        system.debug('updateAccOwnerList'+updateAccOwnerList.size());
        if(updateAccOwnerList.size()>0){
            update updateAccOwnerList;
        }
        
        //update opportunities
        List<Opportunity> oppList=[Select id,Ownerid,AccountId from Opportunity Where AccountId = :accountIds ];
        system.debug('opplist'+oppList.size());
        
        
        
        for(Opportunity op: opplist){
            op.ownerid=ownerid;
            updateoppList.add(op);
            
        }
        
        system.debug('updateoppList'+updateoppList);  
        
        if(!updateoppList.isEmpty())
            update updateoppList;  
    
    //update Quote
    List<SBQQ__Quote__c> qsList=[Select id,Ownerid from SBQQ__Quote__c where SBQQ__Account__c = :accountIds];
     for(SBQQ__Quote__c qs: qsList){
            qs.ownerid=ownerid;
           updateqsList.add(qs);
            
      }
        system.debug('updateqsList'+updateqsList);  
        
        if(!updateqsList.isEmpty())
            update updateqsList; 
        
        //contract
        List<Contract> crList=[Select id,Ownerid from Contract where AccountId = :accountIds];
     for(Contract qs: crList){
            qs.ownerid=ownerid;
           updatecrList.add(qs);
            
      }
        system.debug('updatecrList'+updatecrList);  
        
        if(!updatecrList.isEmpty())
            update updatecrList;  
    }    
}
Hi all,

I have written batch class  which will be sheduled to delete reports which were created 6 months and are not used. I am not sure if this is correct or is there anything required please need suggestion for this.
Global class BatchMassDeleteReports Implements Database.batchable<sobject>{
    
     global Database.QueryLocator start(Database.BatchableContext BC){
        
     return Database.getQueryLocator([SELECT Id from Report where CreatedDate <= LAST_N_DAYS:180 AND LastModifiedDate <= LAST_N_DAYS:180]);
     }
     global  void execute(Database.BatchableContext BC,List<Report> scope){
         list<Report> delReports = (list<Report>)scope;
         if(delReports.CreatedDate <= LAST_N_DAYS:180 && delReports.LastModifiedDate <= LAST_N_DAYS:180)
         {
         delete delReports;
         }   
    }
    global void finish(Database.BatchableContext BC){
        
    }

 }