• sfdc18
  • NEWBIE
  • 40 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 65
    Questions
  • 64
    Replies
Hi,

I am getting below error on visualforce page for find query.
Please suggest the changes which I need to make in order to work with below code.

Error -- Content cannot be displayed: line 1:118 no viable alternative at character '\'


String parentIdWhereClause = parentCaseId != null ?  'AND Id <> \''+ parentCaseId +'\'': '';

string casesubjectSearch = caseSubject.replace(' ', ' OR ');

string sosl = 'FIND :casesubjectSearch IN ALL FIELDS RETURNING Case(id,CaseNumber, Subject where RecordTypeId =:recordtype '+String.escapeSingleQuotes(parentIdWhereClause)+' ORDER BY LastModifiedDate DESC) LIMIT 100';
List<List<case>> searchList = search.query(sosl);
  • April 25, 2017
  • Like
  • 0
Hi,

I am getting error for list remove() method.

Error :
Compile Error: Method does not exist or incorrect signature: [List<Services_and_Equipment__c>].remove(Services_and_Equipment__c)


I am comparing two lists. Based on some condition adding the values in new list.
I want to then remove these values from older list (the values which are added to new list).
Below is the code.
for(Services_and_Equipment__c varAdd : lst_Add_SE) {
    for(Services_and_Equipment__c varDisc : lst_Disconnect_SE) {
       if(varAdd.Services_and_Equipment_Name__r.Service_Type__c 
          ==  varDisc.Services_and_Equipment_Name__r.Service_Type__c) {
                     lst_AddDisconnect_SE.add(varAdd); 
                     lst_AddDisconnect_SE.add(varDisc); 
                     lst_Complex_SE.remove(varAdd);  
                     lst_Disconnect_SE.remove(varDisc);
       }                        
    }     
}
Thanks.

 
Hi,

My test class is not covering code inside if loop highlighted below. The If loop is checking count from Wrapper object.
How should I cover the code inside if loop highlighted below.

Apex Class

public class ABC{

Map<Id, List<Services_and_Equipment__c>> mapInstallation2lst_SE = getSErviceEquipmentsInScopeByProduct(pSet_InstallationIds);

if(InstalltionTypeObj.ApprovedSE_Count == mapInstallation2lst_SE.get(InstallationId).size()){

}


    public class InstallationType{
        public Boolean IsMACD;            // If Installation has any S&E with Macd Type 'Move - Add', 'Move - Disconnect', Upgrade, Downgrade Disconnect than it will be true
        public Integer TotalSE_Count;     // Total S&E records for Installation
        public Integer SimpleSE_Count;    // Total S&E records Where Type of Work is Simple
        public Integer ComplexSE_Count;   // Total S&E records Where Type of Work is Complex
        public Integer ApprovedSE_Count;  // Total S&E records Where Stage is Coordinator Approved or Penidng Disconnect
        public Integer MoveAdd_Count;     // Total S&E records Where Stage is Move - Add
        public Integer Add_Count;         // Total S&E records Where Stage is Add
        public InstallationType(){
            IsMACD = false;
            TotalSE_Count = 0;
            SimpleSE_Count = 0;
            ComplexSE_Count = 0;
            ApprovedSE_Count = 0;
            MoveAdd_Count = 0;
        }
    }

}

Thanks

Hi,

I need a help in test coverage for a controller having wrapper class. Currently it is covering only 60% of code.

Apex Controller :

User-added image
User-added image
User-added image
User-added image
User-added image

Test Class :
 

@isTest(SeeAllData = true) 
public class CopyAttachmentControllerTest {

private  static  RecordType supportCaseRecordType  = [SELECT Name, Id FROM RecordType 
                                                        WHERE Name ='Support Case' 
                                                        AND SObjectType = 'Case'];
                                                        
private  static  RecordType L2CaseRecordType  = [SELECT Name, Id FROM RecordType 
                                                        WHERE Name ='L2 Case' 
                                                        AND SObjectType = 'Case'];

    static testmethod void CopyAttachmentTestCase(){
        Account   testAccount = new Account();
        testAccount.Name  = 'test';
    
        insert testAccount;
    
        Contact   testContact = new Contact();
        testContact.LastName  = 'Test Name';
        testContact.AccountId = testAccount.Id;
    
        insert testContact;

        Product2  testProduct = new Product2();
        testProduct.Id                    = null;
        testProduct.Name                  = 'Test Product Name';
        testProduct.Product_Category__c   = 'Category';
        testProduct.Product_Family__c     = 'Family';
        testProduct.Product_Sub_family__c = 'Sub-Family';    

        insert testProduct;
    
        Case  testCase  = new Case();
        testCase.RecordTypeId = supportCaseRecordType.Id;
        testCase.Summary__c   = 'Summary';
        testCase.Description  = 'Description';
        testCase.Origin       = 'Email';
        testCase.Status       = 'New';
        testCase.I_Agree__c   = true;
        testCase.ContactId    = testContact.Id;
        testCase.ProductId    = testProduct.Id;

        insert testCase;
        
        Case  testCase2  = new Case();
        testCase2.RecordTypeId = L2CaseRecordType.Id;
        testCase2.Summary__c   = 'Summary2';
        testCase2.Description  = 'Description2';
        testCase2.Origin       = 'Email2';
        testCase2.Status       = 'New2';
        testCase2.I_Agree__c   = true;
        testCase2.ContactId    = testContact.Id;
        testCase2.ProductId    = testProduct.Id;

        insert testCase2;


        Attachment att = new Attachment();
        att.ParentId = testCase.Id;
        att.name = 'test'; 
        att.body = blob.valueof('test');
        
        insert att;

        Attachment attDup = new Attachment();
        attDup.ParentId = testCase2.Id;
        attDup.name = att.name; 
        attDup.body = att.body;
        
        List<Attachment> listatt = new List<Attachment>();
        listatt.add(attDup);
        insert listatt;
        System.assertEquals(1, listatt.size());
        
        Id idSelected;
        ApexPages.StandardController sc = new ApexPages.standardController(testCase);
        CopyAttachmentController cls = new CopyAttachmentController(sc);
                cls.Cancel();
        cls.selectall = true;
        cls.displayAttTable = true;
        cls.matchingAttTable = true;        
        CopyAttachmentController.AttachmentWrapper innerClass = new CopyAttachmentController.AttachmentWrapper(att);
        innerClass.selected = true;
        innerClass.att = att;
        List<CopyAttachmentController.AttachmentWrapper> attList = new List<CopyAttachmentController.AttachmentWrapper>();
        //attList = null;
        system.currentPageReference().getParameters().put('idSelected', testCase.Id);
        System.assert(testCase.Id != null);
        
        List<CopyAttachmentController.AttachmentWrapper> listInnerClass = new List<CopyAttachmentController.AttachmentWrapper>();
        listInnerClass.add(new CopyAttachmentController.AttachmentWrapper(attDup));
        //List<string> s = new List<string>();
        //s.add(att.name);
        //cls.matchingFiles = s;        
        cls.SelectAttachments();
        //System.assert(cls.matchingFiles.size()>0); 

    }
}
Thanks
  • December 10, 2015
  • Like
  • 0
Hi,

I am getting below error when I try to attach files in attachment object.
But problem is this error is not occuring continuously.
Sometimes I successfully attach files in attachment object. Sometimes I get this error on insert statement :  insert l2AttList;

User-added image\
Apex Class :
public with sharing class CopyAttachmentsController {

    public Set<string> supportCaseIds = new Set<string>();
    ID l2CaseId; 
    public List<AttachmentWrapper> attList {get; set;}
    public Boolean allChecked { get; set; }
    
    public CopyAttachmentsController(ApexPages.StandardController controller)
    {
        supportCaseIds.add(ApexPages.CurrentPage().getParameters().get('parentId'));
        system.debug('-----------supportCaseIds------------'+supportCaseIds);

        l2CaseId = ApexPages.CurrentPage().getParameters().get('Id');
        system.debug('-----------l2CaseId------------'+l2CaseId);
        
        allChecked = false;
    }
    
    public PageReference CheckAll(){
        for(AttachmentWrapper at : attList){
            at.selected = allChecked;
        }
        return null;
    }

    public List<AttachmentWrapper> getAttachments() {
        if(attList == null) {
            attList = new List<AttachmentWrapper>();
            for(Attachment a: [Select Id, Name, Body, ContentType, ParentId from Attachment Where ParentId in : supportCaseIds]) {
                attList.add(new AttachmentWrapper(a));
            }
        }
        return attList;
    }
 
    public PageReference SelectAttachments() {

        List<Attachment> selectedAttachments = new List<Attachment>();

        for(AttachmentWrapper attach : getAttachments()) {
            if(attach.selected == true) {
                selectedAttachments.add(attach.att);
            }
        }
        List<Attachment> l2AttList = new List<Attachment>();
        for(Attachment selectedAtt : selectedAttachments)
        {
            Attachment attForL2Case = New Attachment();
            IF(selectedAtt != null && selectedAtt.body != null)
            {
            attForL2Case.Name = selectedAtt.Name;
            attForL2Case.Body = selectedAtt.Body;
            attForL2Case.contentType = selectedAtt.contentType;
            attForL2Case.ParentId = ApexPages.CurrentPage().getParameters().get('Id');
            }
            l2AttList.add(attForL2Case);
        }
        /*
        if (Limits.getHeapSize() > Limits.getLimitHeapSize()) { 
            ApexPages.Message errMsg = new  ApexPages.Message(ApexPages.Severity.ERROR,'Attachments limit exceeded : Please deselect few attachments and try again');
            ApexPages.addMessage(errMsg); 
            return null;
        }
        */
        //try 
        //{
        If(l2AttList.size() > 0)
        {
            insert l2AttList;
        }
        //}
        //catch(Exception e)
        //{
            //system.debug('--------exception--------'+e);
        //}

        attList=null;

        PageReference pageReference = new PageReference('/'+l2CaseId);
        pageReference.setRedirect(true);
        return pageReference;
    }

    public class AttachmentWrapper {
        public Attachment att {get; set;}
        public Boolean selected {get; set;}

        public AttachmentWrapper(Attachment a) {
            att = a;
            selected = false;
        }
    }
}
Thanks.
 
  • October 12, 2015
  • Like
  • 0
Hi,
I am getting 70% code coverage. How can I improve my code coverage above 75%.
 
Apex Class:

public with sharing class CopyAttachmentsController {

    public Set<string> supportCaseIds = new Set<string>();
    ID l2CaseId; 
    public List<AttachmentWrapper> attList {get; set;}
    
    public CopyAttachmentsController(ApexPages.StandardController controller)
    {
        supportCaseIds.add(ApexPages.CurrentPage().getParameters().get('parentId'));
        system.debug('-----------supportCaseIds------------'+supportCaseIds);

        l2CaseId = ApexPages.CurrentPage().getParameters().get('Id');
        system.debug('-----------l2CaseId------------'+l2CaseId);
    }

    public List<AttachmentWrapper> getAttachments() {
        if(attList == null) {
            attList = new List<AttachmentWrapper>();
            for(Attachment a: [Select Id, Name, Body, ParentId from Attachment Where ParentId in : supportCaseIds]) {
                attList.add(new AttachmentWrapper(a));
            }
        }
        return attList;
    }
 
    public PageReference processSelected() {

        List<Attachment> selectedAttachments = new List<Attachment>();

        for(AttachmentWrapper attach : getAttachments()) {
            if(attach.selected == true) {
                selectedAttachments.add(attach.att);
            }
        }
        List<Attachment> l2AttList = new List<Attachment>();
        for(Attachment attForL2 : selectedAttachments)
        {
            Attachment attForL2Case = New Attachment(Name = attForL2.Name, Body = attForL2.Body);
            attForL2Case.ParentId = ApexPages.CurrentPage().getParameters().get('Id');
            l2AttList.add(attForL2Case);
        }
        
        if (Limits.getHeapSize() > Limits.getLimitHeapSize()) { 
            ApexPages.Message errMsg = new  ApexPages.Message(ApexPages.Severity.ERROR,'Attachments limit exceeded : Please deselect few attachments and try again');
            ApexPages.addMessage(errMsg); 
            return null;
        }
        
        If(l2AttList.size() > 0)
        {
            insert l2AttList;
        }

        attList=null;

        PageReference pageReference = new PageReference('/'+l2CaseId);
        pageReference.setRedirect(true);
        return pageReference;
    }

    public class AttachmentWrapper {
        public Attachment att {get; set;}
        public Boolean selected {get; set;}

        public AttachmentWrapper(Attachment a) {
            att = a;
            selected = false;
        }
    }
}

Test Class :

@isTest
public class CopyAttachmentsControllerTest {

private  static  RecordType supportCaseRecordType  = [SELECT Name, Id FROM RecordType 
                                                        WHERE Name ='Support Case' 
                                                        AND SObjectType = 'Case'];
                                                        
private  static  RecordType L2CaseRecordType  = [SELECT Name, Id FROM RecordType 
                                                        WHERE Name ='L2 Case' 
                                                        AND SObjectType = 'Case'];

    static testmethod void CopyAttachmentTestCase(){
        Account   testAccount = new Account();
        testAccount.Name  = 'Test Acc';
    
        insert testAccount;
    
        Contact   testContact = new Contact();
        testContact.LastName  = 'Test Name';
        testContact.AccountId = testAccount.Id;
    
        insert testContact;

        Product2  testProduct = new Product2();
        testProduct.Id                    = null;
        testProduct.Name                  = 'Test Product Name';
        testProduct.Product_Category__c   = 'Category';
        testProduct.Product_Family__c     = 'Family';
        testProduct.Product_Sub_family__c = 'Sub-Family';    

        insert testProduct;
    
        Case  testCase  = new Case();
        testCase.RecordTypeId = supportCaseRecordType.Id;
        testCase.Summary__c   = 'Summary';
        testCase.Description  = 'Description';
        testCase.Origin       = 'Email';
        testCase.Status       = 'New';
        testCase.I_Agree__c   = true;
        testCase.ContactId    = testContact.Id;
        testCase.ProductId    = testProduct.Id;

        insert testCase;
        
        Case  testCase2  = new Case();
        testCase2.RecordTypeId = L2CaseRecordType.Id;
        testCase2.Summary__c   = 'Summary2';
        testCase2.Description  = 'Description2';
        testCase2.Origin       = 'Email2';
        testCase2.Status       = 'New2';
        testCase2.I_Agree__c   = true;
        testCase2.ContactId    = testContact.Id;
        testCase2.ProductId    = testProduct.Id;

        insert testCase2;


        Attachment att = new Attachment();
        att.ParentId = testCase.Id;
        att.name = 'test'; 
        att.body = blob.valueof('test');
        
        insert att;

        Attachment attDup = new Attachment();
        attDup.ParentId = testCase2.Id;
        attDup.name = att.name; 
        attDup.body = att.body;
        
        List<Attachment> listatt = new List<Attachment>();
        listatt.add(attDup);
        insert listatt;
        System.assertEquals(1, listatt.size());
        
        Id idRadio;
        ApexPages.StandardController sc = new ApexPages.standardController(testCase);
        CopyAttachmentsController cls = new CopyAttachmentsController(sc);
        cls.processSelected();
        CopyAttachmentsController.AttachmentWrapper innerClass = new CopyAttachmentsController.AttachmentWrapper(att);
        innerClass.selected = true;
        innerClass.att = att;
        system.currentPageReference().getParameters().put('idRadio', testCase.Id);
        System.assert( testCase.Id != null );
        
        List<CopyAttachmentsController.AttachmentWrapper> listInnerClass = new List<CopyAttachmentsController.AttachmentWrapper>();
        listInnerClass.add(new CopyAttachmentsController.AttachmentWrapper(attDup));
        
        ApexPages.Message[] pageMessages = ApexPages.getMessages();
        //System.assertNotEquals(0, pageMessages.size());
        
        Boolean messageFound = false;
        
        for(ApexPages.Message message : pageMessages) {
        if(message.getSummary() == 'Attachment size limit exceeded - please select less no of attachments'
        && message.getDetail() == 'Attachment size limit exceeded - please select less no of attachments'
        && message.getSeverity() == ApexPages.Severity.ERROR) {
        messageFound = true;        
        }
        }
        
        //System.assert(messageFound);
    }
}

 
  • October 06, 2015
  • Like
  • 0
Hi,

My class compares old and new values of records in one of the for loops.
I am getting only 17% code coverage for the class. Below is my apex class and test class.


Apex Class :
 
public class nmPGAllSemFee
{   
    public string query{get;set;}
    public void createNextSemOpportunityOnClosedWonForFullFee(List<Opportunity> triggerNew, map<id, Opportunity> oldMap)
    {
        List<Opportunity> opptyListToInsert = new List<Opportunity>();
        List<nm_Payment__c> paymentListToInsert = new List<nm_Payment__c>();
        
        for(Opportunity newOpportunity : triggerNew)
        {
            Id opptyId = newOpportunity.Id;
            
            
            Opportunity oldOpportunity =  oldMap.get(opptyId);
            System.debug('!!!!!newOpportunity!!!' + newOpportunity);
            if(newOpportunity.nm_Fee_Type__c == 'PGAllSemFee' && 
                newOpportunity.nm_Future_Sems_Created__c == false && 
                newOpportunity.StageName != oldOpportunity.StageName &&  
                newOpportunity.StageName == 'Closed Won'){
                
                opptyListToInsert = new List<Opportunity>();
                newOpportunity.nm_Future_Sems_Created__c = true;
                Opportunity sem2Opp = getNextSemOpportunity(newOpportunity);
                Opportunity sem3Opp = getNextSemOpportunity(sem2Opp);
                Opportunity sem4Opp = getNextSemOpportunity(sem3Opp);
                
                opptyListToInsert.add(sem2Opp);
                opptyListToInsert.add(sem3Opp);
                opptyListToInsert.add(sem4Opp);
                
                insert opptyListToInsert;
                system.debug('!!!!!opptyListToInsert!!!!!!'+opptyListToInsert);
                nm_Payment__c existingPaymentObj = getPaymentForOpportunity(newOpportunity.Id);
                
                nm_Payment__c sem2Payment = existingPaymentObj.clone();
                sem2Payment.nm_OpportunityNew__c = sem2Opp.Id;
                nm_Payment__c sem3Payment = existingPaymentObj.clone();
                sem3Payment.nm_OpportunityNew__c = sem3Opp.Id;
                nm_Payment__c sem4Payment = existingPaymentObj.clone();
                sem4Payment.nm_OpportunityNew__c = sem4Opp.Id;

                paymentListToInsert.add(sem2Payment);
                paymentListToInsert.add(sem3Payment);
                paymentListToInsert.add(sem4Payment);
                
                insert paymentListToInsert;
                
            }
            
        }
        
        }

    public nm_Payment__c getPaymentForOpportunity(Id id){
            List<nm_Payment__c> paymentList = new List<nm_Payment__c>();
            String SobjectApiName = 'nm_Payment__c';
            Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
 
            String commaSepratedFields = '';
            for(String fieldName : fieldMap.keyset()){
                if(commaSepratedFields == null || commaSepratedFields == ''){
                    commaSepratedFields = fieldName;
                }else{
                    commaSepratedFields = commaSepratedFields + ', ' + fieldName;
                }
            }
            
            query = 'select ' + commaSepratedFields + ' from ' + SobjectApiName + ' where nm_OpportunityNew__c = \''+ id + '\' AND nm_PaymentType__c = \'Admission\' AND nm_PaymentStatus__c = \'Payment Approved\'';
            system.debug('!!!!!!!query!!!!!!!'+query);
            paymentList = Database.query(query);
            system.debug('!!!!!!!paymentList!!!!!!!'+paymentList);
            return paymentList[0];
    }
    
    public Opportunity getNextSemOpportunity(Opportunity currentSemOpportunity){
        
        Opportunity nextSemOpportunity = currentSemOpportunity.clone();
        if(currentSemOpportunity.nm_Session__c == 'January'){
            nextSemOpportunity.nm_Session__c = 'July';
        }else if(currentSemOpportunity.nm_Session__c == 'July'){
            nextSemOpportunity.nm_Session__c = 'January';
            nextSemOpportunity.nm_Year__c = currentSemOpportunity.nm_Year__c + 1;
        }
        
        Integer nextSem = Integer.valueOf(currentSemOpportunity.nm_Semester__c ) + 1;
        nextSemOpportunity.StageName = 'Closed Won - Re-registration Pending';
        nextSemOpportunity.nm_Fee_Type__c = 'PGAllSemFee-Considered';//Changing so that trigger does not fire again and future Opportunities are not further created
        nextSemOpportunity.nm_Semester__c = String.valueOf(nextSem);
        return nextSemOpportunity;
    }

}
Test Class :
 
@isTest
public class nmPGAllSemFeeTracker
{
    public static  Opportunity objOpp;
    public static  Opportunity objOpp2;
    public static  nm_Payment__c objPayment;
    public static Lead objLead;
    public static List<Opportunity> opps;
    static  testmethod  void unitTestForPGAllSemFee()
    {
        Product2 objProduct = new Product2();
        objProduct = CommonTrackerClass.createProduct(objProduct);
        Pricebook2 objpriceBook;
        objpriceBook =CommonTrackerClass.createPricebook();
        PricebookEntry objPBE;
        string strrecord = [select id from RecordType where SobjectType='Account' AND IsPersonType=True limit 1].id;
        Account Acc = new Account(
        RecordTypeID=strrecord,
        FirstName='jane',
        LastName='doe',
        nm_PreStudentNo__c ='77213',
        nm_StudentStatus__c='Confirmed',
        nm_Tagged_Pricebook__c=objpriceBook.id,
        nm_SerialNo__c=2,
        PersonMobilePhone='8377985721',
        PersonEmail='teste@gmail.com') ; 
        Test.startTest();
        insert Acc;          
        objOpp = new Opportunity();
        objOpp.StageName = 'Closed';
        objOpp.nm_Fee_Type__c = 'PGAllSemFee';
        objOpp.nm_Future_Sems_Created__c = false;  
        objOpp.Accountid = Acc.id;
        objOpp.CloseDate = date.parse('06/27/2015');
        objOpp.Name = 'testOpp';
        opps = new List<Opportunity>();
        opps.add(objOpp);
        
        objOpp2 = new Opportunity();
        objOpp2.StageName = 'Closed Won';
        objOpp2.nm_Fee_Type__c = 'PGAllSemFee';
        objOpp2.nm_Future_Sems_Created__c = false;  
        objOpp2.Accountid = Acc.id;
        objOpp2.CloseDate = date.parse('06/27/2015');
        objOpp2.Name = 'testOpp2';
        opps.add(objOpp2);
        insert opps;
        update opps;
        //objOpp = CommonTrackerClass.createOpportunity(objOpp);
        
        //objOpp = [Select StageName from Opportunity where Id =: objOpp.Id];
        //objOpp.StageName = 'Closed Won';
        //update objOpp;
        
        //objPBE =CommonTrackerClass.CreatePriceBookEntry(objProduct.id,objpriceBook.id);
        //nm_StudentProgram__c objSp;
       // objSp=CommonTrackerClass.createStudentProgram(objSp);
        
         objLead = new  Lead();
         objLead.nm_SelectedIC__c ='1';
         objLead.LastName ='kumar';
         objLead.FirstName='amit';
         objLead.nm_DateOfBirth__c =System.today();
         objLead.status='Hot';
         objLead.Email='mayurnagaonkar@gmail.com';
         objLead.MobilePhone ='8377985721';
         objLead.nm_ChooseaProgram__c ='Certificate Programs';
         //objLead.nm_Program__c = objP.Id;
         //objLead.nm_EligiblityCriteria__c = objEc.Id;
         objLead.nm_PaymentCompleted__c = false;
         objLead.nm_SelectedProgram__c ='MCA';
         //objLead.nm_InformationCenter__c =objCenter1.id;
         objLead.nm_Year__c =2014;
         objLead.LeadSource ='Walk -in';
         objLead.nm_PaymentStatus__c ='Registration form filled';
         objLead.nm_PlantoStart__c ='2-4 Months';
         objLead.nm_Session__c='July';
         objLead.nm_CopyAddress__c='Yes';
         objLead.nm_ModeOfPayment__c='Online';
         objLead.nm_EscallationDone__c=8;
         objLead.nm_RegistrationID__c='a0BN0000001FUdB';
         //objLead.nm_RegistrationNo__c='a0BN0000001FUdB';
         insert objLead;
        
        objPayment = new nm_Payment__c();
        objPayment.nm_OpportunityNew__c =objOpp.id;
        objPayment.nm_Lead__c=objLead.id;
        objPayment.nm_PaymentType__c ='Admission';
        objPayment.nm_Amount__c = 15500;
        objPayment.nm_PaymentStatus__c ='Payment Approved';
        objPayment = CommonTrackerClass.createPayment(objPayment);
        
        nmPGAllSemFee controller=new nmPGAllSemFee();
        //Apexpages.StandardController stdController = new Apexpages.StandardController(objOpp.Id);
        List<Opportunity> lstOpp = [Select Id, Name from Opportunity where Id =: objOpp.Id];
        if(lstOpp.size() > 0){
        controller.getPaymentForOpportunity(lstOpp[0].Id);
        }
        Test.stopTest();

    }

}
Can you please help me in increasing the code coverage

Thanks
 
Hi,

I want to copy and insert duplicate records to new object.
But Add Error Method from my code doesn't allow me to perform dml operation or send email.
Can you please help me with the same.

Thanks
Hi,

I am unable to Reports in Visualforce Page using jQuery.
Below is my code.
<apex:page >

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /> 

<div id="divTestArea1">
</div>

<script>
j$ = jQuery.noConflict();

j$(function()
{
$("#divTestArea1").load("http://ap1.salesforce.com/00O900000034a1f");
});
</script>

</apex:page>

 
  • April 20, 2015
  • Like
  • 0
Hi,
I have List<User> and its count.
I am iterating over a user count to display outputPanels for each and every user.
How to dynamically assign the value to "Rendered" attribute. i.e. In place of ABC in below example.
for eg.

<apex:repeat value="lstuser" var="u">
<apex:repeat value="list2" var="v">
<apex:outputPanel rendered="{!If(v.Name == 'ABC', true, false)}">
</apex:outputPanel>
</apex:repeat>
</apex:repeat>

Thanks.
  • April 13, 2015
  • Like
  • 0
Hi,

I have Integer Count in my controller.
The value of this count is dynamically rendered through query.
Count = [Select Count() from User where UserRole.Name =: 'Manager'];

How to render <apex:outputPanel> in visualforce page till count becomes 0.
Also the outputPanel should be displayed only once for one user.

Thanks

 
  • April 08, 2015
  • Like
  • 1
Hi,

I am getting code coverage for first two lines(9%) of my trigger which checks the older and newer records.
Can you please help me increasing the code coverage to more than 75%.
Below is my code :
 
-----------------------------------------------------------------
Trigger
-----------------------------------------------------------------
trigger UserAvailabilityCheck on Case (before update) { 

if(stopRecursion.stopRecursiveTriggerRun ) {
    return;
}

stopRecursion.stopRecursiveTriggerRun = true;

Boolean oooFlag;
Set<ID> ids = Trigger.newMap.keyset();
ID oId;

List<Case> caseList = [Select Id, Status, OwnerId from Case where Id in : ids];

for(Case c : caseList) {
oId = c.OwnerId;
}

for (Case c : Trigger.New) {
    Case oldCase = Trigger.oldMap.get(c.Id);

    Boolean oldStatusClosed = oldCase.Status.equals('Closed');
    Boolean oldStatusACR = oldCase.Status.equals('Awaiting Customer Response');
    Boolean oldStatusResolved = oldCase.Status.equals('Resolved');
    Boolean newStatusInProgress = c.Status.equals('In Progress');

    if ((oldStatusClosed && newStatusInProgress)||(oldStatusACR && newStatusInProgress)||(oldStatusResolved && newStatusInProgress)) {

      Map<Id, boolean> onlineMap = n2de.DistributionEngineGlobal.getAvailabilityByUser(oId);

      for (Id id : onlineMap.keySet()) {  
      oooFlag = onlineMap.get(id);
      System.debug('===oooFlag ' + oooFlag);
      break;
      }
      if(!oooFlag){
      c.OwnerId = Label.Case_ReDistributeCasesId;
      }

    }
  }

}
-----------------------------------------------------------------
Test Class 
-----------------------------------------------------------------

@isTest
private class UserAvailabilityCheckTest {

    private  static  RecordType supportCaseRecordType  = [SELECT Name, Id FROM RecordType 
                                                          WHERE Name ='Support Case' 
                                                          AND SObjectType = 'Case'];
    static testMethod void testUserAvailabilityCheck() {
        
        User testUser = new User();
        testUser.Username= 'm98704nn@companyn.com';
        testUser.Email = 'testuser198704nn@companyn.com';
        testUser.Lastname = 'user4';
        testUser.Firstname = 'test4';
        testUser.Alias = 'test4';
        testUser.CommunityNickname = '123464';
        testUser.UserRole = [ select id from userrole where id ='00EG00000015wJk' ];
        testUser.ProfileId = '00eG0000000fz9y';
        
        //testUser.CurrencyIsoCode = 'USD';
        testUser.TimeZoneSidKey = 'GMT';
        testUser.LocaleSidKey = 'en_US';
        testUser.EmailEncodingKey = 'ISO-8859-1';
        testUser.LanguageLocaleKey = 'en_US';
        testUser.UserPermissionsMobileUser = false;

        insert testUser;
        
        User testUser2 = new User();
        testUser2.Username= 'm987041nn@companyn.com';
        testUser2.Email = 'testuser1987041nn@companyn.com';
        testUser2.Lastname = 'user41';
        testUser2.Firstname = 'test41';
        testUser2.Alias = 'test4';
        testUser2.CommunityNickname = '1234641';
        testUser2.UserRole = [ select id from userrole where id ='00EG00000015wJk' ];
        testUser2.ProfileId = '00eG0000000fz9y';
        
        //testUser.CurrencyIsoCode = 'USD';
        testUser2.TimeZoneSidKey = 'GMT';
        testUser2.LocaleSidKey = 'en_US';
        testUser2.EmailEncodingKey = 'ISO-8859-1';
        testUser2.LanguageLocaleKey = 'en_US';
        testUser2.UserPermissionsMobileUser = false;

        insert testUser2;

        Account   testAccount = new Account();
        testAccount.Name  = 'Test Account';
    
        insert testAccount;
    
        Contact   testContact = new Contact();
        testContact.LastName  = 'Test Name';
        
        Test.startTest();

        insert testContact;

        Product2  testProduct = new Product2();
        testProduct.Name                  = 'Test Product Name';
        testProduct.Product_Category__c   = 'Category';
        testProduct.Product_Family__c     = 'Family';
        testProduct.Product_Sub_family__c = 'Sub-Family';    

        insert testProduct;
    
        Case  testCase  = new Case();
        testCase.RecordTypeId = supportCaseRecordType.Id;
        testCase.Summary__c   = 'Summary';
        testCase.Description  = 'Description';
        testCase.Origin       = 'Email';
        testCase.Status       = 'Awaiting Customer Response';
        testCase.I_Agree__c   = true;
        testCase.ContactId    = testContact.Id;
        testCase.ProductId    = testProduct.Id;
        testCase.OwnerId      = testUser.Id;        

        insert testCase;

        testCase.OwnerId = testUser2.Id;  
        update testCase; 

        Test.stopTest();  

        Case c = [SELECT Status,OwnerID FROM Case WHERE Id = :testCase.Id];

        System.assertEquals( testUser2.Id, c.OwnerId );
            
    }
}
  • March 09, 2015
  • Like
  • 0
How to write test class for trigger which compare older and newer valuee
trigger GetAvailability on Case (before update) { 

Boolean oooFlag;
Set<ID> ids = Trigger.newMap.keyset();
ID oId;

List<Case> caseList = [Select Id, Status, OwnerId from Case where Id in : ids];

for(Case c : caseList) {
oId = c.OwnerId;
}

for (Case c : Trigger.New) {
    Case oldCase = Trigger.oldMap.get(c.Id);

    Boolean oldStatus = oldCase.Status.equals('Closed');

    Boolean newStatus = c.Status.equals('New');
 
    if(oldStatus && newStatus) {

      Map<Id, boolean> Map1 = GlobalClass.getAvailability(oId);

      for (Id id : Map1.keySet()) {  
      oooFlag = Map1.get(id);
      System.debug('===oooFlag ' + oooFlag);
      break;
      }
      if(!oooFlag){
      c.OwnerId = 'idtyt3RTGBhtu7u';
      }

    }
  }

}

 
  • March 03, 2015
  • Like
  • 0
Hi,

I have written a below trigger and its test class.
For test class I am getting 34% code coverage.
How to write test class for this to get complete code coverage.
trigger UpdateRecTrigger on Account (before update) {

    for (Account a : Trigger.new) {
        
        RecordType rt = [SELECT Id, Name FROM RecordType WHERE SobjectType='Account' AND Name ='Rec1'];
        if (Trigger.isBefore) {
        if(a.RecordTypeId == rt.Id && c.Number__c != null){
            
            Id aId = a.Id;
            a.Count__c += 1;

            if(a.Count__c > 1){

                if(!a.Flag__c){
                    
                    if(!System.isFuture()){
                    AccountClass.updateRec(aId);
                    } else {
                    AccountClass.updateRecName(aId);
                    }

                } else {
                  
                   a.Flag__c = false;
                }

            }
       
        }
      }
    }

}


 
  • February 04, 2015
  • Like
  • 0
Hi,

I have an object with OWD equal to "Private".
I have sharing rule (Read/Write Access) on object for sharing record of "RecType1" with group of users.(Created Public Group).

I want to provide read only access to records of "RecType1" record type for "Engineer" role.(Engineer profile has CRU permission to this obj)

I have created sharing rule with read only access to this role.
Still I get "Insufficient Privileges" error for users in the Engineer role.
 
  • January 27, 2015
  • Like
  • 0
Hi,

I have a @future method Display().
I want to open visualforce page after executing callout code from future method.

@future(callout=true)
public static void display()
{
//callout code
//after this callout code, this method should open vf page
}

I am calling this future method thro' after insert trigger.
  • January 22, 2015
  • Like
  • 0
Hi,

How to write a test class for trigger which calls @future method

for eg.
trigger AccountCallout on Account (after insert) {
for (Account a : Trigger.new) {
WebServiceCallout.sendNotification(a.Id);
}
}
 
  • January 21, 2015
  • Like
  • 0
Hi,

I have a @future method in apex class and I am calling that method thro after insert trigger.
Rest callout code is present in the future method.
How to show error message on salesforce standard ui when rest callout fails?
  • January 21, 2015
  • Like
  • 0
Hi,

I am unable to get test code coverage for below code :
 
User c = [select Email,ManagerId from User where Id =:uc.OwnerId];
User u = [Select Email from User where Id =:c.ManagerId];
message.setTargetObjectId(c.Id);
message.setWhatId(uc.Id);
message.setSaveAsActivity(false);
message.setToAddresses(new String[] {u.Email});

Messaging.sendEmail(new Messaging.Email[] {message});
Regards,
Mayur
 
  • October 28, 2014
  • Like
  • 0
Hi,

I want to bypass trigger for Community Users.
How to do this?
  • October 13, 2014
  • Like
  • 0
Hi,

I have Integer Count in my controller.
The value of this count is dynamically rendered through query.
Count = [Select Count() from User where UserRole.Name =: 'Manager'];

How to render <apex:outputPanel> in visualforce page till count becomes 0.
Also the outputPanel should be displayed only once for one user.

Thanks

 
  • April 08, 2015
  • Like
  • 1
Hi,

How to render attachment on visualforce page based on file extension.
Also how to download attachment from visualforce page without attachment as standard controller.
  • January 13, 2014
  • Like
  • 1
Hi,

My class compares old and new values of records in one of the for loops.
I am getting only 17% code coverage for the class. Below is my apex class and test class.


Apex Class :
 
public class nmPGAllSemFee
{   
    public string query{get;set;}
    public void createNextSemOpportunityOnClosedWonForFullFee(List<Opportunity> triggerNew, map<id, Opportunity> oldMap)
    {
        List<Opportunity> opptyListToInsert = new List<Opportunity>();
        List<nm_Payment__c> paymentListToInsert = new List<nm_Payment__c>();
        
        for(Opportunity newOpportunity : triggerNew)
        {
            Id opptyId = newOpportunity.Id;
            
            
            Opportunity oldOpportunity =  oldMap.get(opptyId);
            System.debug('!!!!!newOpportunity!!!' + newOpportunity);
            if(newOpportunity.nm_Fee_Type__c == 'PGAllSemFee' && 
                newOpportunity.nm_Future_Sems_Created__c == false && 
                newOpportunity.StageName != oldOpportunity.StageName &&  
                newOpportunity.StageName == 'Closed Won'){
                
                opptyListToInsert = new List<Opportunity>();
                newOpportunity.nm_Future_Sems_Created__c = true;
                Opportunity sem2Opp = getNextSemOpportunity(newOpportunity);
                Opportunity sem3Opp = getNextSemOpportunity(sem2Opp);
                Opportunity sem4Opp = getNextSemOpportunity(sem3Opp);
                
                opptyListToInsert.add(sem2Opp);
                opptyListToInsert.add(sem3Opp);
                opptyListToInsert.add(sem4Opp);
                
                insert opptyListToInsert;
                system.debug('!!!!!opptyListToInsert!!!!!!'+opptyListToInsert);
                nm_Payment__c existingPaymentObj = getPaymentForOpportunity(newOpportunity.Id);
                
                nm_Payment__c sem2Payment = existingPaymentObj.clone();
                sem2Payment.nm_OpportunityNew__c = sem2Opp.Id;
                nm_Payment__c sem3Payment = existingPaymentObj.clone();
                sem3Payment.nm_OpportunityNew__c = sem3Opp.Id;
                nm_Payment__c sem4Payment = existingPaymentObj.clone();
                sem4Payment.nm_OpportunityNew__c = sem4Opp.Id;

                paymentListToInsert.add(sem2Payment);
                paymentListToInsert.add(sem3Payment);
                paymentListToInsert.add(sem4Payment);
                
                insert paymentListToInsert;
                
            }
            
        }
        
        }

    public nm_Payment__c getPaymentForOpportunity(Id id){
            List<nm_Payment__c> paymentList = new List<nm_Payment__c>();
            String SobjectApiName = 'nm_Payment__c';
            Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
 
            String commaSepratedFields = '';
            for(String fieldName : fieldMap.keyset()){
                if(commaSepratedFields == null || commaSepratedFields == ''){
                    commaSepratedFields = fieldName;
                }else{
                    commaSepratedFields = commaSepratedFields + ', ' + fieldName;
                }
            }
            
            query = 'select ' + commaSepratedFields + ' from ' + SobjectApiName + ' where nm_OpportunityNew__c = \''+ id + '\' AND nm_PaymentType__c = \'Admission\' AND nm_PaymentStatus__c = \'Payment Approved\'';
            system.debug('!!!!!!!query!!!!!!!'+query);
            paymentList = Database.query(query);
            system.debug('!!!!!!!paymentList!!!!!!!'+paymentList);
            return paymentList[0];
    }
    
    public Opportunity getNextSemOpportunity(Opportunity currentSemOpportunity){
        
        Opportunity nextSemOpportunity = currentSemOpportunity.clone();
        if(currentSemOpportunity.nm_Session__c == 'January'){
            nextSemOpportunity.nm_Session__c = 'July';
        }else if(currentSemOpportunity.nm_Session__c == 'July'){
            nextSemOpportunity.nm_Session__c = 'January';
            nextSemOpportunity.nm_Year__c = currentSemOpportunity.nm_Year__c + 1;
        }
        
        Integer nextSem = Integer.valueOf(currentSemOpportunity.nm_Semester__c ) + 1;
        nextSemOpportunity.StageName = 'Closed Won - Re-registration Pending';
        nextSemOpportunity.nm_Fee_Type__c = 'PGAllSemFee-Considered';//Changing so that trigger does not fire again and future Opportunities are not further created
        nextSemOpportunity.nm_Semester__c = String.valueOf(nextSem);
        return nextSemOpportunity;
    }

}
Test Class :
 
@isTest
public class nmPGAllSemFeeTracker
{
    public static  Opportunity objOpp;
    public static  Opportunity objOpp2;
    public static  nm_Payment__c objPayment;
    public static Lead objLead;
    public static List<Opportunity> opps;
    static  testmethod  void unitTestForPGAllSemFee()
    {
        Product2 objProduct = new Product2();
        objProduct = CommonTrackerClass.createProduct(objProduct);
        Pricebook2 objpriceBook;
        objpriceBook =CommonTrackerClass.createPricebook();
        PricebookEntry objPBE;
        string strrecord = [select id from RecordType where SobjectType='Account' AND IsPersonType=True limit 1].id;
        Account Acc = new Account(
        RecordTypeID=strrecord,
        FirstName='jane',
        LastName='doe',
        nm_PreStudentNo__c ='77213',
        nm_StudentStatus__c='Confirmed',
        nm_Tagged_Pricebook__c=objpriceBook.id,
        nm_SerialNo__c=2,
        PersonMobilePhone='8377985721',
        PersonEmail='teste@gmail.com') ; 
        Test.startTest();
        insert Acc;          
        objOpp = new Opportunity();
        objOpp.StageName = 'Closed';
        objOpp.nm_Fee_Type__c = 'PGAllSemFee';
        objOpp.nm_Future_Sems_Created__c = false;  
        objOpp.Accountid = Acc.id;
        objOpp.CloseDate = date.parse('06/27/2015');
        objOpp.Name = 'testOpp';
        opps = new List<Opportunity>();
        opps.add(objOpp);
        
        objOpp2 = new Opportunity();
        objOpp2.StageName = 'Closed Won';
        objOpp2.nm_Fee_Type__c = 'PGAllSemFee';
        objOpp2.nm_Future_Sems_Created__c = false;  
        objOpp2.Accountid = Acc.id;
        objOpp2.CloseDate = date.parse('06/27/2015');
        objOpp2.Name = 'testOpp2';
        opps.add(objOpp2);
        insert opps;
        update opps;
        //objOpp = CommonTrackerClass.createOpportunity(objOpp);
        
        //objOpp = [Select StageName from Opportunity where Id =: objOpp.Id];
        //objOpp.StageName = 'Closed Won';
        //update objOpp;
        
        //objPBE =CommonTrackerClass.CreatePriceBookEntry(objProduct.id,objpriceBook.id);
        //nm_StudentProgram__c objSp;
       // objSp=CommonTrackerClass.createStudentProgram(objSp);
        
         objLead = new  Lead();
         objLead.nm_SelectedIC__c ='1';
         objLead.LastName ='kumar';
         objLead.FirstName='amit';
         objLead.nm_DateOfBirth__c =System.today();
         objLead.status='Hot';
         objLead.Email='mayurnagaonkar@gmail.com';
         objLead.MobilePhone ='8377985721';
         objLead.nm_ChooseaProgram__c ='Certificate Programs';
         //objLead.nm_Program__c = objP.Id;
         //objLead.nm_EligiblityCriteria__c = objEc.Id;
         objLead.nm_PaymentCompleted__c = false;
         objLead.nm_SelectedProgram__c ='MCA';
         //objLead.nm_InformationCenter__c =objCenter1.id;
         objLead.nm_Year__c =2014;
         objLead.LeadSource ='Walk -in';
         objLead.nm_PaymentStatus__c ='Registration form filled';
         objLead.nm_PlantoStart__c ='2-4 Months';
         objLead.nm_Session__c='July';
         objLead.nm_CopyAddress__c='Yes';
         objLead.nm_ModeOfPayment__c='Online';
         objLead.nm_EscallationDone__c=8;
         objLead.nm_RegistrationID__c='a0BN0000001FUdB';
         //objLead.nm_RegistrationNo__c='a0BN0000001FUdB';
         insert objLead;
        
        objPayment = new nm_Payment__c();
        objPayment.nm_OpportunityNew__c =objOpp.id;
        objPayment.nm_Lead__c=objLead.id;
        objPayment.nm_PaymentType__c ='Admission';
        objPayment.nm_Amount__c = 15500;
        objPayment.nm_PaymentStatus__c ='Payment Approved';
        objPayment = CommonTrackerClass.createPayment(objPayment);
        
        nmPGAllSemFee controller=new nmPGAllSemFee();
        //Apexpages.StandardController stdController = new Apexpages.StandardController(objOpp.Id);
        List<Opportunity> lstOpp = [Select Id, Name from Opportunity where Id =: objOpp.Id];
        if(lstOpp.size() > 0){
        controller.getPaymentForOpportunity(lstOpp[0].Id);
        }
        Test.stopTest();

    }

}
Can you please help me in increasing the code coverage

Thanks
 
Hi,
I have List<User> and its count.
I am iterating over a user count to display outputPanels for each and every user.
How to dynamically assign the value to "Rendered" attribute. i.e. In place of ABC in below example.
for eg.

<apex:repeat value="lstuser" var="u">
<apex:repeat value="list2" var="v">
<apex:outputPanel rendered="{!If(v.Name == 'ABC', true, false)}">
</apex:outputPanel>
</apex:repeat>
</apex:repeat>

Thanks.
  • April 13, 2015
  • Like
  • 0
Hi,

I have Integer Count in my controller.
The value of this count is dynamically rendered through query.
Count = [Select Count() from User where UserRole.Name =: 'Manager'];

How to render <apex:outputPanel> in visualforce page till count becomes 0.
Also the outputPanel should be displayed only once for one user.

Thanks

 
  • April 08, 2015
  • Like
  • 1
Hi,

I am getting code coverage for first two lines(9%) of my trigger which checks the older and newer records.
Can you please help me increasing the code coverage to more than 75%.
Below is my code :
 
-----------------------------------------------------------------
Trigger
-----------------------------------------------------------------
trigger UserAvailabilityCheck on Case (before update) { 

if(stopRecursion.stopRecursiveTriggerRun ) {
    return;
}

stopRecursion.stopRecursiveTriggerRun = true;

Boolean oooFlag;
Set<ID> ids = Trigger.newMap.keyset();
ID oId;

List<Case> caseList = [Select Id, Status, OwnerId from Case where Id in : ids];

for(Case c : caseList) {
oId = c.OwnerId;
}

for (Case c : Trigger.New) {
    Case oldCase = Trigger.oldMap.get(c.Id);

    Boolean oldStatusClosed = oldCase.Status.equals('Closed');
    Boolean oldStatusACR = oldCase.Status.equals('Awaiting Customer Response');
    Boolean oldStatusResolved = oldCase.Status.equals('Resolved');
    Boolean newStatusInProgress = c.Status.equals('In Progress');

    if ((oldStatusClosed && newStatusInProgress)||(oldStatusACR && newStatusInProgress)||(oldStatusResolved && newStatusInProgress)) {

      Map<Id, boolean> onlineMap = n2de.DistributionEngineGlobal.getAvailabilityByUser(oId);

      for (Id id : onlineMap.keySet()) {  
      oooFlag = onlineMap.get(id);
      System.debug('===oooFlag ' + oooFlag);
      break;
      }
      if(!oooFlag){
      c.OwnerId = Label.Case_ReDistributeCasesId;
      }

    }
  }

}
-----------------------------------------------------------------
Test Class 
-----------------------------------------------------------------

@isTest
private class UserAvailabilityCheckTest {

    private  static  RecordType supportCaseRecordType  = [SELECT Name, Id FROM RecordType 
                                                          WHERE Name ='Support Case' 
                                                          AND SObjectType = 'Case'];
    static testMethod void testUserAvailabilityCheck() {
        
        User testUser = new User();
        testUser.Username= 'm98704nn@companyn.com';
        testUser.Email = 'testuser198704nn@companyn.com';
        testUser.Lastname = 'user4';
        testUser.Firstname = 'test4';
        testUser.Alias = 'test4';
        testUser.CommunityNickname = '123464';
        testUser.UserRole = [ select id from userrole where id ='00EG00000015wJk' ];
        testUser.ProfileId = '00eG0000000fz9y';
        
        //testUser.CurrencyIsoCode = 'USD';
        testUser.TimeZoneSidKey = 'GMT';
        testUser.LocaleSidKey = 'en_US';
        testUser.EmailEncodingKey = 'ISO-8859-1';
        testUser.LanguageLocaleKey = 'en_US';
        testUser.UserPermissionsMobileUser = false;

        insert testUser;
        
        User testUser2 = new User();
        testUser2.Username= 'm987041nn@companyn.com';
        testUser2.Email = 'testuser1987041nn@companyn.com';
        testUser2.Lastname = 'user41';
        testUser2.Firstname = 'test41';
        testUser2.Alias = 'test4';
        testUser2.CommunityNickname = '1234641';
        testUser2.UserRole = [ select id from userrole where id ='00EG00000015wJk' ];
        testUser2.ProfileId = '00eG0000000fz9y';
        
        //testUser.CurrencyIsoCode = 'USD';
        testUser2.TimeZoneSidKey = 'GMT';
        testUser2.LocaleSidKey = 'en_US';
        testUser2.EmailEncodingKey = 'ISO-8859-1';
        testUser2.LanguageLocaleKey = 'en_US';
        testUser2.UserPermissionsMobileUser = false;

        insert testUser2;

        Account   testAccount = new Account();
        testAccount.Name  = 'Test Account';
    
        insert testAccount;
    
        Contact   testContact = new Contact();
        testContact.LastName  = 'Test Name';
        
        Test.startTest();

        insert testContact;

        Product2  testProduct = new Product2();
        testProduct.Name                  = 'Test Product Name';
        testProduct.Product_Category__c   = 'Category';
        testProduct.Product_Family__c     = 'Family';
        testProduct.Product_Sub_family__c = 'Sub-Family';    

        insert testProduct;
    
        Case  testCase  = new Case();
        testCase.RecordTypeId = supportCaseRecordType.Id;
        testCase.Summary__c   = 'Summary';
        testCase.Description  = 'Description';
        testCase.Origin       = 'Email';
        testCase.Status       = 'Awaiting Customer Response';
        testCase.I_Agree__c   = true;
        testCase.ContactId    = testContact.Id;
        testCase.ProductId    = testProduct.Id;
        testCase.OwnerId      = testUser.Id;        

        insert testCase;

        testCase.OwnerId = testUser2.Id;  
        update testCase; 

        Test.stopTest();  

        Case c = [SELECT Status,OwnerID FROM Case WHERE Id = :testCase.Id];

        System.assertEquals( testUser2.Id, c.OwnerId );
            
    }
}
  • March 09, 2015
  • Like
  • 0
How to write test class for trigger which compare older and newer valuee
trigger GetAvailability on Case (before update) { 

Boolean oooFlag;
Set<ID> ids = Trigger.newMap.keyset();
ID oId;

List<Case> caseList = [Select Id, Status, OwnerId from Case where Id in : ids];

for(Case c : caseList) {
oId = c.OwnerId;
}

for (Case c : Trigger.New) {
    Case oldCase = Trigger.oldMap.get(c.Id);

    Boolean oldStatus = oldCase.Status.equals('Closed');

    Boolean newStatus = c.Status.equals('New');
 
    if(oldStatus && newStatus) {

      Map<Id, boolean> Map1 = GlobalClass.getAvailability(oId);

      for (Id id : Map1.keySet()) {  
      oooFlag = Map1.get(id);
      System.debug('===oooFlag ' + oooFlag);
      break;
      }
      if(!oooFlag){
      c.OwnerId = 'idtyt3RTGBhtu7u';
      }

    }
  }

}

 
  • March 03, 2015
  • Like
  • 0
Hi,

I have a @future method Display().
I want to open visualforce page after executing callout code from future method.

@future(callout=true)
public static void display()
{
//callout code
//after this callout code, this method should open vf page
}

I am calling this future method thro' after insert trigger.
  • January 22, 2015
  • Like
  • 0
Hi,

How to write a test class for trigger which calls @future method

for eg.
trigger AccountCallout on Account (after insert) {
for (Account a : Trigger.new) {
WebServiceCallout.sendNotification(a.Id);
}
}
 
  • January 21, 2015
  • Like
  • 0
Hi,

I have a @future method in apex class and I am calling that method thro after insert trigger.
Rest callout code is present in the future method.
How to show error message on salesforce standard ui when rest callout fails?
  • January 21, 2015
  • Like
  • 0
Hi,

I am getting below error in Apex trigger which updates field on parent obj based on value in child obj record

first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateRegion: maximum trigger depth exceeded SampleMasterObject

Apex Trigger Code

trigger updateRegion on SampleMasterObject__c (after insert, after update) {

ID smoId;
String country;
//String region;

for(SampleMasterObject__c s : Trigger.New){

smoId = s.Id;
system.debug('@@@@@@smoId@@@@@@@@@@ : '+smoId);
}

List<SampleChild1__c> lsc = new List<SampleChild1__c>();
lsc = [Select Id, Country__c from SampleChild1__c where SampleMasterObject__c =: smoId];
system.debug('@@@@@@lsc@@@@@@@@@@ : '+lsc);

for(SampleChild1__c sc : lsc) {

country = sc.Country__c;
system.debug('@@@@@@country@@@@@@@@@@ : '+country);
}

If(country == 'IN') {
SampleMasterObject__c sm = new SampleMasterObject__c(Id=smoId, Region__c = 'APAC');

//sm.Id = smoId;
//sm.Region__c = 'APAC';
system.debug('@@@@@@sm.Region__c@@@@@@@@@@ : '+sm.Region__c);
update sm;
}




}
Full Error Statement

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger updateRegion caused an unexpected exception, contact your administrator: updateRegion: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0b90000009eu9JAAQ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateRegion: maximum trigger depth exceeded SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J]: []: Trigger.updateRegion: line 31, column 1
Information:


  • September 30, 2014
  • Like
  • 0
Hello,
I have created a radio button yes/no on VF page. There is text box called "comment" on the page. I need a help on how to create an error message while saving the form(VF). If a user selects the option "Yes" he/she must put value on "comment box" or in another word coment box is not equal to Null. I am new to the VF page. If you could provide me the code, that would be great help. Thank you in advance.