• Sai Ram 118
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 9
    Replies
Hi
Help me with test class

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;
        }
    }
}
Can any onecan help me with test class

public with sharing class OpportunityQuickCreateExt
{
    public OpportunityQuickCreateExt( QuickCreateController quickCreateCont )
    {
        User currentUser = [ SELECT Default_Continent__c, Default_Market__c, Default_Region__c
                             FROM User WHERE Id = :UserInfo.getUserId() ];
        quickCreateCont.quickCreateObject.put( 'Name', 'Dummy Name' );
        quickCreateCont.quickCreateObject.put( 'StageName', 'E Qualify / Suspect-No RFP' );
        quickCreateCont.quickCreateObject.put( 'Continent__c', currentUser.Default_Continent__c );
        
        if( !String.isEmpty( currentUser.Default_Region__c ) )
        {
            List<Region__c> defaultRegion = [SELECT Id FROM Region__c WHERE Name = :currentUser.Default_Region__c LIMIT 1 ];
            quickCreateCont.quickCreateObject.put( 'Region__c', defaultRegion.isEmpty() ? NULL : defaultRegion[0].Id );
        }
        if( !String.isEmpty( currentUser.Default_Market__c ) )
        {
            List<Market__c> defaultMarket = [SELECT Id FROM Market__c WHERE Name = :currentUser.Default_Market__c LIMIT 1 ];
            quickCreateCont.quickCreateObject.put( 'Market__c', defaultMarket.isEmpty() ? NULL : defaultMarket[0].Id );
        }
    }
}
Can you please help me with this

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;
    }
}

Thanks
Hi 

require help in class 

global class CDPForecastExtractBatch implements Database.Batchable<sObject> {
    
    String query;
    Forecast_Scenario__c forecastScenario;
    
    global CDPForecastExtractBatch(Forecast_Scenario__c scenario) {
        forecastScenario = scenario;
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        query = 'SELECT Id, Deal__c, Deal__r.Parent_Deal_Id__c, Deal__r.Stage__c, Deal__r.IsPlaceholder_Deal__c, Deal__r.IsInfrastructure_Deal__c, Deal__r.RecordType.Name, Deal__r.Is_Cloned_Deal__c, Deal__r.Is_Closed_Deal__c, Deal__r.Forecast_Scenario__c, ';
        query += '(SELECT Id, CDP_Asset__c, Customer__c, Customer__r.Name,Customer__r.Account_Subtype__c FROM CDP_Asset_Customer_Accounts__r) , ';
        query += '(SELECT Id, Development_Deal_Id__c, Land_Name__c, CDP_Asset__c, Land_Area__c, Land_Area_UOM__c, Land_Source__c, Land_Code__c FROM CDP_Land_Strategy__r) '; 
        query += 'FROM CDP_Asset__c WHERE (NOT Deal__r.Stage__c like \'%Lost%\')  AND (Deal__r.Is_Cloned_Deal__c = true OR (Deal__r.Stage__c like \'%Won%\') ) ';
        query += 'AND Deal__r.Hold__c = false AND (Deal__r.IsNamedDeal__c = true OR Deal__r.IsPlaceholder_Deal__c = true OR Deal__r.IsInfrastructure_Deal__c = true OR (Deal__r.Stage__c like \'%Won%\') ) ';
           query += 'AND Deal__r.RecordType.Name NOT IN ('+ '\'Value-Add\'' +')';
        return Database.getQueryLocator(query);
    }

       global void execute(Database.BatchableContext BC, List<sObject> scope) {
        CDPForecastExtractHandler.getChildRecords(scope, forecastScenario);
    }
    
    global void finish(Database.BatchableContext BC) {
        
    }
    
}
Hi EveryOne,
Test class Help


global with sharing class LeaseApproval_SendNotification {
    
    public ID leaseAnalysisId    {get;set;}
    public Opportunity opp         {get;set;}
    public Lease_Analysis__c la {get;set;}
    public List<ID> scenarioIds {get;set;}

    public String richComments        {get;set;}

    public LeaseApproval_SendNotification() {
        
    }

    
    
    @RemoteAction
    global static ResultMessage sendNotification(List<String> toEmails, List<String> ccEmails, List<String> bccEmails, String comments, String oppName, String oppId, List<ID> scenarios){
        try{
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            //TODO create the notification record and junction objects
            if(toEmails.size()>0)
            mail.setToAddresses(toEmails);
            if(ccEmails.size()>0)
            mail.setCcAddresses(ccEmails);
            if(bccEmails.size()>0)
            mail.setBccAddresses(bccEmails);

            Messaging.reserveSingleEmailCapacity(1);

            String body = comments;

            String leaseAnalysisLink='<a href="'+URL.getSalesforceBaseUrl().toExternalForm()+'/apex/LeaseAnalysis?opportunityId='+oppId+'">Lease Analysis - '+oppName+'</a><br/>';

            mail.setHTMLBody('You have been notified about a deal ('+leaseAnalysisLink+') from '+userInfo.getFirstName() + ' ' + userInfo.getLastName() +'.  No action is required. \r\n' + body);

            mail.setSubject('NOTIFICATION ALERT from '+userInfo.getFirstName() + ' ' + userInfo.getLastName()+' – '+ oppName);

            //TODO - make for loop over scenario ids to create a pdf per scenario
            PageReference pr = page.LeaseApproval_Notification;

            Blob attachmentBody = pr.getContentAsPDF();
            
            Messaging.EmailFileAttachment att = new Messaging.EmailFileAttachment();
            att.setBody(attachmentBody);
            att.setFileName('Scenario Attachment.pdf');

            mail.setFileAttachments(new List<Messaging.EmailFileAttachment>{att});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            return new ResultMessage(true, 'successfully sent');
        }
        catch(Exception e){
            return new ResultMessage(false, e.getMessage() +  '\n ' + e.getStackTraceString());
        }
        return null;
    }
}
Hi,
I written test class and i am getting 55%. Can any one help me
Class:

public class OV_BAUtility {
     public static List<String> accountList{get;set;}
     public static Map<id,Account> accMap{get;set;}
   
     public static String getAcctIds(String id){  
        system.debug('-----------******-----------------'+id);
        return quoteId(getAccountIds(id));        
    }
     public static list<id> getAccountIds(String Id){
        if(accMap == null){
            accMap= new Map<id,Account>([SELECT id,ParentId,Name from Account where ParentId=:Id]);
        }
        system.debug('Size of map :'+accMap.size());
        accountList = new List<String>();
        accountList.add(Id);
        for(Account acc : accMap.values()){
            if(acc.ParentId == Id){
                //accMap.remove(acc.id);
                accountList.add(acc.id);
                getChildAccount(acc.id,accountList);
            }
        }
        system.debug('FinalList'+accountList);
        return accountList;
    }
    private static void getChildAccount(Id parentId,List<ID> accountList){
        for(Account acc : accMap.values()){
            if(parentId == acc.ParentId){
                //    accMap.remove(acc.id);
                accountList.add(acc.id);
                getChildAccount(acc.id,accountList);
            }
        }
    }
    private static void getParentAccount(Id parentId,List<ID> accountList){
        for(Account acc : accMap.values()){
            if(parentId == acc.id){
                //      accMap.remove(acc.id);
                accountList.add(acc.id);
                if(acc.ParentId != null)
                    getParentAccount(acc.ParentId,accountList);
            }
        }
    }
    private static String quoteId(List<String> ids){
        String idStr = '' ;
        for(String str : ids)
            idStr += '\'' + str + '\',';
        
        idStr = idStr.lastIndexOf(',') > 0 ? '(' + idStr.substring(0,idStr.lastIndexOf(',')) + ')' : idStr ;
        System.debug('quoteId() :  idStr =*************===== ' + idStr);   
        return idStr;
    }
}
Test Class:

@isTest
private class OV_BADashBoardTest {
    
        Id recTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('xyz').getRecordTypeId();
    
        static testMethod void getTotalCountTest(){
            
        Id recTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('xyz').getRecordTypeId();
        Account acc=new Account();
        acc.Name = Datetime.now() + '' + math.random();
        acc.BillingCity = 'Indore';
        acc.BillingCountry = 'India';
        acc.OriginalAccountName__c = 'xyz';
        acc.TradestyleName__c = '';
        acc.Continent__c = 'Asia';
        acc.BillingState = 'MP';
        acc.RecordTypeId = recTypeId;
       // acc.ParentId=;
        insert acc;
        OV_BADashBoard.getToatlCount(acc.Id, acc.Continent__c);
       
    }

}

Thanks
Can any onecan help me with test class

public with sharing class OpportunityQuickCreateExt
{
    public OpportunityQuickCreateExt( QuickCreateController quickCreateCont )
    {
        User currentUser = [ SELECT Default_Continent__c, Default_Market__c, Default_Region__c
                             FROM User WHERE Id = :UserInfo.getUserId() ];
        quickCreateCont.quickCreateObject.put( 'Name', 'Dummy Name' );
        quickCreateCont.quickCreateObject.put( 'StageName', 'E Qualify / Suspect-No RFP' );
        quickCreateCont.quickCreateObject.put( 'Continent__c', currentUser.Default_Continent__c );
        
        if( !String.isEmpty( currentUser.Default_Region__c ) )
        {
            List<Region__c> defaultRegion = [SELECT Id FROM Region__c WHERE Name = :currentUser.Default_Region__c LIMIT 1 ];
            quickCreateCont.quickCreateObject.put( 'Region__c', defaultRegion.isEmpty() ? NULL : defaultRegion[0].Id );
        }
        if( !String.isEmpty( currentUser.Default_Market__c ) )
        {
            List<Market__c> defaultMarket = [SELECT Id FROM Market__c WHERE Name = :currentUser.Default_Market__c LIMIT 1 ];
            quickCreateCont.quickCreateObject.put( 'Market__c', defaultMarket.isEmpty() ? NULL : defaultMarket[0].Id );
        }
    }
}
Hi EveryOne,
Test class Help


global with sharing class LeaseApproval_SendNotification {
    
    public ID leaseAnalysisId    {get;set;}
    public Opportunity opp         {get;set;}
    public Lease_Analysis__c la {get;set;}
    public List<ID> scenarioIds {get;set;}

    public String richComments        {get;set;}

    public LeaseApproval_SendNotification() {
        
    }

    
    
    @RemoteAction
    global static ResultMessage sendNotification(List<String> toEmails, List<String> ccEmails, List<String> bccEmails, String comments, String oppName, String oppId, List<ID> scenarios){
        try{
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            //TODO create the notification record and junction objects
            if(toEmails.size()>0)
            mail.setToAddresses(toEmails);
            if(ccEmails.size()>0)
            mail.setCcAddresses(ccEmails);
            if(bccEmails.size()>0)
            mail.setBccAddresses(bccEmails);

            Messaging.reserveSingleEmailCapacity(1);

            String body = comments;

            String leaseAnalysisLink='<a href="'+URL.getSalesforceBaseUrl().toExternalForm()+'/apex/LeaseAnalysis?opportunityId='+oppId+'">Lease Analysis - '+oppName+'</a><br/>';

            mail.setHTMLBody('You have been notified about a deal ('+leaseAnalysisLink+') from '+userInfo.getFirstName() + ' ' + userInfo.getLastName() +'.  No action is required. \r\n' + body);

            mail.setSubject('NOTIFICATION ALERT from '+userInfo.getFirstName() + ' ' + userInfo.getLastName()+' – '+ oppName);

            //TODO - make for loop over scenario ids to create a pdf per scenario
            PageReference pr = page.LeaseApproval_Notification;

            Blob attachmentBody = pr.getContentAsPDF();
            
            Messaging.EmailFileAttachment att = new Messaging.EmailFileAttachment();
            att.setBody(attachmentBody);
            att.setFileName('Scenario Attachment.pdf');

            mail.setFileAttachments(new List<Messaging.EmailFileAttachment>{att});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            return new ResultMessage(true, 'successfully sent');
        }
        catch(Exception e){
            return new ResultMessage(false, e.getMessage() +  '\n ' + e.getStackTraceString());
        }
        return null;
    }
}
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,