• max.alexander1.3945796734965325E12
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 8
    Replies
HI,
Ihave following code
public class generateBundle {

  public static void generate(Set<Id> Ids) {
  set<id> BundleProductsIds = new set<id>();
  set<id> Products = new set<id>();
  set<id> Pricebookentry = new set<id>();
  map<id, PriceBookentry> myMap = new map<id, PriceBookentry>();
  map<id,Bundle__c> BundleMap = new map <id,Bundle__c>();
  map<id,OpportunityLineItem>  OpportunityMap = new map<id,OpportunityLineitem>();
  List<OpportunityLineItem> Opportunityli = new List<OpportunityLineItem>();
  
  
  
List<opportunityLineItem> lineItem = [select id, product2id,OpportunityId,TotalPrice from Opportunitylineitem where id in:ids];
      for(OpportunityLineitem oli : lineItem) {
        Products.add(oli.product2id );
        OpportunityMap.put(oli.id, oli);
    
}



List <Bundle__c> Bundle =[select id,IncludeIntheBundle__c,PriceBook__c,Bundle__c,Weight__c, BundleProductID__c  from Bundle__c where IncludeIntheBundle__c IN :Products];
  
        for(Bundle__c Bp : Bundle) {
        BundleProductsIds.add(bp.BundleProductID__c);
        BundleMap.put(bp.id, bp);
}
    
List<PriceBookentry> pbeids = [Select id,product2id, pricebook2id from priceBookentry where product2id in: BundleProductsIds and isActive= TRUE  ];
        for(PriceBookentry pbe : pbeids) {
        Pricebookentry.add(pbe.id);
      
        myMap.put(pbe.id,pbe );
  
}


    
                                OpportunityLI.add(New OpportunityLIneitem
                                   (
                                   Opportunityid=OpportunityMap.get(oli.id).Opportunityid,
                                   PriceBookEntryid=myMap.get(pbe.id).id,
                                   Quantity=1,
                                   totalPrice= (BundleMap.get(bp.id).Weight__c)/100*OpportunityMap.get(oli.id).totalPrice
                                    ));
    
    
    
    
    insert    OpportunityLI; 

}

  }

Idea behind is this
if a user selects special product form the list, thathas 2 or more other products attached to it via Junction it shoudl add those product in as well.
error i get with it is
Error: Compile Error: Variable does not exist: oli.id at line 43 column 69

however if i nest for loop with SOQL querries it works, but creates multiple items instead of one, and it is not bulk safe anyway, any help great appreciated
HI I have following VF page 
<apex:page StandardController="Opportunity" extensions="DeleteOpportunityLIneItems" action="{!Autorun}"  >

</apex:page>

it called controller
public class DeleteOpportunityLIneItems {

    Opportunity oli;

    public DeleteOpportunityLIneItems(ApexPages.StandardController stdController){
    
        this.oli = (Opportunity)stdController.getRecord();

    } 
       
    public PageReference autoRun() {
        
        OpportunityLineItem[] objsToDelete = [SELECT id FROM OpportunityLIneItem WHERE Opportunityid = :this.oli.id];
           


        delete objsToDelete;
            
        PageReference pageRef = new PageReference('/' + Oli.id);
        pageRef.setRedirect(true);
        return pageRef;
        }  
    }

this controller deletes all Opportunity Line items, ti works just fin, is there any way i can add a prompt to ask user Are yo USure you want to delete?
If they say yes then Delete if they say No then go back to the Opportunity page, i tried numebr us thisng but i cna get th eprobpt appear stright away, i moves me to VF page with command button then it prompts me if i'm sure, is ther any way to go directly to prompt and hten execute controller?
I have this piece of code that does roll up summary on relatd object for Opportunity called deal__c, however i get this error and i'm not sure why.
here is my code   Trigger.Deals: line 59, column 1, is there any way to overcome it by writing beter querry? or do ihave to create batch class? or put it @ future?

set<id> DealIds = new set<id>(); //roll up summary
    if((trigger.isInsert || trigger.isUpdate) && Trigger.isAfter){
        for(Opportunity o : trigger.new){
            DealIds.add(o.Deal__c);
        }
    }

    if(trigger.isDelete){
        for(Opportunity o : trigger.old){
            DealIds.add(o.Deal__c);
        }
    }

            map<id, Decimal> DealAmountMap = new map<id, Decimal>();
            List<AggregateResult> oList =[select Deal__c,sum(Amount) from Opportunity where Deal__c IN :DealIds group by Deal__c];
            for(AggregateResult q : oList){
                DealAmountMap.put((Id)q.get('Deal__c'),(Double)q.get('expr0'));
            }
   
            map<id, Decimal> DealQuantityMap = new map<id, Decimal>();
            List<AggregateResult> oList1 =[select Deal__c,sum(TotalOpportunityQuantity) from Opportunity where Deal__c IN :DealIds group by Deal__c];
            for(AggregateResult q1 : oList1){
                DealQuantityMap.put((Id)q1.get('Deal__c'),(Double)q1.get('expr0'));
            }

                    list<Deal__c> dealsToUpdate = new list<Deal__c>();
                    List<Deal__c> Deals=[Select Id, TotalAmount__c from Deal__c where Id IN :DealIds];
                    for(Deal__c d : Deals){
                        Double PaymentSum = DealAmountMap.get(d.Id);
                        Double Quantity = DealQuantityMap.get(d.id);
                        d.TotalAmount__c = PaymentSum;
                        d.TotalOpportunityQuantity__c= Quantity;
                        dealsToUpdate.add(d);
                    }
    update dealsToUpdate;
HI, 
has anyone ever integrated CyberSell with salesforce?
if yes any tips on how to go abou it?
HI have follwing code, it has a queerry inside a for loop, however  if i take it out  i cannot refference the date fields orrectlyher eis the code any help greatly appreciated.



trigger UpdatePeriod on Revenue__c (before insert, before update) {
    set<Date> Ids = new set<Date>();
    map<date, Id> myMap = new map<date, Id>();
    for(revenue__c r : trigger.new) {
       
  for(Period__c p: [SELECT Id FROM Period__c WHERE (Start_Date__c <= :r.Date__c and End_Date__c >= :r.Date__c) ]) {
        myMap.put(r.Date__c,p.id);
    }
    }
   
   
    for(Revenue__c r : Trigger.new) {
       
           
            r.Period__c = myMap.get(r.Date__c);
       
    }
}
HI,
I need ot edit all contacts in related lists using VF script, i got one of the site but it only does selected ones, is htere a way to select all of the contacts
here is code

<apex:page standardController="Contact" recordSetVar="unused" sidebar="false">
<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlock >
Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first.
</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Return" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selected}"  var="a" id="table">
<apex:column headerValue="Name">
<apex:inputField value="{!a.Name}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!a.Phone}"/>
</apex:column>
<apex:column headerValue="Mobile Phone">
<apex:inputField value="{!a.MobilePhone}"/>
</apex:column>
<apex:column headerValue="Email">
<apex:inputField value="{!a.Email}"/>
</apex:column>
<apex:column headerValue="Title">
<apex:inputField value="{!a.Title}"/>
</apex:column>
<apex:column headerValue="Account">
<apex:inputField value="{!a.AccountId}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputField value="{!a.Description}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
HI I have following VF page 
<apex:page StandardController="Opportunity" extensions="DeleteOpportunityLIneItems" action="{!Autorun}"  >

</apex:page>

it called controller
public class DeleteOpportunityLIneItems {

    Opportunity oli;

    public DeleteOpportunityLIneItems(ApexPages.StandardController stdController){
    
        this.oli = (Opportunity)stdController.getRecord();

    } 
       
    public PageReference autoRun() {
        
        OpportunityLineItem[] objsToDelete = [SELECT id FROM OpportunityLIneItem WHERE Opportunityid = :this.oli.id];
           


        delete objsToDelete;
            
        PageReference pageRef = new PageReference('/' + Oli.id);
        pageRef.setRedirect(true);
        return pageRef;
        }  
    }

this controller deletes all Opportunity Line items, ti works just fin, is there any way i can add a prompt to ask user Are yo USure you want to delete?
If they say yes then Delete if they say No then go back to the Opportunity page, i tried numebr us thisng but i cna get th eprobpt appear stright away, i moves me to VF page with command button then it prompts me if i'm sure, is ther any way to go directly to prompt and hten execute controller?
HI have follwing code, it has a queerry inside a for loop, however  if i take it out  i cannot refference the date fields orrectlyher eis the code any help greatly appreciated.



trigger UpdatePeriod on Revenue__c (before insert, before update) {
    set<Date> Ids = new set<Date>();
    map<date, Id> myMap = new map<date, Id>();
    for(revenue__c r : trigger.new) {
       
  for(Period__c p: [SELECT Id FROM Period__c WHERE (Start_Date__c <= :r.Date__c and End_Date__c >= :r.Date__c) ]) {
        myMap.put(r.Date__c,p.id);
    }
    }
   
   
    for(Revenue__c r : Trigger.new) {
       
           
            r.Period__c = myMap.get(r.Date__c);
       
    }
}