• rosh
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 12
    Replies
class--------1
public class createApprovalURL {
public static String generateApprovalURL(String recordID){
         String url='';
         List<ProcessInstanceWorkitem> workItemLst;
    workItemLst = [SELECT id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId=:recordID];
            if(workItemLst.size() > 0){
               url='https://'+ System.URL.getSalesforceBaseUrl().getHost() +   
    '/p/process/ProcessInstanceWorkitemWizardStageManager?id=' + workItemLst[0].id;
            }
    System.debug(url);
        return url;
      }
}

class2----
public class cls_CmpApprovalURL{
    //public Id myId {get;set;}
    //myId = apexpages.currentpage().getparameters().get(id);
    //System.debug(myId)
    public String recID {get; set;}
    public String urlStr{
        get{
            return createApprovalURL.generateApprovalURL(recID);
        }
    }
}
  • October 19, 2022
  • Like
  • 0
public class createApprovalURL {
public static String generateApprovalURL(String recordID){
         String url='';
         List<ProcessInstanceWorkitem> workItemLst;
    workItemLst = [SELECT id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId=:recordID];
            if(workItemLst.size() > 0){
               url='https://'+ System.URL.getSalesforceBaseUrl().getHost() +   
    '/p/process/ProcessInstanceWorkitemWizardStageManager?id=' + workItemLst[0].id;
            }
    System.debug(url);
        return url;
      }
}

class---2
public class cls_CmpApprovalURL{
    //public Id myId {get;set;}
    //myId = apexpages.currentpage().getparameters().get(id);
    //System.debug(myId)
    public String recID {get; set;}
    public String urlStr{
        get{
            return createApprovalURL.generateApprovalURL(recID);
        }
    }
}


solution:---
@isTest
public class createApprovalURLTest {
    @isTest
    public static void testCreateApproval(){
        
        //create processinstance
        //Approval.ProcessResult AccountRequestResult = Approval.Process(Request);
         ProcessInstanceWorkitem pworkItem = new ProcessInstanceWorkitem();
        
         String recordID;
        List<ProcessInstanceWorkitem> workItemLst=[SELECT id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId=:recordID];
         String url='';
        
        url='https://'+ System.URL.getSalesforceBaseUrl().getHost() +   
    '/p/process/ProcessInstanceWorkitemWizardStageManager?id=';
            
         System.debug(url);
        createApprovalURL urll= new createApprovalURL();
        //String recordID
        test.startTest();
        createApprovalURL.generateApprovalURL(recordID);
        test.stopTest();
}

}
  • October 19, 2022
  • Like
  • 0
public class cls_CmpApprovalURL{
    //public Id myId {get;set;}
    //myId = apexpages.currentpage().getparameters().get(id);
    //System.debug(myId)
    public String recID {get; set;}
    public String urlStr{
        get{
            return createApprovalURL.generateApprovalURL(recID);
        }
    }
}
  • October 18, 2022
  • Like
  • 0
public class createApprovalURL {
public static String generateApprovalURL(String recordID){
         String url='';
         List<ProcessInstanceWorkitem> workItemLst;
    workItemLst = [SELECT id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId=:recordID];
            if(workItemLst.size() > 0){
               url='https://'+ System.URL.getSalesforceBaseUrl().getHost() +   
    '/p/process/ProcessInstanceWorkitemWizardStageManager?id=' + workItemLst[0].id;
            }
    System.debug(url);
        return url;
      }
}


class 2:------
public class cls_CmpApprovalURL{
    //public Id myId {get;set;}
    //myId = apexpages.currentpage().getparameters().get(id);
    //System.debug(myId)
    public String recID {get; set;}
    public String urlStr{
        get{
            return createApprovalURL.generateApprovalURL(recID);
        }
    }
}
  • October 18, 2022
  • Like
  • 0
trigger VConnect_SchemePDFLimit on ContentDocument (before delete) {
    if(trigger.isBefore){
        if(trigger.isDelete){
            Set<String> docIdSet = new Set<String>();
            List<VConnect_Scheme_PDF__c> idPdfList = new List<VConnect_Scheme_PDF__c>();
            for(ContentDocument cdl : Trigger.old){
                if(cdl.Id != NULL){
                    docIdSet.add(cdl.Id);
                }
            }
            VConnect_PDFlimitHandler.deleteFiles(docIdSet);
        }
    }
}
  • September 28, 2022
  • Like
  • 0
public with sharing class SFDCAccessControlException extends Exception {

    /**
     * ExceptionType - this enum defines the different types of access control exceptions.
     */
    public enum ExceptionType {
        /**
         * This error is a generic error type.
         */
        GENERIC,
        /**
         * This error type is an object level access violation.
         */
        OBJECT_ACCESS_VIOLATION,
        /**
         * This error type is a field level access violation.
         */
        FIELD_ACCESS_VIOLATION,
        /**
         * This error type is a sharing access violation.
         */
        SHARING_ACCESS_VIOLATION,
        /**
         * This error type is a generic record not found error. This can be due to record does not exist, sharing violation, or other errors.
         */
        NO_RECORD_FOUND,
        /**
         * This error type is a generic field not found error.
         */
        FIELD_NOT_FOUND}

    /**
     * ExceptionReason - this enum defines the different reasons for the exception type.
     */
    public enum ExceptionReason {
        /**
         * This is a generic reason.
         */
        GENERIC,
        /**
         * This error is due to the user not having the create permission on the specific object/field/record.
         */
        NO_CREATE,
        /**
         * This error is due to the user not having the read permission on the specific object/field/record.
         */
        NO_READ,
        /**
         * This error is due to the user not having the update permission on the specific object/field/record.
         */
        NO_UPDATE,
        /**
         * This error is due to the user not having the delete permission on the specific object/field/record.
         */
        NO_DELETE}

    private ExceptionType eType;
    private ExceptionReason eReason;
    private String eObject;
    private String eField;
    private String eText;

    /**
     * Constructor for SFDCAccessControlException.
     * @param eText Error text
     * @param eType ExceptionType for this error
     * @param eReason ExceptionReason for this error
     * @param eObject The object name this error was triggered on
     * @param eField The field name this error was triggered on
     */
    public SFDCAccessControlException(String eText, ExceptionType eType, ExceptionReason eReason, String eObject, String eField) {
        this.eText = eText;
        this.eType = eType;
        this.eReason = eReason;
        this.eObject = eObject;
        this.eField = eField;
        System.debug(this);
    }

    /**
      * Get the exception type - Object Access Violation, Field Access Violation, etc.
      * You might not want to expose the details of the exception to the users.
     * Note : to avoid XSS, make sure to escape text before presenting it to the user.
     */
    public ExceptionType getExceptionType() {
        return this.eType;
    }

    /**
     * Get the exception reason - no create, no update, etc.
      * You might not want to expose the details of the exception to the users.
     * Note : to avoid XSS, make sure to escape text before presenting it to the user.
     */
    public ExceptionReason getExceptionReason() {
        return this.eReason;
    }

    /**
     * Get the object on which the exception occurred.
      * You might not want to expose the details of the exception to the users.
     * Note : to avoid XSS, make sure to escape text before presenting it to the user.
     */
    public String getExceptionObject() {
        return this.eObject;
    }

    /**
     * Get the field on which the exception occurred.
      * You might not want to expose the details of the exception to the users.
     * Note : to avoid XSS, make sure to escape text before presenting it to the user.
     */
    public String getExceptionField() {
        return this.eField;
    }

    /**
     * Get the error text.
      * You might not want to expose the details of the exception to the users.
     * Note : to avoid XSS, make sure to escape text before presenting it to the user.
     */
    public String getText() {
        return this.eText;
    }

    /**
     * Get the error text.
      * You might not want to expose the details of the exception to the users.
     * Note : to avoid XSS, make sure to escape text before presenting it to the user.
     */
    public override String getMessage() {
        return this.eText + ':: ' + this.eReason + ' access violation for ' + this.getExceptionObject() + '.' +  this.getExceptionField();
    }
}
  • September 26, 2022
  • Like
  • 0
trigger VConnect_StockAdjLineItem on VConnect_Stock_Adjustment_Line_Item__c (after update) {
        if(VConnectTriggerSettings__c.getValues('VConnect_StockAdjLineItem').isActive__c){
          
        switch on Trigger.operationType {

           when AFTER_UPDATE{
                  VConnect_StockAdjLineItemHelper.stockadjInventory(trigger.new);
           }
        }
    }
}
  • September 12, 2022
  • Like
  • 0
global class VConnect_RetailerClassificationUpdate implements Database.Batchable<sobject>{
    
    global Database.QueryLocator start(Database.BatchableContext BC) 
    {
        String query = 'SELECT Id,Name,VConnect_Retailer_Class__c,RecordType.name FROM Account where RecordType.DeveloperName=\'VConnect_Retailer\' ';
        System.debug('query'+query);
        return Database.getQueryLocator(query);
        
    }
    global void execute(Database.BatchableContext BC, List<Account>scope)
    {
        map<id,String> updatemap = new map<id,String>();
        Decimal TotalInv=0;
        String Classname;
        Account[] updates = new Account[] {}; 
            for (AggregateResult ar : [ select VConnect_Retailer__c a,Sum(Total_Volume_In_Ltrs__c) Inv from VConnect_Invoice__c where VConnect_Retailer__c in :scope group by VConnect_Retailer__c])
        { 
            updates.add(new Account( Id = (Id) ar.get('a'), Total_Invoice_Volume__c = (Decimal) ar.get('Inv') ));   
            System.debug('updates'+updates);
            TotalInv= (Decimal) ar.get('Inv');
            
        } 
        update updates; 
        System.debug('***** TotalInvc*****'+ TotalInv);
        list< Retailer_Classification__mdt> rc = [SELECT Retailer_Class__c,Start_Range_Vol_In_Ltrs__c,End_Range_Vol_In_Ltrs__c FROM Retailer_Classification__mdt where Start_Range_Vol_In_Ltrs__c<=:TotalInv AND End_Range_Vol_In_Ltrs__c>:TotalInv];
        System.debug('*****rc*****'+rc);
        for(Retailer_Classification__mdt rc2: rc){
            Classname = rc2.Retailer_Class__c;
        }
        System.debug('Classname45454'+Classname);
        For (Account ac : scope) {
            ac.VConnect_Retailer_Class__c=Classname;
        }
        update scope; 
        
    } 
    global void finish(Database.BatchableContext BC) 
    {
    }
    
    
}
  • September 12, 2022
  • Like
  • 0
//trigger by Raktim to restrict creation of PO based on Payment term (date:04/08/2022)

public class VConnect_PurchaseOrderTriggerHelper {
    public static void beforeInsert(List<VConnect_Purchase_Order__c> purOrdr){
        Id primaryInvRecId= Schema.SObjectType.Account.getRecordTypeInfosByName().get('Distributor').getRecordTypeId();
        Account accountId = [SELECT Id,VConnect_Days__c FROM Account WHERE OwnerId=: System.UserInfo.getUserId() AND RecordTypeId =:primaryInvRecId LIMIT 1];
        Set<String> payTerm = new Set<String>();
        for(VConnect_Purchase_Order__c varP : purOrdr){
            payTerm.add(varP.VConnect_Payment_Term__c);
        }
        
        List<VConnect_Payment_Term__c> payTermList = [SELECT Id,Name,VConnect_Days__c,VConnect_Payment_Term__c,VConnect_Payment_Term_Description__c
                                                          FROM VConnect_Payment_Term__c WHERE Name IN:payTerm];

        
        for(VConnect_Purchase_Order__c varPO : purOrdr){
            for(VConnect_Payment_Term__c varPT : payTermList){
                if(varPT.VConnect_Days__c > accountId.VConnect_Days__c){
                    varPO.addError('Payment Term Days exceeding, select less no of days');
                }
            }
        }
    }
}
  • September 12, 2022
  • Like
  • 0
public class VConnect_retailersTriggerHandler {
    public static void preventDeleteRetailer(List<Target_Retailer__c> triggerOld) {
        for(Target_Retailer__c tar_Retailer : triggerOld){
            if(tar_Retailer.VConnect_Survey_Status__c =='Published' || tar_Retailer.VConnect_Survey_Status__c =='Inactive'){
                tar_Retailer.addError('Reatilers can not be deleted of published/Inactive Survey');  
            }
        }   
    }
  • September 07, 2022
  • Like
  • 0

public class VConnect_StockAdjTriggerHelper {
    public static void stockOutInventory(List<VConnect_Stock_Adjustment__c> stckAdjList){
        List<VConnect_Stock_Adjustment__c> stockList = [SELECT Id,Name,VConnect_Status__c,
                                                        (SELECT Id,VConnect_Status__c FROM Stock_Adjustment_Line_Items__r)
                                                        FROM VConnect_Stock_Adjustment__c
                                                        WHERE Id IN:stckAdjList];

        List<VConnect_Stock_Adjustment_Line_Item__c> newUpdateList = new List<VConnect_Stock_Adjustment_Line_Item__c>();
        if(!stockList.isEmpty()){
            for(VConnect_Stock_Adjustment__c varStockAdj : stockList){
                for(VConnect_Stock_Adjustment_Line_Item__c varLineItem : varStockAdj.Stock_Adjustment_Line_Items__r){
                    if(varStockAdj.VConnect_Status__c == 'Approved'){
                        varLineItem.VConnect_Status__c = 'Approved';
                        newUpdateList.add(varLineItem);
                    }
                    
                    else if(varStockAdj.VConnect_Status__c == 'Rejected'){
                        varLineItem.VConnect_Status__c = 'Rejected';
                        newUpdateList.add(varLineItem);
                    }
                    
                }
                
            }
        }
        
        if(!newUpdateList.isEmpty()){
            Database.update(newUpdateList);
        }
        
        
    }
}
  • September 06, 2022
  • Like
  • 0

public class VConnect_EInvoiceAuraHelper {
    @AuraEnabled
    public static void getInvoice(Id recordId) {
        // do some preprocessing.
        // execute the batch here
        Set<Id> poids = new Set<Id>();
        poids.add(recordId);
        System.debug('Called');
        Id jobId = Database.executeBatch(new BatchClassEInvoice(poids),200); // optional batch size can be provides as well.
    }
}
  • September 06, 2022
  • Like
  • 0
public with sharing class Vconnect_SchemeProduct {
    
    @AuraEnabled(Cacheable=true)
    public static List <VConnect_Product_Master__c> getProducts() {
        
        List<VConnect_Product_Master__c> ProductList  = [Select Id,Name, VConnect_Material_Code__c, VConnect_Pack_Size__c,VConnect_Material_Code_Description__c,VConnect_Category__c FROM VConnect_Product_Master__c];
        return ProductList;
    }  

    // @AuraEnabled
    // public static List<VConnect_Product_Master__c> getCategoryValues(String categoryName,String schemeId){
    //     system.debug('schemeId'+schemeId);
    //     List<VConnect_Scheme_Product__c> schemeProdLst = [SELECT Id, Name, VConnect_Scheme__c, VConnect_Product__c FROM VConnect_Scheme_Product__c  where VConnect_Scheme__c =: schemeId];
       
    //     set<id> productId = new set<id>();

    //     for(VConnect_Scheme_Product__c schemeProd : schemeProdLst)
    //     productId.add(schemeProd.VConnect_Product__c);

    //      List<VConnect_Product_Master__c> ProductList  = [Select Id, VConnect_Material_Code__c, VConnect_Pack_Size__c,VConnect_Material_Code_Description__c,VConnect_Category__c FROM VConnect_Product_Master__c 
    //      WHERE VConnect_Category__c = :categoryName AND Id NOT IN: productId];
    //      return ProductList;
    // }  

    @AuraEnabled
    public static String getCategoryValues(String categoryName,String schemeId,Integer pageSize, Integer pageNumber){
      //  system.debug('schemeId'+schemeId);
        List<VConnect_Scheme_Product__c> schemeProdLst = [SELECT Id, Name, VConnect_Scheme__c, VConnect_Product__c FROM VConnect_Scheme_Product__c  where VConnect_Scheme__c =: schemeId];
       
        set<id> productId = new set<id>();

        for(VConnect_Scheme_Product__c schemeProd : schemeProdLst)
        productId.add(schemeProd.VConnect_Product__c);

         List<VConnect_Product_Master__c> ProductList  = [Select Id, VConnect_Material_Code__c, VConnect_Pack_Size__c,VConnect_Material_Code_Description__c,VConnect_Category__c FROM VConnect_Product_Master__c 
         WHERE VConnect_Category__c = :categoryName AND Id NOT IN: productId];
        // return ProductList;

        
        String jsonDT = '';
         
        //Offset for SOQL
        Integer offset = (pageNumber - 1) * pageSize;
         
        //Total Records
      //  Integer totalRecords = [SELECT COUNT() FROM Account];
        Integer totalRecords = ProductList.size();

        Integer recordEnd = pageSize * pageNumber;
         
        ProductDTWrapper objDT =  new ProductDTWrapper();  
        objDT.pageSize = pageSize;
        objDT.pageNumber = pageNumber;
        objDT.recordStart = offset + 1;
        objDT.recordEnd = totalRecords >= recordEnd ? recordEnd : totalRecords;
        objDT.totalRecords = totalRecords;
        objDT.products = [Select Id, VConnect_Material_Code__c, VConnect_Pack_Size__c,VConnect_Material_Code_Description__c,VConnect_Category__c FROM VConnect_Product_Master__c 
        WHERE VConnect_Category__c = :categoryName AND Id NOT IN: productId LIMIT :pageSize OFFSET :offset];
        jsonDT = JSON.serialize(objDT);

       // system.debug('b'+ objDT.accounts );
        return jsonDT;

    } 

    public class ProductDTWrapper {
        public Integer pageSize {get;set;}
        public Integer pageNumber {get;set;}
        public Integer totalRecords {get;set;}
        public Integer recordStart {get;set;}
        public Integer recordEnd {get;set;}
        public List<VConnect_Product_Master__c> products {get;set;}
    }

    @AuraEnabled
     public static List<Sobject> createproductscheme(List<SObject> lstSobjectRecords){
        System.debug('lstSobjectRecords===>'+lstSobjectRecords);
        insert lstSobjectRecords;
        return lstSobjectRecords;
    }

    @AuraEnabled(Cacheable=true)
    public static List<Account> getAreaManger(List<String> selectedState){
        return [SELECT Id, VConnect_Area_Manager__c,VConnect_Area_Manager__r.Name,Zone__c FROM Account where VConnect_Area_Manager__r.state IN : selectedState];
    }  

    @AuraEnabled(Cacheable=true)
    public static List<Account> getDistributor(List<String> selectedAreaManager){
        return [SELECT Id,Name, VConnect_Area_Manager__c,VConnect_Area_Manager__r.Name,Zone__c FROM 
        Account where VConnect_Area_Manager__c IN : selectedAreaManager AND RecordType.Developername = 'VConnect_Distributor'];
    }  

    

    @AuraEnabled
    public static String getRetailer(List<String> selectedDistributor, String schemeId,Integer pageSize, Integer pageNumber){

        List<VConnect_Scheme_Audience__c> schemeAudLst = [Select VConnect_Retailer__c, VConnect_Scheme__c FROM VConnect_Scheme_Audience__c where VConnect_Scheme__c =: schemeId ];
        set<id> retailerId = new set<id>();
        for(VConnect_Scheme_Audience__c schemeAud : schemeAudLst)
        retailerId.add(schemeAud.VConnect_Retailer__c);
        
        list<Account> accLst = [ SELECT Id,Name,VConnect_Distributor__c ,VConnect_Telephone__c,VConnect_City__c,VConnect_Email_Id__c,VConnect_Distributor__r.Name,Zone__c FROM 
         Account where VConnect_Distributor__c IN : selectedDistributor AND RecordType.Developername = 'VConnect_Retailer'  AND ID NOT IN: retailerId];
        

        String jsonDT = '';
         
        //Offset for SOQL
        Integer offset = (pageNumber - 1) * pageSize;
         
        //Total Records
      //  Integer totalRecords = [SELECT COUNT() FROM Account];
        Integer totalRecords = accLst.size();

        Integer recordEnd = pageSize * pageNumber;
         
        AccountDTWrapper objDT =  new AccountDTWrapper();  
        objDT.pageSize = pageSize;
        objDT.pageNumber = pageNumber;
        objDT.recordStart = offset + 1;
        objDT.recordEnd = totalRecords >= recordEnd ? recordEnd : totalRecords;
        objDT.totalRecords = totalRecords;
        objDT.accounts = [SELECT Id,Name,VConnect_Distributor__c ,VConnect_Telephone__c,VConnect_City__c,VConnect_Email_Id__c,VConnect_Distributor__r.Name,Zone__c FROM 
        Account where VConnect_Distributor__c IN : selectedDistributor AND RecordType.Developername = 'VConnect_Retailer'  AND ID NOT IN: retailerId LIMIT :pageSize OFFSET :offset];
        jsonDT = JSON.serialize(objDT);

        system.debug('b'+ objDT.accounts );
        return jsonDT;
    }  

    public class AccountDTWrapper {
        public Integer pageSize {get;set;}
        public Integer pageNumber {get;set;}
        public Integer totalRecords {get;set;}
        public Integer recordStart {get;set;}
        public Integer recordEnd {get;set;}
        public List<Account> accounts {get;set;}
    }

    @AuraEnabled
    public static List<Sobject> createSchemeAudience(List<SObject> lstSobjectRecords){
       System.debug('lstSobjectRecords===>'+lstSobjectRecords);
       insert lstSobjectRecords;
       return lstSobjectRecords;
   }
   
    @AuraEnabled
     public static void insertSchemeSlabs(String jsonOflistOfSlabs) {
        List<VConnect_Scheme_Slab__c> listOfSlabs = (List<VConnect_Scheme_Slab__c>) JSON.deserialize(jsonOflistOfSlabs, List<VConnect_Scheme_Slab__c>.class);
        insert listOfSlabs;
    }

    @AuraEnabled
    public static List<Sobject> upsertSchemeSlabs(List<SObject>  lstSobjectRecords) {
       upsert lstSobjectRecords;
       return lstSobjectRecords;
   }

 @AuraEnabled
    public static List<VConnect_Scheme_Slab__c> saveSchemeSlabs(List<VConnect_Scheme_Slab__c> lstSlabs){
       System.debug('lstSlabs===>'+lstSlabs);
       insert lstSlabs;
       return lstSlabs;
}

@AuraEnabled
public static String getFOCProducts(Integer pageSize, Integer pageNumber ) {
    String jsonDT = '';
         
        //Offset for SOQL
        Integer offset = (pageNumber - 1) * pageSize;
         
        //Total Records
        Integer totalRecords = [SELECT COUNT() FROM VConnect_FOC_Master__c];
       // Integer totalRecords = accLst.size();

        Integer recordEnd = pageSize * pageNumber;
         
        FocProductDTWrapper objDT =  new FocProductDTWrapper();  
        objDT.pageSize = pageSize;
        objDT.pageNumber = pageNumber;
        objDT.recordStart = offset + 1;
        objDT.recordEnd = totalRecords >= recordEnd ? recordEnd : totalRecords;
        objDT.totalRecords = totalRecords;
        objDT.focProducts = [Select Id,Name,VConnect_Product__c,VConnect_Product__r.Name,VConnect_ProductCode__c,VConnect_Amount__c FROM VConnect_FOC_Master__c LIMIT :pageSize OFFSET :offset];
        jsonDT = JSON.serialize(objDT);

        system.debug('b'+ objDT.focProducts );
        return jsonDT;
    }  

    public class FocProductDTWrapper {
        public Integer pageSize {get;set;}
        public Integer pageNumber {get;set;}
        public Integer totalRecords {get;set;}
        public Integer recordStart {get;set;}
        public Integer recordEnd {get;set;}
        public List<VConnect_FOC_Master__c> focProducts {get;set;}
    }
    // List<VConnect_FOC_Master__c> FOCProductList  = [Select Id,Name,VConnect_Product__c,VConnect_ProductCode__c,VConnect_Amount__c FROM VConnect_FOC_Master__c];
    // return FOCProductList;
}
  • September 04, 2022
  • Like
  • 0

global class SchemeAutoApprovalBatch implements Database.Batchable<sObject> {
    global Database.QueryLocator  start(Database.BatchableContext bc) {
        
        String status = 'Approval Pending';
        String query = 'SELECT Id,Name,VConnect_SchemeStartDate__c,VConnect_SchemeEndDate__c,VConnect_Status__c FROM VConnect_Scheme__c WHERE VConnect_Status__c =:status'; // collect the batches of records or objects to be passed to execute
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext bc, List<VConnect_Scheme__c> records){ // process each batch of records
        List<ProcessInstanceWorkitem> workItems = [SELECT Id, ProcessInstanceId, OriginalActorId, ActorId, ElapsedTimeInDays, 
                                                   ElapsedTimeInHours, ElapsedTimeInMinutes, IsDeleted, CreatedDate, CreatedById,
                                                   SystemModstamp FROM ProcessInstanceWorkitem  
                                                  ];
        Set<Id> processInsId = new Set<Id>();
        
        if(workItems.size()>0){
            for(ProcessInstanceWorkitem workItem : workItems){
                processInsId.add(workItem.ProcessInstanceId);
            }
            
            if(processInsId.size()>0){
                Map<Id,ProcessInstance> map_processIns=new Map<Id,ProcessInstance>(
                    [SELECT Id, TargetObjectId FROM ProcessInstance where Id IN : processInsId]
                );
                
                List<ProcessInstance> pInstance_List = [SELECT Id, TargetObjectId FROM ProcessInstance where Id IN : processInsId];
                Set<Id> scheme_Info = new Set<Id>();
                for(ProcessInstance instance_Item : pInstance_List){
                    scheme_Info.add(instance_Item.TargetObjectId);
                }
                
                /*Map<Id,User> userActiveInfoMap =new Map<Id,User>([SELECT Id, IsActive, Name, ProfileId, Profile.Name, Userrole.Name FROM User  
                                                                  WHERE IsActive = true ]);*/
                
                //Integer hourTime = Integer.valueOf(Scheme_Auto_Approval__mdt.getInstance('total_time').Time_To_Auto_Approve__c);
                Map<Id,VConnect_Scheme__c> totalScheme =new  Map<Id,VConnect_Scheme__c>([
                    SELECT Id,Name,VConnect_SchemeStartDate__c,VConnect_SchemeEndDate__c,VConnect_Status__c FROM VConnect_Scheme__c WHERE Id IN :scheme_Info ]);
                
                //List<ProcessInstanceWorkitem> reasignrequests = new List<ProcessInstanceWorkitem>();
                
                List<Approval.ProcessWorkitemRequest> requests = new List<Approval.ProcessWorkitemRequest>();
                
                for(ProcessInstanceWorkitem workItem : workItems){
                    Id targetId = map_processIns.get(workItem.ProcessInstanceId).TargetObjectId;
                    if(totalScheme.containsKey(targetId)){
                        if(workItem.ElapsedTimeInHours > Scheme_Auto_Approval__mdt.getInstance('total_time').Time_To_Auto_Approve__c){
                            Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest();
                            req2.setWorkitemId(workItem.Id);
                            req2.setAction('Approve');
                            req2.setComments('Auto Approved');
                            requests.add(req2);
                        }
                    }
                }
                System.debug(requests);
                Approval.ProcessResult[] processResults = Approval.process(requests);
            }
        }
    }    
    global void finish(Database.BatchableContext bc){
        // execute any post-processing operations
    }    
}
  • September 04, 2022
  • Like
  • 0
public class Tpm_SchemeCommunicationHandler {
    @AuraEnabled(cacheable=true)
    public static void sendSMS(String schPdfId) {
        //VConnect_SchemePDFHandler.pdfLink(schPdfId);
        //VConnect_SchemePDFHandler.sendSMS(schPdfId);
        System.debug('schPdfId'+schPdfId);
        Id jobId = Database.executeBatch(new VConnect_SchemeSMSBatch(schPdfId)); // optional batch size can be provides as well.
        System.debug('jobId'+jobId);
    }
}
  • September 03, 2022
  • Like
  • 0
class--------1
public class createApprovalURL {
public static String generateApprovalURL(String recordID){
         String url='';
         List<ProcessInstanceWorkitem> workItemLst;
    workItemLst = [SELECT id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId=:recordID];
            if(workItemLst.size() > 0){
               url='https://'+ System.URL.getSalesforceBaseUrl().getHost() +   
    '/p/process/ProcessInstanceWorkitemWizardStageManager?id=' + workItemLst[0].id;
            }
    System.debug(url);
        return url;
      }
}

class2----
public class cls_CmpApprovalURL{
    //public Id myId {get;set;}
    //myId = apexpages.currentpage().getparameters().get(id);
    //System.debug(myId)
    public String recID {get; set;}
    public String urlStr{
        get{
            return createApprovalURL.generateApprovalURL(recID);
        }
    }
}
  • October 19, 2022
  • Like
  • 0
public class cls_CmpApprovalURL{
    //public Id myId {get;set;}
    //myId = apexpages.currentpage().getparameters().get(id);
    //System.debug(myId)
    public String recID {get; set;}
    public String urlStr{
        get{
            return createApprovalURL.generateApprovalURL(recID);
        }
    }
}
  • October 18, 2022
  • Like
  • 0
public class createApprovalURL {
public static String generateApprovalURL(String recordID){
         String url='';
         List<ProcessInstanceWorkitem> workItemLst;
    workItemLst = [SELECT id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId=:recordID];
            if(workItemLst.size() > 0){
               url='https://'+ System.URL.getSalesforceBaseUrl().getHost() +   
    '/p/process/ProcessInstanceWorkitemWizardStageManager?id=' + workItemLst[0].id;
            }
    System.debug(url);
        return url;
      }
}


class 2:------
public class cls_CmpApprovalURL{
    //public Id myId {get;set;}
    //myId = apexpages.currentpage().getparameters().get(id);
    //System.debug(myId)
    public String recID {get; set;}
    public String urlStr{
        get{
            return createApprovalURL.generateApprovalURL(recID);
        }
    }
}
  • October 18, 2022
  • Like
  • 0
trigger VConnect_SchemePDFLimit on ContentDocument (before delete) {
    if(trigger.isBefore){
        if(trigger.isDelete){
            Set<String> docIdSet = new Set<String>();
            List<VConnect_Scheme_PDF__c> idPdfList = new List<VConnect_Scheme_PDF__c>();
            for(ContentDocument cdl : Trigger.old){
                if(cdl.Id != NULL){
                    docIdSet.add(cdl.Id);
                }
            }
            VConnect_PDFlimitHandler.deleteFiles(docIdSet);
        }
    }
}
  • September 28, 2022
  • Like
  • 0
trigger VConnect_StockAdjLineItem on VConnect_Stock_Adjustment_Line_Item__c (after update) {
        if(VConnectTriggerSettings__c.getValues('VConnect_StockAdjLineItem').isActive__c){
          
        switch on Trigger.operationType {

           when AFTER_UPDATE{
                  VConnect_StockAdjLineItemHelper.stockadjInventory(trigger.new);
           }
        }
    }
}
  • September 12, 2022
  • Like
  • 0
public class VConnect_retailersTriggerHandler {
    public static void preventDeleteRetailer(List<Target_Retailer__c> triggerOld) {
        for(Target_Retailer__c tar_Retailer : triggerOld){
            if(tar_Retailer.VConnect_Survey_Status__c =='Published' || tar_Retailer.VConnect_Survey_Status__c =='Inactive'){
                tar_Retailer.addError('Reatilers can not be deleted of published/Inactive Survey');  
            }
        }   
    }
  • September 07, 2022
  • Like
  • 0

public class VConnect_StockAdjTriggerHelper {
    public static void stockOutInventory(List<VConnect_Stock_Adjustment__c> stckAdjList){
        List<VConnect_Stock_Adjustment__c> stockList = [SELECT Id,Name,VConnect_Status__c,
                                                        (SELECT Id,VConnect_Status__c FROM Stock_Adjustment_Line_Items__r)
                                                        FROM VConnect_Stock_Adjustment__c
                                                        WHERE Id IN:stckAdjList];

        List<VConnect_Stock_Adjustment_Line_Item__c> newUpdateList = new List<VConnect_Stock_Adjustment_Line_Item__c>();
        if(!stockList.isEmpty()){
            for(VConnect_Stock_Adjustment__c varStockAdj : stockList){
                for(VConnect_Stock_Adjustment_Line_Item__c varLineItem : varStockAdj.Stock_Adjustment_Line_Items__r){
                    if(varStockAdj.VConnect_Status__c == 'Approved'){
                        varLineItem.VConnect_Status__c = 'Approved';
                        newUpdateList.add(varLineItem);
                    }
                    
                    else if(varStockAdj.VConnect_Status__c == 'Rejected'){
                        varLineItem.VConnect_Status__c = 'Rejected';
                        newUpdateList.add(varLineItem);
                    }
                    
                }
                
            }
        }
        
        if(!newUpdateList.isEmpty()){
            Database.update(newUpdateList);
        }
        
        
    }
}
  • September 06, 2022
  • Like
  • 0

public class VConnect_EInvoiceAuraHelper {
    @AuraEnabled
    public static void getInvoice(Id recordId) {
        // do some preprocessing.
        // execute the batch here
        Set<Id> poids = new Set<Id>();
        poids.add(recordId);
        System.debug('Called');
        Id jobId = Database.executeBatch(new BatchClassEInvoice(poids),200); // optional batch size can be provides as well.
    }
}
  • September 06, 2022
  • Like
  • 0
public class Tpm_SchemeCommunicationHandler {
    @AuraEnabled(cacheable=true)
    public static void sendSMS(String schPdfId) {
        //VConnect_SchemePDFHandler.pdfLink(schPdfId);
        //VConnect_SchemePDFHandler.sendSMS(schPdfId);
        System.debug('schPdfId'+schPdfId);
        Id jobId = Database.executeBatch(new VConnect_SchemeSMSBatch(schPdfId)); // optional batch size can be provides as well.
        System.debug('jobId'+jobId);
    }
}
  • September 03, 2022
  • Like
  • 0