• Abhishek Tiwari 25
  • NEWBIE
  • 40 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 10
    Replies
Unable to compleet the chalange getting error as 
Challenge Not yet complete... here's what's wrong: 
Whoops! We found at least one contact with a mailing state that is longer than two characters.

CHalanage--
https://trailhead.salesforce.com/en/superbadges/superbadge_reports 
Import survey and opportunity data
Install the unmanaged package from the pre-work if you haven’t already. Clean and import Sandita’s data into Salesforce. You might need to modify the Excel data structure to import it correctly.
Insertion is done successfully but the record is not shared to the corresponding user.Please help 
 
 
//This class is used for manual sharing of Case Record
public class ManualSharingRecord {
   
    //This method takes two parameter first the record ID which you want to share
    //and second one to whom you want to share the record(Either user or group)
    public static Boolean successfullCaseSharing(ID recordId,ID userORGroup)
    {
        //create the object of caseshare object type
        CaseShare csShare=new CaseShare();
       
        //set the record level of sharing
        csShare.CaseAccessLevel='edit';
        //put the recordId which you want to share
        csShare.CaseId=recordId;
        system.debug('Record Id'+ csShare.CaseId);
        //put the userORGroup id to whom you want to share the record
        csShare.UserOrGroupId=userORGroup;
                system.debug('userId'+csShare.UserOrGroupId);
       csShare.RowCause=schema.caseShare.RowCause.manual;
       
        Database.SaveResult save=Database.insert(csShare,false);
        {
            if(save.issuccess())
            {
                return true;
            }
            else
            {
                Database.Error err=save.getErrors()[0];
                system.debug('Error'+save.getErrors()[0].getMessage());
                if(err.getStatusCode()==statuscode.FIELD_FILTER_VALIDATION_EXCEPTION &&err.getMessage().contains('Accesslevel'))
                {
                    return true;
                }
                else
                {
                    return false;
                }
                   
            }
        }
       
        
      
    }
 
}
 
 
 
case cs=new case(status='new',origin='phone');
    insert cs;
ID recordId=cs.id;
User us=[select id from user where name like '%abc%'];
ID userORGroup=us.id;
boolean rs=ManualSharingRecord.successfullCaseSharing(recordId, userORGroup);
system.debug('result'+rs);
 
I am facing coverage issue in my test class,please suggest
CLASS
public class SurveyDetailViewPage {
    String Id;
    public Survey_Mcd__c smc;
    public SurveyDetailViewPage(ApexPages.StandardController controller) {
    Id = ApexPages.Currentpage().getParameters().get('id');
    this.smc = (Survey_Mcd__c)controller.getRecord();
    }

}


TEST CLASS

@isTest
private class TestsurveydetailViewPage {
  static testMethod void myUnitTest1() {
  
        Test.startTest();
        Survey_Mcd__c smc = new Survey_Mcd__c();
        smc.Survey_Name__c = 'McDonald';
        smc.Question__c = 'Test';
        smc.X5_Scale_Rating__c = false;
        insert smc;
        
List<Survey_Mcd__c> smcRecord = new List<Survey_Mcd__c>();
smcRecord = [Select Id From Survey_Mcd__c where Id=:smc.Id LIMIT 1];
if(smcRecord.size()>0)
ApexPages.Currentpage().getParameters().put('id',smcRecord.get(0).Id); 
        Test.stopTest();
    }
}
PageReference searchPOAgain
I am getting error  in test class as 
System.DmlException: Update failed. First exception on row 0 with id a1h17000003NcsjAAC; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please select only one checkbox: []
Class.TestselectOneCheckbox.myUnitTest: line 18, column 1
Please help :



Trigger:
trigger selectOneCheckbox on Survey_Mcd__c (before update) {
for(Survey_Mcd__c sms : Trigger.New){
  if(Trigger.isUpdate){
  if((sms.Yes_No__c && sms.X5_Scale_Rating__c && sms.Comment__c)  || (sms.Yes_No__c && sms.X5_Scale_Rating__c)  
  || (sms.Yes_No__c && sms.Comment__c) || (sms.X5_Scale_Rating__c && sms.Comment__c)){
  sms.addError('Please select only one checkbox');
   }
  }
 }
}

Test class

@isTest
public class TestselectOneCheckbox {
    static testMethod  void myUnitTest() {
        system.test.startTest();
         
            Survey_Mcd__c sms= new Survey_Mcd__c();
                 sms.Yes_No__c=true;
            sms.X5_Scale_Rating__c=true;
            sms.Comment__c=true;
               insert sms;
        List <Survey_Mcd__c> sm= [select id,Comment__c,X5_Scale_Rating__c,Yes_No__c 
                                  from Survey_Mcd__c where id=:sms.id];
         for ( Survey_Mcd__c v:sm)
        {
            v.Comment__c=true;
            v.X5_Scale_Rating__c=false;
        } 
    update sm;
        Survey_Mcd__c sms1= new Survey_Mcd__c();
                 sms1.Yes_No__c=true;
            sms1.X5_Scale_Rating__c=true;
            sms1.Comment__c=true;
               update sms1;
            system.test.stopTest();
        }
}

 
I am getting error as 
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] while executing my test class for trigger Please suggest:

Trigger:
trigger selectOneCheckbox on Survey_Mcd__c (before update) {
for(Survey_Mcd__c sms : Trigger.New){
  if(Trigger.isUpdate){
  if((sms.Yes_No__c && sms.X5_Scale_Rating__c && sms.Comment__c)  || (sms.Yes_No__c && sms.X5_Scale_Rating__c)  
  || (sms.Yes_No__c && sms.Comment__c) || (sms.X5_Scale_Rating__c && sms.Comment__c)){
  sms.addError('Please select only one checkbox');
   }
  }
 }
}

Test Class:
@isTest
public class TestselectOneCheckbox {

    static testMethod  void myUnitTest() {
        system.test.startTest();
            
            Survey_Mcd__c sms= new Survey_Mcd__c();
                 sms.Yes_No__c=true;
            sms.X5_Scale_Rating__c=true;
            sms.Comment__c=true;
               update sms;
        List <Survey_Mcd__c> sm= [select id,Comment__c,X5_Scale_Rating__c,Yes_No__c from Survey_Mcd__c where id=:sms.id];
         for ( Survey_Mcd__c v:sm)
        {
            v.Comment__c=true;
        } 
        insert sm;
            system.test.stopTest();
        
    }
}


 
Unable to compleet the chalange getting error as 
Challenge Not yet complete... here's what's wrong: 
Whoops! We found at least one contact with a mailing state that is longer than two characters.

CHalanage--
https://trailhead.salesforce.com/en/superbadges/superbadge_reports 
Import survey and opportunity data
Install the unmanaged package from the pre-work if you haven’t already. Clean and import Sandita’s data into Salesforce. You might need to modify the Excel data structure to import it correctly.
I need to send mails to those leads who has not opened first email which I have already sent to them...
How can I achieve it??   Through HTML status report (Unopened) filed I got those clients who didn't open an email...But how can I get those clients throgh query??

plz help  
  • April 19, 2018
  • Like
  • 0
Insertion is done successfully but the record is not shared to the corresponding user.Please help 
 
 
//This class is used for manual sharing of Case Record
public class ManualSharingRecord {
   
    //This method takes two parameter first the record ID which you want to share
    //and second one to whom you want to share the record(Either user or group)
    public static Boolean successfullCaseSharing(ID recordId,ID userORGroup)
    {
        //create the object of caseshare object type
        CaseShare csShare=new CaseShare();
       
        //set the record level of sharing
        csShare.CaseAccessLevel='edit';
        //put the recordId which you want to share
        csShare.CaseId=recordId;
        system.debug('Record Id'+ csShare.CaseId);
        //put the userORGroup id to whom you want to share the record
        csShare.UserOrGroupId=userORGroup;
                system.debug('userId'+csShare.UserOrGroupId);
       csShare.RowCause=schema.caseShare.RowCause.manual;
       
        Database.SaveResult save=Database.insert(csShare,false);
        {
            if(save.issuccess())
            {
                return true;
            }
            else
            {
                Database.Error err=save.getErrors()[0];
                system.debug('Error'+save.getErrors()[0].getMessage());
                if(err.getStatusCode()==statuscode.FIELD_FILTER_VALIDATION_EXCEPTION &&err.getMessage().contains('Accesslevel'))
                {
                    return true;
                }
                else
                {
                    return false;
                }
                   
            }
        }
       
        
      
    }
 
}
 
 
 
case cs=new case(status='new',origin='phone');
    insert cs;
ID recordId=cs.id;
User us=[select id from user where name like '%abc%'];
ID userORGroup=us.id;
boolean rs=ManualSharingRecord.successfullCaseSharing(recordId, userORGroup);
system.debug('result'+rs);
 
I am facing coverage issue in my test class,please suggest
CLASS
public class SurveyDetailViewPage {
    String Id;
    public Survey_Mcd__c smc;
    public SurveyDetailViewPage(ApexPages.StandardController controller) {
    Id = ApexPages.Currentpage().getParameters().get('id');
    this.smc = (Survey_Mcd__c)controller.getRecord();
    }

}


TEST CLASS

@isTest
private class TestsurveydetailViewPage {
  static testMethod void myUnitTest1() {
  
        Test.startTest();
        Survey_Mcd__c smc = new Survey_Mcd__c();
        smc.Survey_Name__c = 'McDonald';
        smc.Question__c = 'Test';
        smc.X5_Scale_Rating__c = false;
        insert smc;
        
List<Survey_Mcd__c> smcRecord = new List<Survey_Mcd__c>();
smcRecord = [Select Id From Survey_Mcd__c where Id=:smc.Id LIMIT 1];
if(smcRecord.size()>0)
ApexPages.Currentpage().getParameters().put('id',smcRecord.get(0).Id); 
        Test.stopTest();
    }
}
PageReference searchPOAgain
I am getting error as 
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] while executing my test class for trigger Please suggest:

Trigger:
trigger selectOneCheckbox on Survey_Mcd__c (before update) {
for(Survey_Mcd__c sms : Trigger.New){
  if(Trigger.isUpdate){
  if((sms.Yes_No__c && sms.X5_Scale_Rating__c && sms.Comment__c)  || (sms.Yes_No__c && sms.X5_Scale_Rating__c)  
  || (sms.Yes_No__c && sms.Comment__c) || (sms.X5_Scale_Rating__c && sms.Comment__c)){
  sms.addError('Please select only one checkbox');
   }
  }
 }
}

Test Class:
@isTest
public class TestselectOneCheckbox {

    static testMethod  void myUnitTest() {
        system.test.startTest();
            
            Survey_Mcd__c sms= new Survey_Mcd__c();
                 sms.Yes_No__c=true;
            sms.X5_Scale_Rating__c=true;
            sms.Comment__c=true;
               update sms;
        List <Survey_Mcd__c> sm= [select id,Comment__c,X5_Scale_Rating__c,Yes_No__c from Survey_Mcd__c where id=:sms.id];
         for ( Survey_Mcd__c v:sm)
        {
            v.Comment__c=true;
        } 
        insert sm;
            system.test.stopTest();
        
    }
}


 
Controller class Bold Text lines are not covering

public class AddPaymentController {
 public Payment__C paymentObj {get;set;}
 Public String invId {get;set;}
    public AddPaymentController(ApexPages.StandardController controller) {
       if(paymentObj == null) {
           paymentObj = new Payment__C();
           String invId = ApexPages.CurrentPage().getParameters().get('invid');
             if(invId !=null) {
     Invoice__c invObj = [Select Prospect_Client__r.ShippingPostalCode,Prospect_Client__r.ShippingState,Prospect_Client__r.Cell_Phone__c,Prospect_Client__r.Email__c,Prospect_Client__r.ShippingStreet,Prospect_Client__r.Name,Prospect_Client_City__c,Name,Id From Invoice__c i where id =:invId];
                           
                      if(invObj !=null) {
                          paymentObj.invoice_numbers__c = invObj.Name;
                          paymentObj.Invoice_Number__c = invObj.id;                        
                          paymentObj.City__c=invObj.Prospect_Client_City__c;         
                          paymentObj.State__c=invObj.Prospect_Client__r.ShippingState;
                          paymentObj.Zip__c=invObj.Prospect_Client__r.ShippingPostalCode;
                          paymentObj.Name__c=invObj.Prospect_Client__r.Name;
                          paymentObj.Street__c=invObj.Prospect_Client__r.ShippingStreet;
                          paymentObj.Phone__c=invObj.Prospect_Client__r.Cell_Phone__c;
                          paymentObj.Email_Address__c=invObj.Prospect_Client__r.Email__c;    
                         
                      }                           
             }
       }
    }       
   public Pagereference save(){
   
       if(paymentObj.Amount__c==null)
       {
       ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'please enter Amount and insert.');
            ApexPages.addMessage(myMsg);
       }                         
         upsert paymentObj;
        //  ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Payment Created Successfully.Thank you!'));   
          Pagereference refpyob = new Pagereference('/apex/Invoice?id='+paymentObj.Invoice_Number__c);                   
          refpyob.setRedirect(true);
          return refpyob; 
                                     
}       
}

test class i am getting 84 percent


@isTest

public with sharing class TestAddPaymentController{
  public static testMethod void unitTestInvoice7()
  {
 try{
 
// String strRetUrl = ApexPages.CurrentPage().getParameters().put('retURL','/apex/AddPaymentVFPage');
       User objUser =[select Id, Name ,Email from User Where UserName = 'naveen@cloudprousa.com.test'];
          
          Staff__c objStaff = new Staff__c(User__c = objUser.Id,Name='Naveen1',Last_Name__c='Alasapuri1');
          insert objStaff;
          
          Account objAcc = new Account(Name = 'Test Prospect4', OwnerId=objUser.Id, Company_Name__c='test',Sales_Consultant__c = objStaff.Id,
                         Cell_Phone__c='987', ShippingStreet='test', ShippingCity='test', ShippingState='NJ');
          insert objAcc;
            Lead_Source__c objLS = new Lead_Source__c ( Name = 'Test Lead',Sales_Consultant__c =objStaff.Id);
      insert objLS;
          
            //SalesWorksheet record insertion
            
            Salesworksheet__c objSW = new Salesworksheet__c(C_Adjustment__c = 10,Lead_Source__c=objLS.Id);
            insert objSW;
            
            //User objUser =[select Id from User Where UserName = 'naveen@cloudprousa.com.test'];
            
            //Staff__c objStaff = new Staff__c(User__c = objUser.Id);
            //insert objStaff;
            
            Invoice__c objInv = new Invoice__c(Sales_Worksheet__c = objSW.Id);
            insert objInv;
            

            
            objSW.Technician__c = objStaff.Id;
            update objSW;
        //Payment record insertion
      Payment__c objPayment= new Payment__c(Amount__c=1000);
      insert objPayment;
        
     // insert objInv;
      String strInvId = ApexPages.CurrentPage().getParameters().put('invid',objInv.id);
      
         
      
      
      ApexPages.StandardController controller = new ApexPages.StandardController(objPayment);
      AddPaymentController objCGC = new AddPaymentController(controller);
      objCGC.save();
       //ApexPages.currentPage().getParameters().put('invid',objInv.id);
       
       
      // ApexPages.Message[] pageMessages = ApexPages.getMessages();
     //      System.assertNotEquals(0, pageMessages.size());
           
          
     //  PageReference pageRef =Page.Invoice;
     // Test.setCurrentPageReference(pageRef);
     
   //   ApexPages.CurrentPage().getParameters().put('retURL','/apex/Invoice?id='+objInv.Id);
       
    
    }catch(exception e)
    {
      system.debug('Exception..'+e);
    }
  }
 
  public static testMethod void unitTestInvoice8()
  {
 try{
 
// String strRetUrl = ApexPages.CurrentPage().getParameters().put('retURL','/apex/AddPaymentVFPage');
       User objUser =[select Id, Name ,Email from User Where UserName = 'naveen@cloudprousa.com.test'];
          
          Staff__c objStaff = new Staff__c(User__c = objUser.Id,Name='Naveen1',Last_Name__c='Alasapuri1');
          insert objStaff;
          
          Account objAcc = new Account(Name = 'Test Prospect4', OwnerId=objUser.Id, Company_Name__c='test',Sales_Consultant__c = objStaff.Id,
                         Cell_Phone__c='987', ShippingStreet='test', ShippingCity='test', ShippingState='NJ');
          insert objAcc;
            Lead_Source__c objLS = new Lead_Source__c ( Name = 'Test Lead',Sales_Consultant__c =objStaff.Id);
      insert objLS;
          
            //SalesWorksheet record insertion
            
            Salesworksheet__c objSW = new Salesworksheet__c(C_Adjustment__c = 10,Lead_Source__c=objLS.Id);
            insert objSW;
            
            //User objUser =[select Id from User Where UserName = 'naveen@cloudprousa.com.test'];
            
            //Staff__c objStaff = new Staff__c(User__c = objUser.Id);
            //insert objStaff;
            
            Invoice__c objInv = new Invoice__c(Sales_Worksheet__c = objSW.Id);
            insert objInv;
            

            
            objSW.Technician__c = objStaff.Id;
            update objSW;
        //Payment record insertion
      Payment__c objPayment= new Payment__c(Amount__c=1000);
      insert objPayment;
        
     // insert objInv;
     // String strInvId = ApexPages.CurrentPage().getParameters().put('invid',objInv.id);
      
         
             

       
      
      ApexPages.StandardController controller = new ApexPages.StandardController(objPayment);
      AddPaymentController objCGC = new AddPaymentController(controller);
      objCGC.save();
      
      PageReference testPage = new pagereference('/apex/Invoice?id='+objInv.Id);
      //change the following to opp.id instead of 'opp.id'
      //   testPage.getParameters().put('invid',objInv.id);

               Test.setCurrentPage(testPage);                    
    }catch(exception e)
    {
      system.debug('Exception..'+e);
    }
  }
 
 
}