• Chandu007
  • NEWBIE
  • 94 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 20
    Replies
I'm fresher , i would like to do a administrator certification, since i'm new i dont know the procedure and also about that can anyone help me ?
i want to make my visualforce component Read only when Case object status changed to Closed. i know we have Read only attribute in VF Page. do we have this in VF component too?
Is there any other solutions other than salesforce recommended (https://help.salesforce.com/articleView?id=000324937&language=en_US&type=1&mode=1) for this error "Compiled formula is too big to execute (5,259 characters). Maximum size is 5,000 characters"User-added image
I am trying to fetch Duplicate Records based on certain field but hitting below error. Please help me if my query is wrong.

Query:-  SELECT MHC2__MHC_Project_ID__c, count(Id) FROM MHC2__Project__c GROUP BY MHC2__MHC_Project_ID__c HAVING count(Id)>1 limit 1000


Error:- EXCEEDED_ID_LIMIT: Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch

when i tried to get them to CSV then hitting below error

Failed: InvalidBatch : Failed to process query: FUNCTIONALITY_NOT_ENABLED: Aggregate Relationships not supported in Bulk Query


Thanks,
Chandra
I want to restrict users from creating duplicate records on custom object using Batch class & Trigger??? since it's not working with Trigger(getting System.Query Exception)

Review all error messages below to correct your data.
Apex trigger ProjectDuplicateCheck caused an unexpected exception, contact your administrator: ProjectDuplicateCheck: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.ProjectDuplicateCheck: line 11, column 1

Please suggest if we have any AppExchange Apps to achieve this.


Thanks,
Chandra
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger ProjectDuplicateCheck caused an unexpected exception, contact your administrator: ProjectDuplicateCheck: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.ProjectDuplicateCheck: line 11, column 1

Trigger:-
trigger ProjectDuplicateCheck on MC2__Project__c (before insert,before update) {
   
    Set<String> setProjId = new Set<String>();
    For(MC2__Project__c mp : trigger.new)
    {
        setProjId.add(mp.MC2__MC_Project_ID__c);
    }
    
    if(setProjId.size() > 0 )
    { 
        List<MC2__Project__c> lstproject = [select MC2__MC_Project_ID__c,id from MC2__Project__c where MC2__MC_Project_ID__c!=null AND MC2__MC_Project_ID__c in:setProjId];
        
        
        Map<String,MC2__Project__c> Projmap = new Map<String,MC2__Project__c>();
        For(MC2__Project__c mhp: lstproject)
        {
            Projmap.put(mhp.MC2__MC_Project_ID__c,mhp);
        }
        
        For(MC2__Project__c mhp : trigger.new)
        {
            if(Projmap.containsKey(mhp.MC2__MC_Project_ID__c))
            {
                mhp.MC2__MC_Project_ID__c.addError('Project Id already exists, Please create project with new Project Id');
            }
        } 
      }
}
I am doing some modifications to existing test class and removed SeeAllData=true(for best practise). now i am getting below error. So, now i want to know whether SeeAllData=true when we are using Pricebook object in test class.

Error:-

System.QueryException: List has no rows for assignment to SObject

errored line from test class:-
Pricebook2 pb = [select Id from Pricebook2 where isStandard=true limit 1]; 
Getting System.DMLException in test class for below trigger. Please help me to solve it.

Trigger:- 

trigger OpportunityHowell on Opportunity (after Insert,after Update) {
   
  List<Opportunity> listOpportunitiesToUpdate = new List<Opportunity>();
  Set<Id> allOids = new Set<Id>();
  for(Opportunity o: Trigger.new){
    if(o.Multiplier__c != null && o.Multiplier__c != trigger.oldMap.get(o.id).Multiplier__c){
      allOids.add(o.id);
    }
  }
  listOpportunitiesToUpdate = [select id, (SELECT Id,Dollar_Sales_Howell__c from OpportunityLineItems) from Opportunity where id in :allOids];
  for(Opportunity o:listOpportunitiesToUpdate){
    o.Sum_of_Dollar_Sales_Howell__c = 0;
    for(OpportunityLineItem oli: o.OpportunityLineItems)
    Try{
      o.Sum_of_Dollar_Sales_Howell__c += oli.Dollar_Sales_Howell__c;
      }
    Catch(Exception e)
    {
  }
  if(listOpportunitiesToUpdate.size()>0)   
    update listOpportunitiesToUpdate;    
    }
  }

Test class:-

@isTest
public class OpportunityHowellTest {

    public static testMethod void TestOppty(){
        
         Set<Id> allOids = new Set<Id>();
         MHC2__Project__c p = new MHC2__Project__c(Name='Test Project',MHC2__MHC_Project_Bid_Date__c=System.Today(),MHC2__MHC_Target_Bid_Date__c=System.Today());
        insert p;
        Account a = new Account(Name='Test Account');
        insert a;
        
        Opportunity op = new Opportunity();
        op.Name = 'My Test Opportunity';
        op.Multiplier__c = 2;
        op.Sum_of_Dollar_Sales_Howell__c = 0;
        op.Bid_Date_Time__c = System.Now().addDays(30);
        op.CloseDate = System.Now().addDays(45).date();
        op.StageName = 'Bidding';
        op.AccountId = a.Id;
        op.Bid_Type__c = 'Lump Sum';
        op.Project__c = p.Id;
        insert op;
        
        op.Multiplier__c = 5;
        
        update op;
     
        
       OpportunityLineItem oli = new OpportunityLineItem();
        oli.Quantity = 1.0;
        oli.OpportunityId = op.Id;
        oli.Invoiced__c = false;
        insert oli; 
  }
}

Error:-

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityHowell: execution of AfterInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.OpportunityHowell: line 6, column 1: []
Hi,

I am able to cover Trigger.IsInsert & Trigger.IsUpdate but Trigger.IsDelete is not covering. Please check below test class and provide your suggestions.

Trigger:-
trigger CMC_Post_Tention_Weight_Rollup on OpportunityLineItem (after Insert, After Delete, After Update) 
{
Product2 productPostTensionWeight = [select id, name From Product2 where name = 'Post tension'];
    
if(trigger.isInsert)
{
List <OpportunityLineItem> postTensionWeight = trigger.new; //for update/Insert    
List<Id> listOptyIds = new List<Id>(); 
for(OpportunityLineItem eachOptyLineItem : PostTensionWeight ) 
    {
    listOptyIds.add(eachOptyLineItem.OpportunityId); 
    }

List <Opportunity> AllOppty = [Select ID, Name, Total_Post_Tension_Weight__c  from Opportunity 
                               where id in: listOptyIds];
for(Opportunity opty:AllOppty)
    {
    for(OpportunityLineItem PTW : postTensionWeight)
        {
          
        if(PTW.Product2Id == productPostTensionWeight.Id && PTW.OpportunityId == opty.Id)
            {   
            Opty.Total_Post_Tension_Weight__c = Opty.Total_Post_Tension_Weight__c + PTW.Post_Tension_Weight__c;   
            
            }
         }    
     }
update AllOppty;
}

if(trigger.isDelete)
{
List <OpportunityLineItem> postTensionWeight = trigger.Old; //for Delete    
List<Id> listOptyIds = new List<Id>(); 
for(OpportunityLineItem eachOptyLineItem : PostTensionWeight ) 
    {
    listOptyIds.add(eachOptyLineItem.OpportunityId); 
    }

List <Opportunity> AllOppty = [Select ID, Name, Total_Post_Tension_Weight__c  from Opportunity 
                               where id in: listOptyIds];
for(Opportunity opty:AllOppty)
    {
    for(OpportunityLineItem PTW : postTensionWeight)
        {
      
        if(PTW.Product2Id == productPostTensionWeight.Id && PTW.OpportunityId == opty.Id)
            {
           Opty.Total_Post_Tension_Weight__c = Opty.Total_Post_Tension_Weight__c - PTW.Post_Tension_Weight__c;   
            
            }
         }    
     }

update AllOppty;
}

if(trigger.isUpdate)
{
List <OpportunityLineItem> postTensionWeight = trigger.New;
List <OpportunityLineItem> OldpostTensionWeight = trigger.Old;    
List<Id> listOptyIds = new List<Id>(); 
for(OpportunityLineItem eachOptyLineItem : PostTensionWeight ) 
    {
    listOptyIds.add(eachOptyLineItem.OpportunityId); 
    }

List <Opportunity> AllOppty = [Select ID, Name, Total_Post_Tension_Weight__c  from Opportunity 
                               where id in: listOptyIds];
for(Opportunity opty:AllOppty)
    {
    for(OpportunityLineItem PTW : postTensionWeight)
        {
        For(OpportunityLineItem OPTW : OldpostTensionWeight)
        {        
        if(PTW.Product2Id == productPostTensionWeight.Id && PTW.OpportunityId == opty.Id && PTW.ID==OPTW.ID)
            {
      
            Opty.Total_Post_Tension_Weight__c = Opty.Total_Post_Tension_Weight__c - OPTW.Post_Tension_Weight__c + PTW.Post_Tension_Weight__c;   
            
            }
         }
        }     
     }

update AllOppty;
}
   


Test Class:- 

@istest(SeeAllData = true)
public with sharing class testupdateoppty{
 public static testMethod void TestdeletetonneageMethod() 
    {
      Opportunity op3 = new Opportunity(Name='Testoppthhhhhhssssde');
         
      op3.Bid_Date_Time__c = system.today();
      op3.CloseDate = system.today();
      op3.Market_Segment__c = 'Test1';
      op3.Stage_Structural__c = 'Planning';
      op3.State__c = 'AK';
      op3.City__c = 'Test';
      op3.Opportunity_Type__c = 'Test2';             
      op3.Referred_To__c = 'Test3';
      op3.Referred_From__c = 'Test4';
      op3.Sales_Office__c = 'Test6';
      op3.StageName = 'Planning';
      op3.Total_Loose_Dowel_Revenue__c = 1234;
      op3.Total_TBA_Revenue__c = 200000;
      op3.Total_Loose_Dowel_Revenue__c=1000;
      op3.Total_Loose_Dowel_Tons__c= 2000;
      op3.Dummy_Tonnage__c = 23 ;
      insert op3;
      
       Pricebook2 pb1 = [select Id from Pricebook2 where isStandard=true limit 1];                          
       Product2 prod1 = new Product2(Name = 'Loose Dowels123', ProductCode = 'LB');        
       insert prod1;
       
     
       
        PricebookEntry price = new PricebookEntry(
            
            Pricebook2Id = pb1.Id,
            UnitPrice = 1.0,
            IsActive = true,
            Product2Id = prod1.Id
            
            );
            insert price;
       
      
                 
      List<opportunityLineItem> opppro1 = new opportunitylineitem[]{new opportunitylineitem(UnitPrice=10000.00,
      Quantity=10,Total_Revenue__c = 10000.00, opportunityid=op3.id, pricebookEntryId=Price.id, Invoiced__c = TRUE)};
           
            insert opppro1;   
    
    op3.Dummy_Tonnage__c  = 50;
           update op3;
            
          Test.startTest();
           delete op3;
          Test.stopTest();
    }
}
 
Trigger:- 

 trigger CreateAttachment on Attachment (after insert, after update) {
        for(integer i =0; i<= Trigger.new.size();i++){
            try{
                ID refid = id.valueof(trigger.new[i].parentid);
                system.debug('xxxxxxxxxxxxxxxxxxxxxxxxx' + refid);
                Id Opportunity15 = string.valueof(trigger.new[i].parentid).substring(0,15);
                if (string.valueof(trigger.new[i].parentid).substring(0,3) == '006'){
                ID contractid = [SELECT id FROM CMC_Contract__c where OpportunityId__c =:  string.valueof(trigger.new[i].parentid).substring(0,15)].id;        
                    if(contractid != null){
                        Attachment ConAttachment = New Attachment(
                        Body = trigger.new[i].Body,
                        IsPrivate = trigger.new[i].IsPrivate,
                        ContentType = trigger.new[i].ContentType,
                        OwnerId = trigger.new[i].OwnerId,
                        Name = trigger.new[i].name,
                        parentid = contractid);
                        insert ConAttachment;

                    }
                }    
        
            } 
            catch(exception ex){
                system.debug('Exception' + ex);
            }
        }
    }

Test Class:- 

@isTest
public class CreateAttachmentTest {

    public static testMethod void Attachmentcreatemethod(){
        
        Test.startTest();
        Account act = new Account(Name='Test Acc');
        insert act;
        MHC2__Project__c proj = new MHC2__Project__c(Name='Test Project3');
        insert proj;
        List<CMC_Contract__c> conList = new List<CMC_Contract__c>();
        CMC_Contract__c c1 = new CMC_Contract__c();
        conList.add(c1);
        insert conList;       
        
        
        Opportunity op = new Opportunity(Name='My Test Opportunity5');
        op.Bid_Date_Time__c = System.Now().addDays(60);
        op.CloseDate = System.Now().addDays(30).date();
        op.StageName = 'Bidding';
        op.AccountId = act.Id;
        op.Bid_Type__c = 'Lump Sum';
        op.Project__c = proj.Id;
        insert op;
        
        Attachment attach=new Attachment();
        attach.Name='Unit Test Attachmnt';
        Blob bodyBlob1=Blob.valueOf('Unit Test Attachment Body1');
        attach.body=bodyBlob1;
        attach.parentId=op.id;
        insert attach;
        
        Test.stopTest();
        
    }
}

Lines highlighted in bold are not covered. i think i am missing to add some oppty id but not sure where it went wrong. Please comment your suggestions


Thanks,
Chandu
Hi,

I have multiple classes related to single object. some test classes covering code coverage upto 40 to 50 which doesn't have separate test class. my question is should i write test class again for every class or can use(call all classes) same test class for mutiple classes. Please help.
here is my class:-
public class CloneXmittal {
public ID transmittalid = ApexPages.currentPage().getParameters().get('transmittalid');
public ID ClonedTXid;
  public CloneXmittal(){}
  public void CloneXmittal1(){
        Transmittal__c TXOriginal = [Select id, Name,Addcontact__c,Bid_Due_Date__c,Change_Update_Sent__c,Contacts__c,Delivery_Method__c,Emaillist__c,FTP_Link__c,Opportunity__c,Requested_By__c,RFP_Sent_to_Vendor__c,Rownumber__c,Sales_Admin_Instructions__c,Structural_Fab_Misc_Vendor__c,Transmittal_Request_Date__c,Vendor_Instructions__c,Vendor_Proposal_Deadline__c,Vendor_Type__c from Transmittal__c where id =: transmittalid ];
        Transmittal__c TX = new Transmittal__c(
                                Addcontact__c=TXOriginal.Addcontact__c,
                                Contacts__c=TXOriginal.Contacts__c,
                         Delivery_Method__c=TXOriginal.Delivery_Method__c,
                                Emaillist__c=TXOriginal.Emaillist__c,
                                FTP_Link__c=TXOriginal.FTP_Link__c,
                                Opportunity__c=TXOriginal.Opportunity__c,
                                Requested_By__c=TXOriginal.Requested_By__c,
                                Rownumber__c=TXOriginal.Rownumber__c,                     Structural_Fab_Misc_Vendor__c=TXOriginal.Structural_Fab_Misc_Vendor__c,

 Vendor_Type__c=TXOriginal.Vendor_Type__c
                                );
                                insert TX;
                                ClonedTXid = TX.id;
        List<StructuralFab_Vendors__c> SFABLIST= new List<StructuralFab_Vendors__c>([Select ContactList__c, Transmittal__c, Account__c from StructuralFab_Vendors__c where Transmittal__c =:transmittalid  ]);
        List<StructuralFab_Vendors__c> SFABCLONE= new List<StructuralFab_Vendors__c>();
        for(StructuralFab_Vendors__c SFAB: SFABLIST){
             StructuralFab_Vendors__c SFABCOPY = SFAB.clone(false,true,false);
             SFABCOPY.Transmittal__c = TX.id;
            SFABCLONE.add(SFABCOPY );       
        }
        insert SFABCLONE;
        CloneXmittalDML();
}
public pagereference CloneXmittalDML(){
 PageReference home = new PageReference('/' + ClonedTXid );
        home.setRedirect(true);
return home;
}
}

test class:-

@isTest
public class CloneXmittalTest {
    
    static testMethod void test1(){
       Transmittal__c tr = new Transmittal__c();
        tr.Addcontact__c=false;
        tr.Delivery_Method__c='Email / Web';
        insert tr; 
        
        List<StructuralFab_Vendors__c> SFABCLONE= new List<StructuralFab_Vendors__c>();
        SFABCLONE[0].Transmittal__c = tr.Id;
        
        insert SFABCLONE;

        CloneXmittal cx = new CloneXmittal();
        cx.CloneXmittal1();
       
    }
}
public class Constant
    {  
        
         public static boolean recCheck = false;
        
    }
Hi,

In my org we have around 500 custom objects and they have some records(data). now my requirement is to get all those custom objects API names, record count of each object and last modified date of each record in object. to get record count of each object i am using (select count() from custom object name) 500 times. So, can i get this in a single shot into vf page or excel using query or Apex code? any suggestions? 
I am trying to fetch Duplicate Records based on certain field but hitting below error. Please help me if my query is wrong.

Query:-  SELECT MHC2__MHC_Project_ID__c, count(Id) FROM MHC2__Project__c GROUP BY MHC2__MHC_Project_ID__c HAVING count(Id)>1 limit 1000


Error:- EXCEEDED_ID_LIMIT: Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch

when i tried to get them to CSV then hitting below error

Failed: InvalidBatch : Failed to process query: FUNCTIONALITY_NOT_ENABLED: Aggregate Relationships not supported in Bulk Query


Thanks,
Chandra
here is my class:-
public class CloneXmittal {
public ID transmittalid = ApexPages.currentPage().getParameters().get('transmittalid');
public ID ClonedTXid;
  public CloneXmittal(){}
  public void CloneXmittal1(){
        Transmittal__c TXOriginal = [Select id, Name,Addcontact__c,Bid_Due_Date__c,Change_Update_Sent__c,Contacts__c,Delivery_Method__c,Emaillist__c,FTP_Link__c,Opportunity__c,Requested_By__c,RFP_Sent_to_Vendor__c,Rownumber__c,Sales_Admin_Instructions__c,Structural_Fab_Misc_Vendor__c,Transmittal_Request_Date__c,Vendor_Instructions__c,Vendor_Proposal_Deadline__c,Vendor_Type__c from Transmittal__c where id =: transmittalid ];
        Transmittal__c TX = new Transmittal__c(
                                Addcontact__c=TXOriginal.Addcontact__c,
                                Contacts__c=TXOriginal.Contacts__c,
                         Delivery_Method__c=TXOriginal.Delivery_Method__c,
                                Emaillist__c=TXOriginal.Emaillist__c,
                                FTP_Link__c=TXOriginal.FTP_Link__c,
                                Opportunity__c=TXOriginal.Opportunity__c,
                                Requested_By__c=TXOriginal.Requested_By__c,
                                Rownumber__c=TXOriginal.Rownumber__c,                     Structural_Fab_Misc_Vendor__c=TXOriginal.Structural_Fab_Misc_Vendor__c,

 Vendor_Type__c=TXOriginal.Vendor_Type__c
                                );
                                insert TX;
                                ClonedTXid = TX.id;
        List<StructuralFab_Vendors__c> SFABLIST= new List<StructuralFab_Vendors__c>([Select ContactList__c, Transmittal__c, Account__c from StructuralFab_Vendors__c where Transmittal__c =:transmittalid  ]);
        List<StructuralFab_Vendors__c> SFABCLONE= new List<StructuralFab_Vendors__c>();
        for(StructuralFab_Vendors__c SFAB: SFABLIST){
             StructuralFab_Vendors__c SFABCOPY = SFAB.clone(false,true,false);
             SFABCOPY.Transmittal__c = TX.id;
            SFABCLONE.add(SFABCOPY );       
        }
        insert SFABCLONE;
        CloneXmittalDML();
}
public pagereference CloneXmittalDML(){
 PageReference home = new PageReference('/' + ClonedTXid );
        home.setRedirect(true);
return home;
}
}

test class:-

@isTest
public class CloneXmittalTest {
    
    static testMethod void test1(){
       Transmittal__c tr = new Transmittal__c();
        tr.Addcontact__c=false;
        tr.Delivery_Method__c='Email / Web';
        insert tr; 
        
        List<StructuralFab_Vendors__c> SFABCLONE= new List<StructuralFab_Vendors__c>();
        SFABCLONE[0].Transmittal__c = tr.Id;
        
        insert SFABCLONE;

        CloneXmittal cx = new CloneXmittal();
        cx.CloneXmittal1();
       
    }
}
i want to make my visualforce component Read only when Case object status changed to Closed. i know we have Read only attribute in VF Page. do we have this in VF component too?
How to write a trigger code with handler class to copy few field value from one object (A)to another object (B) ?


Condition :1
Object A

picklist Field : Subodh            Salary =5000
picklist Field : Subodh             Salary =7000

Object B 
picklist Field : Subodh       Total Salary :12000

Condition : 2

Object : A

picklist Field : Subodh             Salary =7000
picklist Field : Rahul                Salary =7000
picklist Field : Amit                  Salary =5000
picklist Field : Rahul                Salary =7000
picklist Field : Amit                   Salary =5000


Object : B

picklist Field : Subodh            Total Salary =7000
picklist Field : Rahul               Total Salary =14000
picklist Field : Amit                  Total Salary =10000


Thanks
Subodh

Hi,

As I have an issue :
I have to populate the count of one object which have related as follow::

    Seesion Issue----(Child of Session Object)
                      Session ------(Parent of Session Issue and Middle Issue)
                                    Middle Issue------(Parent of Section Issue)
                                           section Issue()-------Accounts(parent of Section Issue)

Hi,

I have a custom object named "Sales Order", would like to save object record as pdf on save under Files related list of the Sales Order.

Provision to format the pdf record with HTML/CSS and restricting the fields to get saved is highly desirable.

Can some one help with available options for me.

Thanks,
Prasanth

 
I'm fresher , i would like to do a administrator certification, since i'm new i dont know the procedure and also about that can anyone help me ?

SELECT Id, (SELECT Name from Contacts WHERE CreatedDate > YESTERDAY or LastModifiedDate >  YESTERDAY) from Account where CreatedDate > YESTERDAY or LastModifiedDate > YESTERDAY

I want to get all records from Account and Contact where created date or last modified date is within a certain range. If there are changes in Contact , I want those records , even there are no changes in Account Object 

But this query will not fetch any records if there are any change in only Contact and no change in Account. How can I possibly do that.

Can anybody please help.

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger ProjectDuplicateCheck caused an unexpected exception, contact your administrator: ProjectDuplicateCheck: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.ProjectDuplicateCheck: line 11, column 1

Trigger:-
trigger ProjectDuplicateCheck on MC2__Project__c (before insert,before update) {
   
    Set<String> setProjId = new Set<String>();
    For(MC2__Project__c mp : trigger.new)
    {
        setProjId.add(mp.MC2__MC_Project_ID__c);
    }
    
    if(setProjId.size() > 0 )
    { 
        List<MC2__Project__c> lstproject = [select MC2__MC_Project_ID__c,id from MC2__Project__c where MC2__MC_Project_ID__c!=null AND MC2__MC_Project_ID__c in:setProjId];
        
        
        Map<String,MC2__Project__c> Projmap = new Map<String,MC2__Project__c>();
        For(MC2__Project__c mhp: lstproject)
        {
            Projmap.put(mhp.MC2__MC_Project_ID__c,mhp);
        }
        
        For(MC2__Project__c mhp : trigger.new)
        {
            if(Projmap.containsKey(mhp.MC2__MC_Project_ID__c))
            {
                mhp.MC2__MC_Project_ID__c.addError('Project Id already exists, Please create project with new Project Id');
            }
        } 
      }
}
I am doing some modifications to existing test class and removed SeeAllData=true(for best practise). now i am getting below error. So, now i want to know whether SeeAllData=true when we are using Pricebook object in test class.

Error:-

System.QueryException: List has no rows for assignment to SObject

errored line from test class:-
Pricebook2 pb = [select Id from Pricebook2 where isStandard=true limit 1]; 
Getting System.DMLException in test class for below trigger. Please help me to solve it.

Trigger:- 

trigger OpportunityHowell on Opportunity (after Insert,after Update) {
   
  List<Opportunity> listOpportunitiesToUpdate = new List<Opportunity>();
  Set<Id> allOids = new Set<Id>();
  for(Opportunity o: Trigger.new){
    if(o.Multiplier__c != null && o.Multiplier__c != trigger.oldMap.get(o.id).Multiplier__c){
      allOids.add(o.id);
    }
  }
  listOpportunitiesToUpdate = [select id, (SELECT Id,Dollar_Sales_Howell__c from OpportunityLineItems) from Opportunity where id in :allOids];
  for(Opportunity o:listOpportunitiesToUpdate){
    o.Sum_of_Dollar_Sales_Howell__c = 0;
    for(OpportunityLineItem oli: o.OpportunityLineItems)
    Try{
      o.Sum_of_Dollar_Sales_Howell__c += oli.Dollar_Sales_Howell__c;
      }
    Catch(Exception e)
    {
  }
  if(listOpportunitiesToUpdate.size()>0)   
    update listOpportunitiesToUpdate;    
    }
  }

Test class:-

@isTest
public class OpportunityHowellTest {

    public static testMethod void TestOppty(){
        
         Set<Id> allOids = new Set<Id>();
         MHC2__Project__c p = new MHC2__Project__c(Name='Test Project',MHC2__MHC_Project_Bid_Date__c=System.Today(),MHC2__MHC_Target_Bid_Date__c=System.Today());
        insert p;
        Account a = new Account(Name='Test Account');
        insert a;
        
        Opportunity op = new Opportunity();
        op.Name = 'My Test Opportunity';
        op.Multiplier__c = 2;
        op.Sum_of_Dollar_Sales_Howell__c = 0;
        op.Bid_Date_Time__c = System.Now().addDays(30);
        op.CloseDate = System.Now().addDays(45).date();
        op.StageName = 'Bidding';
        op.AccountId = a.Id;
        op.Bid_Type__c = 'Lump Sum';
        op.Project__c = p.Id;
        insert op;
        
        op.Multiplier__c = 5;
        
        update op;
     
        
       OpportunityLineItem oli = new OpportunityLineItem();
        oli.Quantity = 1.0;
        oli.OpportunityId = op.Id;
        oli.Invoiced__c = false;
        insert oli; 
  }
}

Error:-

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityHowell: execution of AfterInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.OpportunityHowell: line 6, column 1: []
Hi,

I am able to cover Trigger.IsInsert & Trigger.IsUpdate but Trigger.IsDelete is not covering. Please check below test class and provide your suggestions.

Trigger:-
trigger CMC_Post_Tention_Weight_Rollup on OpportunityLineItem (after Insert, After Delete, After Update) 
{
Product2 productPostTensionWeight = [select id, name From Product2 where name = 'Post tension'];
    
if(trigger.isInsert)
{
List <OpportunityLineItem> postTensionWeight = trigger.new; //for update/Insert    
List<Id> listOptyIds = new List<Id>(); 
for(OpportunityLineItem eachOptyLineItem : PostTensionWeight ) 
    {
    listOptyIds.add(eachOptyLineItem.OpportunityId); 
    }

List <Opportunity> AllOppty = [Select ID, Name, Total_Post_Tension_Weight__c  from Opportunity 
                               where id in: listOptyIds];
for(Opportunity opty:AllOppty)
    {
    for(OpportunityLineItem PTW : postTensionWeight)
        {
          
        if(PTW.Product2Id == productPostTensionWeight.Id && PTW.OpportunityId == opty.Id)
            {   
            Opty.Total_Post_Tension_Weight__c = Opty.Total_Post_Tension_Weight__c + PTW.Post_Tension_Weight__c;   
            
            }
         }    
     }
update AllOppty;
}

if(trigger.isDelete)
{
List <OpportunityLineItem> postTensionWeight = trigger.Old; //for Delete    
List<Id> listOptyIds = new List<Id>(); 
for(OpportunityLineItem eachOptyLineItem : PostTensionWeight ) 
    {
    listOptyIds.add(eachOptyLineItem.OpportunityId); 
    }

List <Opportunity> AllOppty = [Select ID, Name, Total_Post_Tension_Weight__c  from Opportunity 
                               where id in: listOptyIds];
for(Opportunity opty:AllOppty)
    {
    for(OpportunityLineItem PTW : postTensionWeight)
        {
      
        if(PTW.Product2Id == productPostTensionWeight.Id && PTW.OpportunityId == opty.Id)
            {
           Opty.Total_Post_Tension_Weight__c = Opty.Total_Post_Tension_Weight__c - PTW.Post_Tension_Weight__c;   
            
            }
         }    
     }

update AllOppty;
}

if(trigger.isUpdate)
{
List <OpportunityLineItem> postTensionWeight = trigger.New;
List <OpportunityLineItem> OldpostTensionWeight = trigger.Old;    
List<Id> listOptyIds = new List<Id>(); 
for(OpportunityLineItem eachOptyLineItem : PostTensionWeight ) 
    {
    listOptyIds.add(eachOptyLineItem.OpportunityId); 
    }

List <Opportunity> AllOppty = [Select ID, Name, Total_Post_Tension_Weight__c  from Opportunity 
                               where id in: listOptyIds];
for(Opportunity opty:AllOppty)
    {
    for(OpportunityLineItem PTW : postTensionWeight)
        {
        For(OpportunityLineItem OPTW : OldpostTensionWeight)
        {        
        if(PTW.Product2Id == productPostTensionWeight.Id && PTW.OpportunityId == opty.Id && PTW.ID==OPTW.ID)
            {
      
            Opty.Total_Post_Tension_Weight__c = Opty.Total_Post_Tension_Weight__c - OPTW.Post_Tension_Weight__c + PTW.Post_Tension_Weight__c;   
            
            }
         }
        }     
     }

update AllOppty;
}
   


Test Class:- 

@istest(SeeAllData = true)
public with sharing class testupdateoppty{
 public static testMethod void TestdeletetonneageMethod() 
    {
      Opportunity op3 = new Opportunity(Name='Testoppthhhhhhssssde');
         
      op3.Bid_Date_Time__c = system.today();
      op3.CloseDate = system.today();
      op3.Market_Segment__c = 'Test1';
      op3.Stage_Structural__c = 'Planning';
      op3.State__c = 'AK';
      op3.City__c = 'Test';
      op3.Opportunity_Type__c = 'Test2';             
      op3.Referred_To__c = 'Test3';
      op3.Referred_From__c = 'Test4';
      op3.Sales_Office__c = 'Test6';
      op3.StageName = 'Planning';
      op3.Total_Loose_Dowel_Revenue__c = 1234;
      op3.Total_TBA_Revenue__c = 200000;
      op3.Total_Loose_Dowel_Revenue__c=1000;
      op3.Total_Loose_Dowel_Tons__c= 2000;
      op3.Dummy_Tonnage__c = 23 ;
      insert op3;
      
       Pricebook2 pb1 = [select Id from Pricebook2 where isStandard=true limit 1];                          
       Product2 prod1 = new Product2(Name = 'Loose Dowels123', ProductCode = 'LB');        
       insert prod1;
       
     
       
        PricebookEntry price = new PricebookEntry(
            
            Pricebook2Id = pb1.Id,
            UnitPrice = 1.0,
            IsActive = true,
            Product2Id = prod1.Id
            
            );
            insert price;
       
      
                 
      List<opportunityLineItem> opppro1 = new opportunitylineitem[]{new opportunitylineitem(UnitPrice=10000.00,
      Quantity=10,Total_Revenue__c = 10000.00, opportunityid=op3.id, pricebookEntryId=Price.id, Invoiced__c = TRUE)};
           
            insert opppro1;   
    
    op3.Dummy_Tonnage__c  = 50;
           update op3;
            
          Test.startTest();
           delete op3;
          Test.stopTest();
    }
}
 
Trigger:- 

 trigger CreateAttachment on Attachment (after insert, after update) {
        for(integer i =0; i<= Trigger.new.size();i++){
            try{
                ID refid = id.valueof(trigger.new[i].parentid);
                system.debug('xxxxxxxxxxxxxxxxxxxxxxxxx' + refid);
                Id Opportunity15 = string.valueof(trigger.new[i].parentid).substring(0,15);
                if (string.valueof(trigger.new[i].parentid).substring(0,3) == '006'){
                ID contractid = [SELECT id FROM CMC_Contract__c where OpportunityId__c =:  string.valueof(trigger.new[i].parentid).substring(0,15)].id;        
                    if(contractid != null){
                        Attachment ConAttachment = New Attachment(
                        Body = trigger.new[i].Body,
                        IsPrivate = trigger.new[i].IsPrivate,
                        ContentType = trigger.new[i].ContentType,
                        OwnerId = trigger.new[i].OwnerId,
                        Name = trigger.new[i].name,
                        parentid = contractid);
                        insert ConAttachment;

                    }
                }    
        
            } 
            catch(exception ex){
                system.debug('Exception' + ex);
            }
        }
    }

Test Class:- 

@isTest
public class CreateAttachmentTest {

    public static testMethod void Attachmentcreatemethod(){
        
        Test.startTest();
        Account act = new Account(Name='Test Acc');
        insert act;
        MHC2__Project__c proj = new MHC2__Project__c(Name='Test Project3');
        insert proj;
        List<CMC_Contract__c> conList = new List<CMC_Contract__c>();
        CMC_Contract__c c1 = new CMC_Contract__c();
        conList.add(c1);
        insert conList;       
        
        
        Opportunity op = new Opportunity(Name='My Test Opportunity5');
        op.Bid_Date_Time__c = System.Now().addDays(60);
        op.CloseDate = System.Now().addDays(30).date();
        op.StageName = 'Bidding';
        op.AccountId = act.Id;
        op.Bid_Type__c = 'Lump Sum';
        op.Project__c = proj.Id;
        insert op;
        
        Attachment attach=new Attachment();
        attach.Name='Unit Test Attachmnt';
        Blob bodyBlob1=Blob.valueOf('Unit Test Attachment Body1');
        attach.body=bodyBlob1;
        attach.parentId=op.id;
        insert attach;
        
        Test.stopTest();
        
    }
}

Lines highlighted in bold are not covered. i think i am missing to add some oppty id but not sure where it went wrong. Please comment your suggestions


Thanks,
Chandu
Hi,

I have multiple classes related to single object. some test classes covering code coverage upto 40 to 50 which doesn't have separate test class. my question is should i write test class again for every class or can use(call all classes) same test class for mutiple classes. Please help.
here is my class:-
public class CloneXmittal {
public ID transmittalid = ApexPages.currentPage().getParameters().get('transmittalid');
public ID ClonedTXid;
  public CloneXmittal(){}
  public void CloneXmittal1(){
        Transmittal__c TXOriginal = [Select id, Name,Addcontact__c,Bid_Due_Date__c,Change_Update_Sent__c,Contacts__c,Delivery_Method__c,Emaillist__c,FTP_Link__c,Opportunity__c,Requested_By__c,RFP_Sent_to_Vendor__c,Rownumber__c,Sales_Admin_Instructions__c,Structural_Fab_Misc_Vendor__c,Transmittal_Request_Date__c,Vendor_Instructions__c,Vendor_Proposal_Deadline__c,Vendor_Type__c from Transmittal__c where id =: transmittalid ];
        Transmittal__c TX = new Transmittal__c(
                                Addcontact__c=TXOriginal.Addcontact__c,
                                Contacts__c=TXOriginal.Contacts__c,
                         Delivery_Method__c=TXOriginal.Delivery_Method__c,
                                Emaillist__c=TXOriginal.Emaillist__c,
                                FTP_Link__c=TXOriginal.FTP_Link__c,
                                Opportunity__c=TXOriginal.Opportunity__c,
                                Requested_By__c=TXOriginal.Requested_By__c,
                                Rownumber__c=TXOriginal.Rownumber__c,                     Structural_Fab_Misc_Vendor__c=TXOriginal.Structural_Fab_Misc_Vendor__c,

 Vendor_Type__c=TXOriginal.Vendor_Type__c
                                );
                                insert TX;
                                ClonedTXid = TX.id;
        List<StructuralFab_Vendors__c> SFABLIST= new List<StructuralFab_Vendors__c>([Select ContactList__c, Transmittal__c, Account__c from StructuralFab_Vendors__c where Transmittal__c =:transmittalid  ]);
        List<StructuralFab_Vendors__c> SFABCLONE= new List<StructuralFab_Vendors__c>();
        for(StructuralFab_Vendors__c SFAB: SFABLIST){
             StructuralFab_Vendors__c SFABCOPY = SFAB.clone(false,true,false);
             SFABCOPY.Transmittal__c = TX.id;
            SFABCLONE.add(SFABCOPY );       
        }
        insert SFABCLONE;
        CloneXmittalDML();
}
public pagereference CloneXmittalDML(){
 PageReference home = new PageReference('/' + ClonedTXid );
        home.setRedirect(true);
return home;
}
}

test class:-

@isTest
public class CloneXmittalTest {
    
    static testMethod void test1(){
       Transmittal__c tr = new Transmittal__c();
        tr.Addcontact__c=false;
        tr.Delivery_Method__c='Email / Web';
        insert tr; 
        
        List<StructuralFab_Vendors__c> SFABCLONE= new List<StructuralFab_Vendors__c>();
        SFABCLONE[0].Transmittal__c = tr.Id;
        
        insert SFABCLONE;

        CloneXmittal cx = new CloneXmittal();
        cx.CloneXmittal1();
       
    }
}
Hi,

We had a known issue, described here: https://success.salesforce.com/issues_view?id=a1p3A000001RXBZQA4 related to the performance in API versions 44 and 45.

Now, the issue status says "FIXED - SUMMER '19". Does it mean that we have to switch our classes from 44 and 45 to API 46 (Summer'19)?
I assume that "FIXED" means that old versions should work correctly and there is no need for any actions from our site. Unfortunately, in case of performance issue, it is not easy to verify it on our own.
Could anyone explain how exactly Salesforce deals with these  changes?

Many thanks,
Jakub
public class Constant
    {  
        
         public static boolean recCheck = false;
        
    }
Hey,
(I'm pretty new to SF so I'm sorry if what I'm posting is posted as the wrong topic)

Question:
I'm trying to log in to a Sandbox environment in my org but I can't get past the verification step. SF tries to send a verification code to my mail according to this format:
firstname.lastname@orgname.se.invalid
The part that says ".invalid" is not part of my real mail meaning the code gets sent somewhere that isn't my e-mail inbox. 
How do I get past this?
Thanks in advance for help!:)