• Sunay
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 10
    Replies

Hi I have written a Apex trigger for inserting opportunity line items and it is working fine. But the only issue is I am not able to insert more than 15 records in one shot. Please Help me!!

 

The code is as below:

 

trigger OppportunityProductInsert on Opportunity (after Insert, after Update ) {

Integer Num =1;
For (Integer I = 0; I < Num; I++)
For (Opportunity a : Trigger.new)
if (a.RecordTypeId=='01290000000UUr2' && (a.Number_of_Resources__c-a.Total_Number_of_Opportunity_Products__c)>0)
{
Product2 Prod = [select Id from Product2 limit 1 ];
Pricebook2 PB = [select Id from Pricebook2 where IsActive=True  limit 1 ];
PricebookEntry P = [select Id from PricebookEntry where CurrencyIsoCode=:a.CurrencyIsoCode And Pricebook2Id=:PB.Id limit 1 ]; 
OpportunityLineItem OppLI = new OpportunityLineItem (OpportunityId=a.id, UnitPrice=0, Quantity =1, PricebookEntryId=P.Id);
Insert OppLI;
}
}

 

  • May 26, 2011
  • Like
  • 0

Hi,

 

I am trying to integrate sales force with Oracle ERP, hence I need help on this how to integrate using API coding as I am new to this integration.

 

Please find the details below:

 

I am trying to push accounts, contacts, opportunities and quotes into oracle. Since the order has to be generated from oracle, the required details from sales force has to be pushed. But I understand that oracle ERP has different tables which is referred by a single field or ID, hence I need help on how to go about this and do the integration using API codes.

 

Also I need help on how to give the sequences/validations while inserting the data.

 

Please help me regarding this!!!

 

Regards,

Sunay

  • May 26, 2011
  • Like
  • 0

Hi,

 

I need help on building a trigger to add the line items automatically based on a field, where the number is mentioned. As per that number the line items is created automatically. Please find the code for reference which I am working on:

 

trigger OpportunityProductInsert on Opportunity (after insert, after update){

                //USE DESCRIBE METHODS INSTEAD OF SOQL TO GET RECORDTYPEIDS. HELPS IN REDUCING DMLS

 

    Schema.DescribeSObjectResult d = Schema.SObjectType.Opportunity;

    Map<String,Schema.RecordTypeInfo> rtMapByName = d.getRecordTypeInfosByName();

    Id oppRTID = rtMapByName.get('Insert Opp RecordTypeName Here').getRecordTypeId();

//USE MAPS AND LIST TO HOLD DATA

Map<Id,String> currencyisocodemap = new Map<Id, String>();                

    for(Opportunity o :Trigger.new){

                if(o.CurrencyISOCode!=null){

                                currencyisocode.put(o.id, o.CurrencyISOCode);

                }

 

 

    }

//USE RELATIONSHIP QUERIES TO REDUCE SOQLS

 

List<PricebookEntry> pbe = [select Id, CurrencyISOCode from PriceBookEntry where CurrencyISOCode in :currencysiocodemap.keyset() and Pricebook2.isActive = true];

 

Map<String,String> isomap = new Map<String, String>();

 

for(PricebookEntry p  :pbe){

                isomap.put(p.CurrencyISOCode. p.Id);

 

}

 

List<OpportunityLineItem> oppline = new List<OpportunityLineItem>();

 

    for(Opportunity o :Trigger.new){

                //USE LISTS TO HOLD RECORDS BEFORE DOING 'BULK' INSERT

                If(o.N__c>0 && o.RecordTypeId==OppRTId){

                                oppLine.add(new OpportunityLineItem(OpportunityId = o.id, UnitPrice = 0, Quantity = 1, PricebookEntryId = isomap.get(o.CurrencyISOCode));

 

 

 

 

                }

 

 

 

    }

//INSERT OUTSIDE FOR LOOP. BULK INSERT. REDUCE DMLS

if(oppline.size()!=0) insert oppline;

 

}

  • May 03, 2011
  • Like
  • 0

Hi I have written a Apex trigger for inserting opportunity line items and it is working fine. But the only issue is I am not able to insert more than 15 records in one shot. Please Help me!!

 

The code is as below:

 

trigger OppportunityProductInsert on Opportunity (after Insert, after Update ) {

Integer Num =1;
For (Integer I = 0; I < Num; I++)
For (Opportunity a : Trigger.new)
if (a.RecordTypeId=='01290000000UUr2' && (a.Number_of_Resources__c-a.Total_Number_of_Opportunity_Products__c)>0)
{
Product2 Prod = [select Id from Product2 limit 1 ];
Pricebook2 PB = [select Id from Pricebook2 where IsActive=True  limit 1 ];
PricebookEntry P = [select Id from PricebookEntry where CurrencyIsoCode=:a.CurrencyIsoCode And Pricebook2Id=:PB.Id limit 1 ]; 
OpportunityLineItem OppLI = new OpportunityLineItem (OpportunityId=a.id, UnitPrice=0, Quantity =1, PricebookEntryId=P.Id);
Insert OppLI;
}
}

 

  • May 26, 2011
  • Like
  • 0

Hi,

 

I am trying to integrate sales force with Oracle ERP, hence I need help on this how to integrate using API coding as I am new to this integration.

 

Please find the details below:

 

I am trying to push accounts, contacts, opportunities and quotes into oracle. Since the order has to be generated from oracle, the required details from sales force has to be pushed. But I understand that oracle ERP has different tables which is referred by a single field or ID, hence I need help on how to go about this and do the integration using API codes.

 

Also I need help on how to give the sequences/validations while inserting the data.

 

Please help me regarding this!!!

 

Regards,

Sunay

  • May 26, 2011
  • Like
  • 0