• Ankit Kumar 169
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Create a Vf page Which displays Accounts Name and related contact[Picklist] in a table format and Having a button in the last Column ""Delete"".It will delete the account and all the contacts related to the account."
Apex code ::
public class Trg11HelperClass {
    public static void addLineItem(List<Opportunity> opList){
        
            if(opList.Size()>0){
    List<OpportunityLineItem> Oli = [select Description,ListPrice,Name,OpportunityId from 
                                     OpportunityLineItem where  OpportunityId IN : opList];
                 
              for(Opportunity op:opList){
                  Integer count =0;
              for(OpportunityLineItem o:oli)  {
                 
                  count++;
                
                }  
                  if(count > 2){
                        op.addError('opportunity cannot be closed');
                           } 
                
            }
        }
    }
}

Trigger::

trigger Trg11 on Opportunity (after insert) {
    if(trigger.isUpdate)
Trg11HelperClass.addLineItem(Trigger.new);
}
My Code is : 

public class PriceBookController {
    public PriceBookController(){
        
        Pricebook2  p = new Pricebook2();
        p.name='Lenovo Pricebook2';
        p.Description ='Pricebook with All product and Price';
        p.IsActive = true;
        insert p;

        
       List<Product2> proList = new List<Product2>(); 
        
        for(Integer i =0 ;i<10;i++){ 
            Product2 pro = new Product2();            
            pro.Name = 'Lenovo'+ i; 
                       
            proList.add(pro); 
        } 
        insert proList;
         
        Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];
        PricebookEntry standardPBE = new PricebookEntry(Pricebook2Id = standardPB.Id, Product2Id = proList[0].Id, UnitPrice = 1000, IsActive = true);
        insert standardPBE;
      
        PricebookEntry  pb = new PricebookEntry();
        pb.IsActive =true;
        pb.Pricebook2Id =p.id;
        pb.UseStandardPrice =false;   
        pb.UnitPrice =5001;
        pb.Product2Id=proList[0].Id;
        
        insert pb;

        }
           
        
        }
        
    NOTE :  It is only assign one product with standard pricebook and custom pricebook and for rest of the product they will not assign anything.
Create a Vf page Which displays Accounts Name and related contact[Picklist] in a table format and Having a button in the last Column ""Delete"".It will delete the account and all the contacts related to the account."
User Object has Records and Custom Object[Emp] has no records in it. User object has records in it, so we can't create a master detail relation.Created lookup relation, Then try to convert look up to master by clicking on change field type there is no master detail option to select.
emp Object has below fields.
User-added image