• Navya sree 4
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 3
    Replies
Hi All,
Thanks in Advance....!
I want to create data table which i need to use it for several times in my application. where i can pass Object,Fields,where condition, Hyper link fields.... 

Currently I am facing issue in making columns hyper link dynamically.

so please give me suggesions.
 Thanks
Hi
Can anyone help me with test class

global class CreateTaskOnContactFromEmail implements Messaging.InboundEmailHandler {
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){
        
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        String myPlainText= '';
        string sub = '';
        List<Attachment> attachments = new List<Attachment>();
        String docUrl = '';
        
       
        myPlainText = email.plainTextBody;
        sub = email.subject;
       
        
        sub.contains('ref:');
        Task newTask = new Task();
        Account vAcc = new Account();
        EmailMessage  emailMsg = new EmailMessage();
               try {
            vAcc = [SELECT Id, Name, PersonEmail,OwnerId,Owner.Name FROM Account WHERE PersonEmail =:email.fromAddress AND IsPersonAccount = True
                    LIMIT 1]; 
            Contact vCon = [SELECT Id, Name, Email FROM Contact WHERE Email = :email.fromAddress LIMIT 1];
            
            if(vAcc.id != NULL){
                
                Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                message.toAddresses = new String[]{vAcc.OwnerId};
                    message.subject = 'Task is Created for your Account';
                String emailBody = 'Hi'+' '+vAcc.Owner.Name+'\n'+'A new Task is created for your Account'+' '+vAcc.Name;
                message.plainTextBody = emailBody;
                Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{message});
                
                
                if(email.textAttachments != null)
                {
                    for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
                        
                        String body = tAttachment.body;
                        Blob b = blob.valueOf(tAttachment.body);
                        String str = EncodingUtil.base64Encode(b);
                        
                        ContentVersion conVer = new ContentVersion();
                        conVer.VersionData = EncodingUtil.base64Decode(str);
                        conVer.Title = tAttachment.fileName;
                        conVer.ContentLocation = 'S'; 
                        conVer.PathOnClient = tAttachment.fileName;
                        insert conVer;
                        
                        conVer = [select ContentDocumentId from ContentVersion where id = :conVer.id limit 1];
                        
                        ContentDocumentLink cdl = new ContentDocumentLink();
                        cdl.LinkedEntityId = vAcc.id;
                        cdl.ContentDocumentId = conVer.ContentDocumentId;
                        cdl.ShareType = 'I'; 
                        cdl.Visibility = 'InternalUsers';
                        insert cdl; 
                        
                        
                        docUrl += tAttachment.fileName + '\n';
                    }
                }
                if(email.binaryAttachments != null)
                {
                    for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
                        ContentVersion conVer = new ContentVersion();
                        conVer.VersionData = bAttachment.body;
                        conVer.Title = bAttachment.fileName;
                        conVer.ContentLocation = 'S'; 
                        conVer.PathOnClient = bAttachment.fileName;
                        insert conVer;
                        
                        conVer = [select ContentDocumentId from ContentVersion where id = :conVer.id limit 1];
                        
                        ContentDocumentLink cdl = new ContentDocumentLink();
                        cdl.LinkedEntityId = vAcc.id;
                        cdl.ContentDocumentId = conVer.ContentDocumentId;
                        cdl.ShareType = 'I'; 
                        cdl.Visibility = 'InternalUsers';
                        insert cdl;
                        docUrl += bAttachment.fileName + '\n';
                    }
                }
                if(attachments.size() > 0){insert attachments;
                                           system.debug(attachments[0]);}
                
                
                emailMsg.RelatedToId =vAcc.Id;
                emailMsg.TextBody = email.plainTextBody;
                emailMsg.Subject = email.subject;
                emailMsg.FromAddress = email.fromAddress;
                emailMsg.Status = '2';
                emailMsg.Incoming= True;
                emailMsg.Attachment__c = docUrl;
                insert emailMsg;
                
            }
        }catch (QueryException e) {
            UTIL_LoggingService.logHandledException(e, UserInfo.getOrganizationId(),UserInfo.getOrganizationName(),'CreateTaskOnContactFromEmail',
                                                    'handleInboundEmail','', system.LoggingLevel.FINEST); 
        }
        
       
        result.success = true;
        return result;
    }
}

Thanks
public class ContactpQueueable implements Queueable {
    public List<Contact> conToInsert = new List<Contact>();
    public List<Contact> conToDeleteList = new List<Contact>();
    
    
    public void execute(QueueableContext context) {
        if(!conToInsert.isEmpty()){
            Database.insert(conToInsert );
        }
        if(!conDeleteList.isEmpty()){
            Database.delete(conToDeleteList);
        }
    }
}
When entering the information on UI: check, whether the phone number starts with "+" and the international country code. If not show an error message
Hi,
Can you please help me with test class


public class OV_CustomerTierCtrl {
    //To get ultimate parent customer tier,Total leasearea for current account 
    @AuraEnabled public static OV_CustomerTierWrapper getCustomerTier(String id){
        OV_CustomerTierWrapper dbw = new OV_CustomerTierWrapper();
        Account acc = [Select Ultimate_Parent_Account_ID_t__c from Account where Id =:id];
        getLeaseArea(id,dbw,'Local');
        addCustomerTier(dbw.totalLeaseSQFT,'Local',dbw); 
        getLeaseArea(acc.Ultimate_Parent_Account_ID_t__c,dbw,'Global');
        addCustomerTier(dbw.totalUltimateLeaseSQFT,'Global',dbw);
        return dbw;        
    }
    //To get total lease area for entire hirarchy
    private static void getLeaseArea(String id , OV_CustomerTierWrapper dbw,String tierType){
        String acctIds =OV_BAUtility.getAcctIds(id);   
        String leaseSQFTQuery = 'select sum(Lease_Area_SF__c) from Lease__c where isActive__c= \'yes\' AND Account_Name__r.Id IN '+acctIds;
        Decimal leaseSQFT=0;
        try{   
            AggregateResult[] acct = database.query(leaseSQFTQuery);
            if(acct[0].get('expr0')!=null){
                leaseSQFT = (Decimal)acct[0].get('expr0');
            } 
            if(tierType=='Global'){
                dbw.totalUltimateLeaseSQFT=leaseSQFT;
            }else{
                dbw.totalLeaseSQFT=leaseSQFT;
            }    
        }catch(Exception e){
        }        
    }
    //To update ultimate parent customer tier based on total lease area 
    private static void addCustomerTier(Decimal leaseArea,String tierType,OV_CustomerTierWrapper dbw ){
        String customerTier='';
        CustomerTier__c tier =[SELECT Bronze_Level__c,Gold_Level__c,Platinum_Level__c,Silver_Level__c FROM CustomerTier__c];
        if(leaseArea < tier.Bronze_Level__c){
            customerTier='Bronze'; 
        }else if(leaseArea>=tier.Bronze_Level__c && leaseArea<tier.Silver_Level__c){
            customerTier='Silver'; 
        }else if(leaseArea>=tier.Silver_Level__c && leaseArea<tier.Gold_Level__c){
            customerTier='Gold'; 
        }else{
            customerTier='Platinum';  
        }
        if(tierType=='Global'){
            dbw.globalUltimateTier=customerTier;
        }else{
            dbw.customerTier=customerTier;
        }        
    }
    public class OV_CustomerTierWrapper{
        @AuraEnabled public Decimal totalLeaseSQFT{get;set;}
        @AuraEnabled public Decimal totalUltimateLeaseSQFT{get;set;}
        @AuraEnabled public String customerTier{get;set;}
        @AuraEnabled public String globalUltimateTier{get;set;}
    }
}
Hi 

Test Class Help


public with sharing class ForecastArchiveController {
    public String userInfo {get; private set;}
    public ForecastArchiveController() {
        setUserDetails(this);
    }
    
    public static void setUserDetails(ForecastArchiveController controller) {
        User userDetail = [SELECT Id, Name, Forecast_OA_Region_Name__c, Forecast_OA_Region_Id__c, UserRole.Name, Profile.Name FROM User WHERE Id =: UserInfo.getUserId()];
        UserWrapper userWrap = new UserWrapper(userDetail);
        controller.userInfo = JSON.serialize(userWrap);
    }

    public class UserWrapper {
        public String userName;
        public String userId;
        public String userForecastOARegion;
        public String userForecastOARegionId;
        public String userRole;
        public String userProfile;

        public UserWrapper(User user) {
            this.userName = user.Name;
            this.userId = user.Id;
            this.userForecastOARegion = user.Forecast_OA_Region_Name__c;
            this.userForecastOARegionId = user.Forecast_OA_Region_Id__c;
            this.userRole = user.UserRole.Name;
            this.userProfile = user.Profile.Name;
        }
    }
}
Hi ,
Can you please help me with test class


global class UpdateUnitHighestStageBatchJob implements Database.Batchable<sObject>{
    
    private List<Id> unitIds;

    public UpdateUnitHighestStageBatchJob() {

    }

    public UpdateUnitHighestStageBatchJob(List<Id> parameter) {
        unitIds = parameter;
    }

    global Database.QueryLocator start(Database.BatchableContext context) {
        String soql = 'SELECT Id, Opportunity_Highest_Stage__c FROM Unit__c';
        if (null != unitIds && !unitIds.isEmpty()) {
            soql += ' WHERE Id IN :unitIds';
        }
        return Database.getQueryLocator(soql);
    }
    
    global void execute (Database.BatchableContext context , List<sObject> scope) {
        List<Unit__c> units = (List<Unit__c>) scope;
        Map<Id, Unit__c> units2Update = new Map<Id, Unit__c>();
        for (Unit__c unit: units) {
            List<Unit_Opportunity_Relationship__c> uors = [SELECT Unit__c, Opportunity__r.StageName FROM Unit_Opportunity_Relationship__c 
                        WHERE Unit__c = :unit.Id AND Opportunity__r.StageName != 'Closed Won' AND 
                            Opportunity__r.StageName != 'Closed Lost'];
            String OpportunityHighestStage = 'Z';
            for (Unit_Opportunity_Relationship__c uor : uors) {
                if (OpportunityHighestStage.codePointAt(0) > uor.Opportunity__r.StageName.codePointAt(0)) {
                    OpportunityHighestStage = uor.Opportunity__r.StageName;
                }
              }
              if ('Z' != OpportunityHighestStage) {
                unit.Opportunity_Highest_Stage__c = OpportunityHighestStage;
                units2Update.put(unit.Id, unit);
            }        
        }
        
        if (!units2Update.isEmpty()) {
            update(units2Update.values());    
        }
    }

    global void finish (Database.BatchableContext context) {

    }
}
Hi Everyone,

Please help me with test class.


global class Constants
{
    // -------- Constants --------    
    // Diagnostic
    public static final String ENTERING = 'Entering: ';
    public static final String EXITING = 'Exiting: ';
    public static final String LOG = 'Diagnostics Log:\n';
    public static final String START_ERROR = 'Exception occurred: ';
    
    // From lead triggers
    public static final String CONVERT_LEAD_DEFAULT_OCR_ROLE = 'Other';
    public static final String LEAD_OPEN_STATUS = 'Open';
    public static final String LEAD_REJECTED_STATUS = 'Rejected';
    public static final String LEAD_REENGAGE_STATUS = 'Re-engage';
    public static final String LEAD_STAGE_SAL = 'Sales Accepted Lead';
    public static final String LEAD_STAGE_SQO = 'Sales Qualified Opportunity';
    public static final String LEAD_STAGE_MQL = 'Marketing Qualified Lead';
    public static final String LEAD_SUBSCRIPTION_UNSUBSCRIBED = 'Unsubscribed';
    public static final String LEAD_SUBSCRIPTION_SUBSCRIBED = 'Subscribed';
    public static final String LEAD_VLP_STATUS = 'VLP';
    
    // Scheduling helpers
    public static final String WEEKLY = 'Weekly';
    public static final String DAILY = 'Daily';
    public static final String HOURLY = 'Hourly';
    
    public static final String MONDAY = 'Monday';
    public static final String TUESDAY = 'Tuesday';
    public static final String WEDNESDAY = 'Wednesday';
    public static final String THURSDAY = 'Thursday';
    public static final String FRIDAY = 'Friday';
    public static final String SATURDAY = 'Saturday';
    public static final String SUNDAY = 'Sunday';
    public static final String MON = 'MON';
    public static final String TUE = 'TUE';
    public static final String WED = 'WED';
    public static final String THU = 'THU';
    public static final String FRI = 'FRI';
    public static final String SAT = 'SAT';
    public static final String SUN = 'SUN';
    
    public static final String AM12 = '12:00 AM';
    public static final String AM1 = '01:00 AM';
    public static final String AM2 = '02:00 AM';
    public static final String AM3 = '03:00 AM';
    public static final String AM4 = '04:00 AM';
    public static final String AM5 = '05:00 AM';
    public static final String AM6 = '06:00 AM';
    public static final String AM7 = '07:00 AM';
    public static final String AM8 = '08:00 AM';
    public static final String AM9 = '09:00 AM';
    public static final String AM10 = '10:00 AM';
    public static final String AM11 = '11:00 AM';
    public static final String PM12 = '12:00 PM';
    public static final String PM1 = '01:00 PM';
    public static final String PM2 = '02:00 PM';
    public static final String PM3 = '03:00 PM';
    public static final String PM4 = '04:00 PM';
    public static final String PM5 = '05:00 PM';
    public static final String PM6 = '06:00 PM';
    public static final String PM7 = '07:00 PM';
    public static final String PM8 = '08:00 PM';
    public static final String PM9 = '09:00 PM';
    public static final String PM10 = '10:00 PM';
    public static final String PM11 = '11:00 PM';
    public static final String MIL_AM12 = '0';
    public static final String MIL_AM1 = '1';
    public static final String MIL_AM2 = '2';
    public static final String MIL_AM3 = '3';
    public static final String MIL_AM4 = '4';
    public static final String MIL_AM5 = '5';
    public static final String MIL_AM6 = '6';
    public static final String MIL_AM7 = '7';
    public static final String MIL_AM8 = '8';
    public static final String MIL_AM9 = '9';
    public static final String MIL_AM10 = '10';
    public static final String MIL_AM11 = '11';
    public static final String MIL_PM12 = '12';
    public static final String MIL_PM1 = '13';
    public static final String MIL_PM2 = '14';
    public static final String MIL_PM3 = '15';
    public static final String MIL_PM4 = '16';
    public static final String MIL_PM5 = '17';
    public static final String MIL_PM6 = '18';
    public static final String MIL_PM7 = '19';
    public static final String MIL_PM8 = '20';
    public static final String MIL_PM9 = '21';
    public static final String MIL_PM10 = '22';
    public static final String MIL_PM11 = '23';
    
    public static final String JAN = 'JAN';
    public static final String FEB = 'FEB';
    public static final String MAR = 'MAR';
    public static final String APR = 'APR';
    public static final String MAY = 'MAY';
    public static final String JUN = 'JUN';
    public static final String JUL = 'JUL';
    public static final String AUG = 'AUG';
    public static final String SEP = 'SEP';
    public static final String OCT = 'OCT';
    public static final String NOV = 'NOV';
    public static final String DEC = 'DEC';
    public static final String LABEL_JANURARY = 'Janurary';
    public static final String LABEL_FEBRUARY = 'February';
    public static final String LABEL_MARCH = 'March';
    public static final String LABEL_APRIL = 'April';
    public static final String LABEL_MAY = 'May';
    public static final String LABEL_JUNE = 'June';
    public static final String LABEL_JULY = 'July';
    public static final String LABEL_AUGUST = 'August';
    public static final String LABEL_SEPTEMBER = 'September';
    public static final String LABEL_OCTOBER = 'October';
    public static final String LABEL_NOVEMBER = 'November';
    public static final String LABEL_DECEMBER = 'December';
    
    // -------- Constructor --------
    // None

    // -------- Variables --------
    // None
    
    // -------- Properties --------
    // None
    
    // -------- Methods --------
    // Return a select option list of days
    public static List<SelectOption> buildListOfDays()
    {
        List<SelectOption> result = new List<SelectOption>();
        result.add(new SelectOption(Constants.MON, Constants.MONDAY));
        result.add(new SelectOption(Constants.TUE, Constants.TUESDAY));
        result.add(new SelectOption(Constants.WED, Constants.WEDNESDAY));
        result.add(new SelectOption(Constants.THU, Constants.THURSDAY));
        result.add(new SelectOption(Constants.FRI, Constants.FRIDAY));
        result.add(new SelectOption(Constants.SAT, Constants.SATURDAY));
        result.add(new SelectOption(Constants.SUN, Constants.SUNDAY));
        
        return result;
    } 
    
    // Return a set of days
    public static Set<String> buildSetOfDays()
    {
        Set<String> result = new Set<String>();
        result.add(Constants.MON);
        result.add(Constants.TUE);
        result.add(Constants.WED);
        result.add(Constants.THU);
        result.add(Constants.FRI);
        result.add(Constants.SAT);
        result.add(Constants.SUN);
        
        return result;
    }
    
    // Return a select options list of hours
    public static List<SelectOption> buildListOfHours()
    {
        List<SelectOption> result = new List<SelectOption>();
        result.add(new SelectOption(Constants.MIL_AM12, Constants.AM12));
        result.add(new SelectOption(Constants.MIL_AM1, Constants.AM1));
        result.add(new SelectOption(Constants.MIL_AM2, Constants.AM2));
        result.add(new SelectOption(Constants.MIL_AM3, Constants.AM3));
        result.add(new SelectOption(Constants.MIL_AM4, Constants.AM4));
        result.add(new SelectOption(Constants.MIL_AM5, Constants.AM5));
        result.add(new SelectOption(Constants.MIL_AM6, Constants.AM6));
        result.add(new SelectOption(Constants.MIL_AM7, Constants.AM7));
        result.add(new SelectOption(Constants.MIL_AM8, Constants.AM8));
        result.add(new SelectOption(Constants.MIL_AM9, Constants.AM9));
        result.add(new SelectOption(Constants.MIL_AM10, Constants.AM10));
        result.add(new SelectOption(Constants.MIL_AM11, Constants.AM11));
        result.add(new SelectOption(Constants.MIL_PM12, Constants.PM12));
        result.add(new SelectOption(Constants.MIL_PM1, Constants.PM1));
        result.add(new SelectOption(Constants.MIL_PM2, Constants.PM2));
        result.add(new SelectOption(Constants.MIL_PM3, Constants.PM3));
        result.add(new SelectOption(Constants.MIL_PM4, Constants.PM4));
        result.add(new SelectOption(Constants.MIL_PM5, Constants.PM5));
        result.add(new SelectOption(Constants.MIL_PM6, Constants.PM6));
        result.add(new SelectOption(Constants.MIL_PM7, Constants.PM7));
        result.add(new SelectOption(Constants.MIL_PM8, Constants.PM8));
        result.add(new SelectOption(Constants.MIL_PM9, Constants.PM9));
        result.add(new SelectOption(Constants.MIL_PM10, Constants.PM10));
        result.add(new SelectOption(Constants.MIL_PM11, Constants.PM11));
        
        return result;
    }
    
    // Return a set of hours
    public static Set<String> buildSetOfHours()
    {
        Set<String> result = new Set<String>();
        result.add(Constants.MIL_AM12);
        result.add(Constants.MIL_AM1);
        result.add(Constants.MIL_AM2);
        result.add(Constants.MIL_AM3);
        result.add(Constants.MIL_AM4);
        result.add(Constants.MIL_AM5);
        result.add(Constants.MIL_AM6);
        result.add(Constants.MIL_AM7);
        result.add(Constants.MIL_AM8);
        result.add(Constants.MIL_AM9);
        result.add(Constants.MIL_AM10);
        result.add(Constants.MIL_AM11);
        result.add(Constants.MIL_PM12);
        result.add(Constants.MIL_PM1);
        result.add(Constants.MIL_PM2);
        result.add(Constants.MIL_PM3);
        result.add(Constants.MIL_PM4);
        result.add(Constants.MIL_PM5);
        result.add(Constants.MIL_PM6);
        result.add(Constants.MIL_PM7);
        result.add(Constants.MIL_PM8);
        result.add(Constants.MIL_PM9);
        result.add(Constants.MIL_PM10);
        result.add(Constants.MIL_PM11);
        
        return result;
    }
    
    // Build list of months for select options
    public static List<SelectOption> buildListOfMonths()
    {
        List<SelectOption> result = new List<SelectOption>();
        result.add(new SelectOption(Constants.JAN, Constants.LABEL_JANURARY));
        result.add(new SelectOption(Constants.FEB, Constants.LABEL_FEBRUARY));
        result.add(new SelectOption(Constants.MAR, Constants.LABEL_MARCH));
        result.add(new SelectOption(Constants.APR, Constants.LABEL_APRIL));
        result.add(new SelectOption(Constants.MAY, Constants.LABEL_MAY));
        result.add(new SelectOption(Constants.JUN, Constants.LABEL_JUNE));
        result.add(new SelectOption(Constants.JUL, Constants.LABEL_JULY));
        result.add(new SelectOption(Constants.AUG, Constants.LABEL_AUGUST));
        result.add(new SelectOption(Constants.SEP, Constants.LABEL_SEPTEMBER));
        result.add(new SelectOption(Constants.OCT, Constants.LABEL_OCTOBER));
        result.add(new SelectOption(Constants.NOV, Constants.LABEL_NOVEMBER));
        result.add(new SelectOption(Constants.DEC, Constants.LABEL_DECEMBER));
        
        return result;
    }
    
    // Build a set of months
    public static Set<String> buildSetOfMonths()
    {
        Set<String> result = new Set<String>();
        result.add(Constants.JAN);
        result.add(Constants.FEB);
        result.add(Constants.MAR);
        result.add(Constants.APR);
        result.add(Constants.MAY);
        result.add(Constants.JUN);
        result.add(Constants.JUL);
        result.add(Constants.AUG);
        result.add(Constants.SEP);
        result.add(Constants.OCT);
        result.add(Constants.NOV);
        result.add(Constants.DEC);
    
        return result;
    }
    
    // -------- Internal Classes --------
    // None
}
Hi,
can you please help me test class

public with sharing class LookupController {

   /* Method to query records using SOSL*/
    @AuraEnabled
    public static String search(String objectAPIName, String searchText,
            List<String> whereClause, List<String> extrafields){

        objectAPIName = String.escapeSingleQuotes(objectAPIName);
        searchText = String.escapeSingleQuotes(searchText);
        String searchQuery = 'FIND \'' + searchText + '*\' IN ALL FIELDS RETURNING ' + objectAPIName + '(Id,Name' ;
        if(!extrafields.isEmpty()){
            searchQuery = searchQuery + ',' + String.join(extrafields, ',') ;
        }
        system.debug(whereClause);
        if(!whereClause.isEmpty()){
            searchQuery = searchQuery + ' WHERE ' ;
            searchQuery = searchQuery + String.join(whereClause, 'AND') ;
        }
        searchQuery = searchQuery + ' LIMIT 10 ) ';
        system.debug(searchQuery);
        return JSON.serializePretty(search.query(searchQuery)) ;
    }

    /* Method to query records using SOQL*/
    @AuraEnabled
    public static List<SObject> getRecentlyViewed(
            String objectAPIName,
            List<String> whereClause,
            List<String> extrafields){

        String searchQuery = 'SELECT Id, Name';
        if(!extrafields.isEmpty()){
            searchQuery = searchQuery + ',' + String.join(extrafields, ',') ;
        }
        //searchQuery = searchQuery + ' FROM ' + objectAPIName + ' WHERE LastViewedDate != NULL ';
        searchQuery = searchQuery + ' FROM ' + objectAPIName ;
        if(!whereClause.isEmpty()){
            searchQuery = searchQuery + ' AND ' ;
            searchQuery = searchQuery + String.join(whereClause, 'AND') ;
            system.debug(searchQuery);
        }
        searchQuery = searchQuery + ' ORDER BY LastViewedDate DESC LIMIT 10 ' ;
        List<SObject> objectList =  new List<SObject>();
                system.debug('-----------------------'+searchQuery);
        objectList = Database.query(searchQuery);
        return objectList;
    }
}


Thanks
Hi ,
Can you please help with test class for paginator.


public class LDS_PaginationController {


    /*
    *  Account pagination query to query record with OFFSET and LIMIT
    * */

    @AuraEnabled
    public static List<Account> getAllRecords(String pageNumber,String currnetPagesCount){
        String accountQuery = 'SELECT Id,Name,Type,Industry,Rating,BillingCity FROM Account ORDER BY Name LIMIT '+currnetPagesCount+'  ';
        if(String.isBlank(pageNumber) || Integer.valueOf(pageNumber) == 1){
           // accountQuery = accountQuery + ' 0';
        }else{
          //  accountQuery = accountQuery + String.valueOf((Integer.valueOf(pageNumber)-1)*Integer.valueOf(currnetPagesCount));
        }
        system.debug(' accountQuery ----------'+accountQuery);
         return Database.query(accountQuery);
    }

    /*
    *  When
total number of records to display changes
    *  provide footer with
new set of page counter info
    *  to display
    * */

    @AuraEnabled
    public static PGN_PageInfo getPageCountInfo(String pageCountInfo){
        
        Integer currentListCount = pageCountInfo != null && pageCountInfo != '' ? Integer.valueOf(pageCountInfo) : 5;
        
        PGN_PageInfo pgn = new PGN_PageInfo();        
        pgn.totalPages = ([SELECT COUNT() FROM Account]/(currentListCount))+1;
        pgn.currentPageNumber = 1;
        List<Integer> cnt = new List<Integer>();
        for(Integer loop_var = 0;loop_var < pgn.totalPages;loop_var++){
            cnt.add(loop_var+1);
            if((loop_var+1) == 4)
                break;
        }
        if(pgn.totalPages > 4)
            cnt.add(pgn.totalPages);
        pgn.pageCounter = cnt;
        
        return pgn;        
    }

    /*
    *  When page count change or next or previous button is clicked
    *  provide footer with
new set of page counter info
    *  to display
    * */

    @AuraEnabled
    public static PGN_PageInfo getPageCountChange(String pageNumber,String currnetPagesCount,String totalPages){
        PGN_PageInfo pgn = new PGN_PageInfo();
        pgn.currentPageNumber = Integer.valueOf(pageNumber);
        pgn.totalPages = Integer.valueOf(totalPages);

        List<Integer> cnt = new List<Integer>();

        if((Integer.valueOf(pageNumber)+2) < Integer.valueOf(totalPages) && Integer.valueOf(pageNumber) != 1){
            for(Integer loop_var = (Integer.valueOf(pageNumber)-1);loop_var < (Integer.valueOf(pageNumber)+3);loop_var++){
                cnt.add(loop_var);
            }
            cnt.add(pgn.totalPages);

        }else if(Integer.valueOf(pageNumber) == 1){
            for(Integer loop_var = 1;loop_var < 5;loop_var++){
                cnt.add(loop_var);
            }
            cnt.add(pgn.totalPages);
        }else{
            if(Integer.valueOf(currnetPagesCount) >= pgn.totalPages){
                for(Integer loop_var = 1;loop_var < (pgn.totalPages+1);loop_var++){
                    cnt.add(loop_var);
                }
            }else{
                for(Integer loop_var = (pgn.totalPages-4);loop_var < (pgn.totalPages+1);loop_var++){
                    cnt.add(loop_var);
                }
            }
        }
        pgn.pageCounter = cnt;

        return pgn;
    }
    
    
}
Hi,
Test Class Failing for Methods defined as TestMethod do not support getContent call


Test Class:
@isTest
private class PicklistDescriberTest {
 
    @isTest 
    static void test() {
        
        Map<String, Schema.RecordTypeInfo> recordTypes = Schema.SObjectType.Account.getRecordTypeInfosByName();
        List<String> recordTypeNames = new List<String>(recordTypes.keyset());
         
      
        
        Account testAccount = new Account(Name='Test Account', Continent__c = 'Asia', Country__c = 'India', RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId());
        insert testAccount;
        
          
        
        System.assert(PicklistDescriber.describe(testAccount.Id, 'Asia').size()!=0);
        
        
        System.assert(PicklistDescriber.describe('Account', recordTypeNames[0], 'Continent__c').size() > 0);
        
        System.assert(PicklistDescriber.describe('Account', recordTypes.get(recordTypeNames[0]).getRecordTypeId(), 'Continent__c').size() > 0);
        
        System.assert(PicklistDescriber.describe('Account', recordTypeNames[0], 'Country__c', 'Continent__c').size() > 0);
        
        System.assert(PicklistDescriber.describeWithDependency('Account', recordTypeNames[0], 'Country__c', 'Continent__c').size() > 0);
        
        System.assert(PicklistDescriber.describeWithDependency('Account', recordTypes.get(recordTypeNames[0]).getRecordTypeId(), 'Country__c', 'Continent__c').size() > 0);
    }
    
}



Actual Class:

public with sharing class PicklistDescriber {
    static final Pattern OPTION_PATTERN = Pattern.compile('<option.+?>(.+?)</option>');

    /**
        Desribe a picklist field for an sobject id. RecordType is automatically picked
        based on the record's RecordTypeId field value.
        example usage :
        List<String> options = PicklistDescriber.describe(accountId, 'Industry');
    */
    public static List<String> describe(Id sobjectId, String pickListFieldAPIName) {
        return parseOptions(
                            new Map<String, String> {
                                                     'id' => sobjectId,
                                                     'pickListFieldName'=> pickListFieldAPIName
                                                    }
                            );
    }

    /**
        Describe a picklist field for a SobjectType, its given record type developer name and the picklist field
        example usage :
        List<String> options = PicklistDescriber.describe('Account', 'Record_Type_1', 'Industry'));
    */
    public static List<String> describe(String sobjectType, String recordTypeName, String pickListFieldAPIName) {
        return parseOptions(
                            new Map<String, String> {
                                                     'sobjectType' => sobjectType,
                                                     'recordTypeName' => recordTypeName,
                                                     'pickListFieldName'=> pickListFieldAPIName
                                                    }
                            );
    }

    /**
        Describe a picklist field for a SobjectType, its given record type ID and the picklist field
        example usage :
        Id recType1Id = [Select Id from RecordType Where SobjectType = 'Account'
                                            AND DeveloperName like 'Record_Type_2'].Id;
        System.assertEquals(REC_TYPE_1_OPTIONS, PicklistDescriber.describe('Account', recType2Id, 'Industry'));
    */
    public static List<String> describe(String sobjectType, Id recordTypeId, String pickListFieldAPIName) {
        return parseOptions(
                            new Map<String, String> {
                                                     'sobjectType' => sobjectType,
                                                     'recordTypeId' => recordTypeId,
                                                     'pickListFieldName'=> pickListFieldAPIName
                                                    }
                            );
    }

    public static List<String> describe(String sobjectType, String recordTypeName, String pickListFieldAPIName, String contrfieldName) {
        return parseOptions(
                            new Map<String, String> {
                                                     'sobjectType' => sobjectType,
                                                     'recordTypeName' => recordTypeName,
                                                     'pickListFieldName'=> pickListFieldAPIName,
                                                     'contrfieldName' => contrfieldName
                                                    }
                            );
    }

    public static Map<String,List<String>> describeWithDependency(String sobjectType, String recordTypeName, String pickListFieldAPIName, String contrfieldName) {
        Map<String, List<String>> result = new Map<String,List<String>>();
        Map<String, List<String>> depentOptions = PicklistFieldController.getDependentOptionsImpl(sobjectType, contrfieldName, pickListFieldAPIName);
        for(String pickval : PicklistDescriber.describe(sobjectType, recordTypeName, pickListFieldAPIName, contrfieldName)) {
            for(String dep : depentOptions.keySet()) {
                result.put(dep, new List<String>());
                for(String val : depentOptions.get(dep)) {
                    if(val == pickval) {
                        result.get(dep).add(val);
                    }
                }
            }
        }

        return result;
    }

    public static Map<String,List<String>> describeWithDependency(String sobjectType, Id recordTypeId, String pickListFieldAPIName, String contrfieldName) {
        Map<String, List<String>> result = new Map<String,List<String>>();
        Map<String, List<String>> depentOptions = PicklistFieldController.getDependentOptionsImpl(sobjectType, contrfieldName, pickListFieldAPIName);
        for(String pickval : PicklistDescriber.describe(sobjectType, recordTypeId, pickListFieldAPIName)) {
            for(String dep : depentOptions.keySet()) {
                result.put(dep, new List<String>());
                for(String val : depentOptions.get(dep)) {
                        System.debug(val);
                        System.debug(pickval);
                    if(val == pickval) {
                        result.get(dep).add(val);
                    }
                }
            }
        }

        return result;
    }

    /*
        Internal method to parse the OPTIONS
    */
    static List<String> parseOptions(Map<String, String> params) {
        PageReference pr = Page.PicklistDesc;
        // to handle development mode, if ON
        pr.getParameters().put('core.apexpages.devmode.url', '1');

        for (String key : params.keySet()) {
            pr.getParameters().put(key, params.get(key));
        }

        String xmlContent = pr.getContent().toString();

        Matcher mchr = OPTION_PATTERN.matcher(xmlContent);
        List<String> options = new List<String>();
        while(mchr.find()) {
            System.debug(mchr.group(1));
            options.add(mchr.group(1));
        }
        // remove the --None-- element
        if (!options.isEmpty()) options.remove(0);
        return options;
    }
}
Hi 
Help me with test class


public with sharing class CancelPendingApprovalsOfLostDeals implements Database.Batchable<sObject> {

    public Database.QueryLocator start(Database.BatchableContext context) {
        return Database.getQueryLocator([SELECT Id, StageName FROM Opportunity WHERE StageName='Closed Lost']);
    }

    public void execute(Database.BatchableContext context, List<Opportunity> opportunities) {
        Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>();
        for (Opportunity opp: opportunities) {
            oppMap.put(opp.Id, opp);
        }

        OpportunityManagement.CancelApprovalsIfClosed(oppMap);
    }

    public void finish(Database.BatchableContext context){
                
    }
}

Thanks
Hi Everyone,
can you please provide test class for this class

global class ApprovalDelegationsSchedulable implements Schedulable {
    global void execute(SchedulableContext sc) {
        ApprovalDelegationsBatchable b = new ApprovalDelegationsBatchable();
        database.executebatch(b);
    }
}


Thanks you
Hi you help with code coverage,


public with sharing class AccountQuickCreateExt
{
    public AccountQuickCreateExt( QuickCreateController quickCreateCont )  //QuickCreateController  is abstact class
    {
        User currentUser = [ SELECT Default_Continent__c, DefaultCountry__c
                             FROM User WHERE Id = :UserInfo.getUserId() ];
        quickCreateCont.quickCreateObject.put( 'Continent__c', currentUser.Default_Continent__c );
        quickCreateCont.quickCreateObject.put( 'Country__c', currentUser.DefaultCountry__c );
    }
}
Hi Everyone,
Please help me with test class

​public class PicklistDescController {
    public Sobject sobj {get;set;}
    public String pickListFieldName {get;set;}
    public String contrfieldName {get; set;}

    public PicklistDescController() {
        Map<String, String> reqParams = ApexPages.currentPage().getParameters();
        String sobjId = reqParams.get('id');
        String recordTypeId = reqParams.get('recordTypeId');
        String recordTypeName = reqParams.get('recordTypeName');
        String sobjectTypeName = reqParams.get('sobjectType');
        this.pickListFieldName = reqParams.get('picklistFieldName');
        this.contrfieldName = (reqParams.get('contrfieldName') != null) ? reqParams.get('contrfieldName') : '';

        Schema.SobjectType sobjectType = null;

        if (sobjectTypeName != null && sobjectTypeName.trim().length() > 0) {
            sobjectType = Schema.getGlobalDescribe().get(sobjectTypeName);
            // create blank sobject record
            sobj = sobjectType.newSobject();

            // if no recordTypeId passed explicitly by user, try loading one from the RecordType table
            if (isBlank(recordTypeId) && !isBlank(recordTypeName)) {
                // queryexception is fine, we don't want to return anything good for bad recordtype
                RecordType recType = [Select Id from RecordType Where SobjectType =:sobjectTypeName
                                            AND DeveloperName like :recordTypeName];
                recordTypeid = recType.id;
            }
            sobj.put('RecordTypeId', recordTypeid);

        } else if (sobjId != null && sobjId.trim().length() > 0) {
            // find the so
            for (SobjectType sobjType : Schema.getGlobalDescribe().values()){
                String sobjPrefix = sobjType.getDescribe().getKeyPrefix();
                if (sobjPrefix == null) continue;
                System.debug('SobjectType ' + sobjType + ', ' + sobjPrefix);
                if (sobjId.toLowerCase().startsWith(sobjPrefix.toLowerCase())) {
                    sobjectType = sobjType;
                    break;
                }
            }
            // following not working with input:field
            //sobj = sobjectType.newSobject(sobjId);
            sobj = Database.query ('SELECT ' + pickListFieldName + ((contrfieldName != '') ? ', ' + contrfieldName : contrfieldName) + ' FROM ' + sobjectType + ' WHERE ID =:sobjId');
        }

    }

    static boolean isBlank(String val) {
        return val == null || val.trim().length() == 0;
    }
}
Hi Everyone,
I am new to salesforce, can you please provide test class for this class

public without sharing class UtilityClassWithoutSharing {
  static final String ERROR_MSG = 'The Opportunity you have chosen does not meet all Opportunity Validation rules.  Please update the opportunity and then re-assocaite it with the Deal.';
  
  //Method used in Deal Trigger.
  public static void updateOpp(map<id,id> oppIdDealIdMap, List<Deal__c> newDeals){
    
    list<Opportunity> opps = [select id,Deal__c from Opportunity where id in:oppIdDealIdMap.keySet()];
    list<Opportunity> oppsToUpdate = new list<Opportunity>();
    
    if(opps!=null && opps.size()>0){
      for(Opportunity opp:opps){
        if(opp.Deal__c != oppIdDealIdMap.get(opp.id)){
          opp.Deal__c = oppIdDealIdMap.get(opp.id);
          oppsToUpdate.add(opp);
        }
      }
    }
    
    // for handeling proper error messages
    //modified by Manmeet on 19th Dec 2012 for T-104876
    if(oppsToUpdate!=null && oppsToUpdate.size()>0){
      Database.SaveResult[] results = Database.update(oppsToUpdate,false);
      System.debug('MPK: '+results);
      Map<Id,String> mapErrors = new Map<Id,String>();
      for(Integer index = 0 ; index < results.size(); index++){
          Database.SaveResult result = results.get(index);
          Opportunity oppty = oppsToUpdate.get(index);
          if(!result.isSuccess() && String.valueOf(result.getErrors()[0].getStatusCode()).contains('FIELD_CUSTOM_VALIDATION_EXCEPTION')){
              mapErrors.put(oppty.Deal__c,ERROR_MSG);
          }
      }
      for(Deal__c deal  : newDeals){
          if(mapErrors.containsKey(deal.id)){
              deal.addError(mapErrors.get(deal.id));
          }
      }
    }
  }
  
  //Method used in Deal Trigger.
  public static void updateOppToRemoveDealId(list<id> oppIdDealIdMap){
    
    list<Opportunity> opps = [select id,Deal__c from Opportunity where Deal__c in:oppIdDealIdMap];
    list<Opportunity> oppsToUpdate = new list<Opportunity>();
    
    if(opps!=null && opps.size()>0){
      for(Opportunity opp:opps){
          opp.Deal__c = null;
          oppsToUpdate.add(opp);
        
      }
    }
    
    if(oppsToUpdate!=null && oppsToUpdate.size()>0){
      update oppsToUpdate;
    }
  }
}


Thanks
Hi
Can anyone help me with test class

global class CreateTaskOnContactFromEmail implements Messaging.InboundEmailHandler {
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){
        
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        String myPlainText= '';
        string sub = '';
        List<Attachment> attachments = new List<Attachment>();
        String docUrl = '';
        
       
        myPlainText = email.plainTextBody;
        sub = email.subject;
       
        
        sub.contains('ref:');
        Task newTask = new Task();
        Account vAcc = new Account();
        EmailMessage  emailMsg = new EmailMessage();
               try {
            vAcc = [SELECT Id, Name, PersonEmail,OwnerId,Owner.Name FROM Account WHERE PersonEmail =:email.fromAddress AND IsPersonAccount = True
                    LIMIT 1]; 
            Contact vCon = [SELECT Id, Name, Email FROM Contact WHERE Email = :email.fromAddress LIMIT 1];
            
            if(vAcc.id != NULL){
                
                Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                message.toAddresses = new String[]{vAcc.OwnerId};
                    message.subject = 'Task is Created for your Account';
                String emailBody = 'Hi'+' '+vAcc.Owner.Name+'\n'+'A new Task is created for your Account'+' '+vAcc.Name;
                message.plainTextBody = emailBody;
                Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{message});
                
                
                if(email.textAttachments != null)
                {
                    for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
                        
                        String body = tAttachment.body;
                        Blob b = blob.valueOf(tAttachment.body);
                        String str = EncodingUtil.base64Encode(b);
                        
                        ContentVersion conVer = new ContentVersion();
                        conVer.VersionData = EncodingUtil.base64Decode(str);
                        conVer.Title = tAttachment.fileName;
                        conVer.ContentLocation = 'S'; 
                        conVer.PathOnClient = tAttachment.fileName;
                        insert conVer;
                        
                        conVer = [select ContentDocumentId from ContentVersion where id = :conVer.id limit 1];
                        
                        ContentDocumentLink cdl = new ContentDocumentLink();
                        cdl.LinkedEntityId = vAcc.id;
                        cdl.ContentDocumentId = conVer.ContentDocumentId;
                        cdl.ShareType = 'I'; 
                        cdl.Visibility = 'InternalUsers';
                        insert cdl; 
                        
                        
                        docUrl += tAttachment.fileName + '\n';
                    }
                }
                if(email.binaryAttachments != null)
                {
                    for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
                        ContentVersion conVer = new ContentVersion();
                        conVer.VersionData = bAttachment.body;
                        conVer.Title = bAttachment.fileName;
                        conVer.ContentLocation = 'S'; 
                        conVer.PathOnClient = bAttachment.fileName;
                        insert conVer;
                        
                        conVer = [select ContentDocumentId from ContentVersion where id = :conVer.id limit 1];
                        
                        ContentDocumentLink cdl = new ContentDocumentLink();
                        cdl.LinkedEntityId = vAcc.id;
                        cdl.ContentDocumentId = conVer.ContentDocumentId;
                        cdl.ShareType = 'I'; 
                        cdl.Visibility = 'InternalUsers';
                        insert cdl;
                        docUrl += bAttachment.fileName + '\n';
                    }
                }
                if(attachments.size() > 0){insert attachments;
                                           system.debug(attachments[0]);}
                
                
                emailMsg.RelatedToId =vAcc.Id;
                emailMsg.TextBody = email.plainTextBody;
                emailMsg.Subject = email.subject;
                emailMsg.FromAddress = email.fromAddress;
                emailMsg.Status = '2';
                emailMsg.Incoming= True;
                emailMsg.Attachment__c = docUrl;
                insert emailMsg;
                
            }
        }catch (QueryException e) {
            UTIL_LoggingService.logHandledException(e, UserInfo.getOrganizationId(),UserInfo.getOrganizationName(),'CreateTaskOnContactFromEmail',
                                                    'handleInboundEmail','', system.LoggingLevel.FINEST); 
        }
        
       
        result.success = true;
        return result;
    }
}

Thanks
public class ContactpQueueable implements Queueable {
    public List<Contact> conToInsert = new List<Contact>();
    public List<Contact> conToDeleteList = new List<Contact>();
    
    
    public void execute(QueueableContext context) {
        if(!conToInsert.isEmpty()){
            Database.insert(conToInsert );
        }
        if(!conDeleteList.isEmpty()){
            Database.delete(conToDeleteList);
        }
    }
}
hi all,

I urgently need to edit/delete a post made by me on this discussion forum...But its not allowing me to do so and pops up
saying that 'you cant delete this question as others are interested in it'.
There are no likes and no comments on it still i am unable  to delete it
Any help would be highly appreciated

Its very urgent,
Thanks,