• sandeep kumar 44
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies
URGENT : I am getting an error in apex class i am trying to insert oppurtunity and line items .

ERROR : System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry currency code does not match opportunity currency code): [PricebookEntryId]: 

Apex Class : public class UpdateOpptyLineItems{
    public static void UpdateLineItems(List<OpportunityLineItem> oliList,Double ExportQuantity,string Operation){
        List<OpportunityLineItem> oliListToBeUpdated = new List<OpportunityLineItem>();        
        Date PreviousDate = System.Today();
        Date CurrentDate = System.Today();
        Map<Date,List<OpportunityLineItem>> dateFinalOli = new Map<Date,List<OpportunityLineItem>>();
        for(OpportunityLineItem oli:oliList){
            if(dateFinalOli.containsKey(Date.ValueOf(oli.ServiceDate))){
                dateFinalOli.get(Date.ValueOf(oli.ServiceDate)).add(oli);
            }
            else{
                List<OpportunityLineItem> oliList1 = new List<OpportunityLineItem>();
                oliList1.add(oli);
                dateFinalOli.put(Date.ValueOf(oli.ServiceDate),oliList1);
            }
        }
        system.debug('dateFinalOli : ' + dateFinalOli);        
        for(Date dt:dateFinalOli.KeySet()){
            Integer i=0;
            for(OpportunityLineItem oli:dateFinalOli.get(dt)){                
                if(oli.Tipo__c == '1.Estoque Inicial'){                     
                    if(i != 0){
                        if(Operation == 'Remove'){
                            oliListToBeUpdated.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity - ExportQuantity, TotalPrice = oli.TotalPrice));       
                        }
                        if(Operation == 'Add'){
                            oliListToBeUpdated.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity + ExportQuantity, TotalPrice = oli.TotalPrice));       
                        }
                    }
                }                        
                if(oli.Tipo__c == '6.Estoque Final'){    
                    if(Operation == 'Remove'){
                        oliListToBeUpdated.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity - ExportQuantity,TotalPrice = oli.TotalPrice ));
                    }
                    if(Operation == 'Add'){
                        oliListToBeUpdated.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity + ExportQuantity,TotalPrice = oli.TotalPrice));
                    }
                }       
                i++;    
            }
        }
        system.debug('Final OLI List : ' + oliListToBeUpdated);
        if(!oliListToBeUpdated.isEmpty()){
            update oliListToBeUpdated;
        }
    }
    public static void UpsertLineItems(List<Opportunity> oppImportFinalRec,Integer StartingMonth,Id pbID,Double ImportQuantity, Decimal UnitPrice){
        List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
        List<OpportunityLineItem> oliListInsert = new List<OpportunityLineItem>();
        Map<Date,List<OpportunityLineItem>> dateFinalOli = new Map<Date,List<OpportunityLineItem>>();
        for(OpportunityLineItem oli:oppImportFinalRec[0].OpportunityLineItems){
            if(dateFinalOli.containsKey(Date.ValueOf(oli.ServiceDate))){
                dateFinalOli.get(Date.ValueOf(oli.ServiceDate)).add(oli);
            }
            else{
                List<OpportunityLineItem> oliList1 = new List<OpportunityLineItem>();
                oliList1.add(oli);
                dateFinalOli.put(Date.ValueOf(oli.ServiceDate),oliList1);
            }
        }       
        system.debug('dateFinalOli : ' + dateFinalOli); 
        for(Integer I=StartingMonth;i<=12;i++){
            Date ServiceDate = Date.newInstance(oppImportFinalRec[0].CloseDate.Year(), I, 1);
            System.debug('ServiceDate : ' + ServiceDate);
            if(dateFinalOli.containsKey(ServiceDate)){
                for(OpportunityLineItem oli:dateFinalOli.get(ServiceDate)){
                    if(oli.Tipo__c == '1.Estoque Inicial'){
                        if(I!= StartingMonth){
                            oliList.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity + ImportQuantity));
                        }
                    }
                    if(oli.Tipo__c == '6.Estoque Final'){
                        oliList.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity + ImportQuantity));
                    }
                }
            }
            else{           
                if(I!= StartingMonth){
                    oliListInsert.add(new OpportunityLineItem(ServiceDate = ServiceDate,PriceBookEntryId = pbID,OpportunityId = oppImportFinalRec[0].Id,Tipo__c = '1.Estoque Inicial',Quantity = ImportQuantity,UnitPrice = UnitPrice));
                }           
                oliListInsert.add(new OpportunityLineItem(ServiceDate = ServiceDate,PriceBookEntryId = pbID,OpportunityId = oppImportFinalRec[0].Id,Tipo__c = '6.Estoque Final',Quantity = ImportQuantity,UnitPrice = UnitPrice));
            }
        }
        system.debug(' Update List : ' + oliList);
        system.debug(' Insert List : ' + oliListInsert);
        if(!oliList.isEmpty()){
            update oliList;
        }
        if(!oliListInsert.isEmpty()){
            insert oliListInsert;
        }
    }
    public static void InsertLineItems(Integer StartingMonth,string OppID, Id pbID,Double ImportQuantity, Decimal UnitPrice){
        List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
        for(Integer I=StartingMonth;i<=12;i++){
            if(I!= StartingMonth){
                oliList.add(new OpportunityLineItem(PriceBookEntryId = pbID,OpportunityId = OppID,Tipo__c = '1.Estoque Inicial',Quantity = ImportQuantity,UnitPrice = UnitPrice));
            }
            oliList.add(new OpportunityLineItem(PriceBookEntryId = pbID,OpportunityId = OppID,Tipo__c = '6.Estoque Final',Quantity = ImportQuantity,UnitPrice = UnitPrice));
        }
        if(!oliList.isEmpty()){
           insert oliList;
       }   
    
    }
    public static Id InsertOpportunity(Id pbID,string AccountName,string AccountID,string RegionID,string RegionName,string MainYear,string ImportRegionOwner){
        ID recTypeOppPadrao = RecordTypeMemory.getRecType( 'Opportunity', 'Padrao' );
        Periodo_da_Oportunidade__c po = Periodo_da_Oportunidade__c.getInstance();
        system.debug(po.Periodo_Aberto_Ate__c);
        Database.saveresult insOpp;
        String oppName = '';
        oppName += AccountName;
        oppName += ' - '+ MainYear;
        oppName += ' - ' + RegionName;
        Opportunity opp = new Opportunity();
        opp.RecordTypeId = recTypeOppPadrao;
        opp.Name = oppName;
        opp.Owner = new User (Id = ImportRegionOwner);
        opp.AccountID = AccountID;
        opp.CloseDate = Date.ValueOf(po.Periodo_Aberto_Ate__c); 
        opp.Pricebook2Id  = pbID;
        //opp.CloseDate = System.today() + 90;   
        opp.StageName = 'RFC';
        opp.Micro_Regiao_Principal__c = RegionID;       
        insOpp = (Test.isRunningTest()) ? null : Database.insert(opp);
        return insOpp.getId();
    }   
}
hello all,

i am working on a visualforce page and i want to replace the dot in decimal with comma can and one help me please .

<apex:column headerValue="Preço de lista">
<apex:outputText value="{!oliWrapper.price}" id="unitPrice"/>
</apex:column>

Thanks in Advance

 
hello i have written below batch class but when its running its giving an error : System.StringException: Invalid id: u.id at line number 16

global class batchleadUpdate implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
   
    User u = [select Id from User where Profile.Name='System Administrator' Limit 1];
   
        String query = 'SELECT Id,Name,Status ,OwnerId  FROM Lead WHERE Status != \'Closed - Converted\' AND CreatedDate < LAST_N_DAYS:30';
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext BC, List<Lead> scope)
    {
         for(Lead le : scope)
         {
             le.OwnerId = 'u.Id'  ;           
         }
         update scope;
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

can any one help me by telling what i did wrong . will be of great help
Thanks all
hello all ,

i need a urgent help with an issue in my org i have a trigger which creates chield records for oppurtunity object and i have a test calss for it . we have activated multi currency in the org and i added Currency Iso Code field in trigger for inserting the object .

trigger is running fien but the code coverage become zero. below is my trigger and test class please help .

test class :

trigger TrgCreateSales on Opportunity (after update,after insert)
{
    for (Opportunity a : Trigger.New)
    {
   
    if(CheckFirstRun.firstRun)
    {
        if(a.StageName=='Closed Won')
        {
       
        list<sale__c> salesobj=new list<sale__c>();
        sale__c objsales=new sale__c();
       
        salesobj =[Select Id from sale__c where Opportunity_Name__c=:a.id];
       
        if(salesobj.size()<=0)
        {
               
             salesobj =[Select Id from sale__c where Opportunity_Name__c=:a.id all rows];
             system.debug('TEstTarUn '+ salesobj);
           
           
            if(salesobj.size()>0)
            {
             system.debug('Undelete '+ salesobj);
             undelete salesobj;
            }
            else
            {
                system.debug('Insert '+ salesobj);
               
                objsales.Opportunity_Name__c=a.id;
                objsales.text_area__c='';
                 insert objsales;
               
               
               
                //create sales split base upon opprtunity team member
                 list<Opportunity_Member__c> lsttmopp= [select id,Employee__c from Opportunity_Member__c where Opportunity_to_Member__c=:a.id];
                
                
                 list<Sales_Split__c> lstspkut=new list<Sales_Split__c>();
                
                 for(Opportunity_Member__c objoteammem : lsttmopp)
                 {
                     Sales_Split__c ssplit=new Sales_Split__c();
                     ssplit.sale__c=objsales.id;
                     ssplit.Employee__c=objoteammem.Employee__c ;
                     lstspkut.add(ssplit);
                 }
                 insert lstspkut;
             }
         }
         else
         {
        
             list<Sales_Split__c> objsalesplit= new list<Sales_Split__c>();
             objsalesplit=[Select Id from Sales_Split__c where sale__c=:salesobj[0].id];
             if(objsalesplit.size()<=0)
             {
                     //create sales split base upon opprtunity team member
                 list<Opportunity_Member__c> lsttmopp= [select id,Employee__c from Opportunity_Member__c where Opportunity_to_Member__c=:a.id];
                
                
                 list<Sales_Split__c> lstspkut=new list<Sales_Split__c>();
                
                 for(Opportunity_Member__c objoteammem : lsttmopp)
                 {
                     Sales_Split__c ssplit=new Sales_Split__c();
                     ssplit.sale__c=salesobj[0].id;
                     ssplit.Employee__c=objoteammem.Employee__c ;
                     lstspkut.add(ssplit);
                 }
                 insert lstspkut;
             }
             else
             {
            
             }
         }
      }
        else
        {
           
                sale__c salesobj1=new sale__c();
                try
                {
                 salesobj1=[select id from sale__c where Opportunity_Name__c=:a.id];
                            
                 delete salesobj1;
                
                }
                catch(exception e)
                {
                }
               
        }
       
        }
    }
}

test class :

@isTest
private class TestClassCreateSales
{
    static testMethod void testSales()
    {
    try
    {
        //Test 1 - Sale created before the update
        Opportunity objopp=new Opportunity();
        objopp.Name='Test1';
        objopp.CloseDate=Date.today().adddays(5);
        objopp.StageName='Low Interest';
        objopp.CurrencyIsoCode = 'ARS';
        insert objopp;
       
        sale__c objsales1=new sale__c();
        objsales1.Opportunity_Name__c  =objopp.id;
        objsales1.CurrencyIsoCode = objopp.CurrencyIsoCode;
        insert objsales1;
       
        Employee__c empobj = new Employee__c();
        empobj.Name = 'emptest';
        insert empobj;
       
        Opportunity_Member__c objmember1=new Opportunity_Member__c();
        objmember1.Opportunity_to_Member__c=objopp.id;
        objmember1.Employee__c = empobj.Name;
        objmember1.Role__c = 'Leader';
        insert objmember1;
       
        objopp.StageName='Closed Won';
        update objopp;
       
        // Test 2 - Sale created by the trigger
        Opportunity objopp1=new Opportunity();
        objopp1.Name='Test21';
        objopp1.CloseDate=Date.today().adddays(5);
        objopp1.StageName='Closed Lost';
        objopp1.CurrencyIsoCode = 'ARS';
        insert objopp1;
       
        Opportunity_Member__c objmember=new Opportunity_Member__c();
        objmember.Opportunity_to_Member__c=objopp1.id;
        objmember1.Employee__c = empobj.Name;
        objmember1.Role__c = 'Leader';
        insert objmember;
       
        objopp1.StageName='Closed Won';
        Update objopp1;
       
        // Test 3 - Undelete
        Opportunity objopp2=new Opportunity();
        objopp2.Name='Test22';
        objopp2.CloseDate=Date.today().adddays(5);
        objopp2.StageName='Low Interest';
        objopp2.CurrencyIsoCode = 'BRL';
        insert objopp2;
       
        Opportunity_Member__c objmember2=new Opportunity_Member__c();
        objmember2.Opportunity_to_Member__c=objopp2.id;
        objmember2.Employee__c = empobj.Name;
        objmember2.Role__c = 'Leader';
        insert objmember2;
       
        sale__c objsales2=new sale__c();
        objsales2.Opportunity_Name__c  =objopp2.id;
        objsales2.CurrencyIsoCode = objopp2.CurrencyIsoCode;
        insert objsales2;
       
        delete objsales2;
       
        objopp2.StageName = 'Closed Won';
        update objopp2;
       
        }
        catch(exception e)
        {
        }
       
       
    }
   
}

thanks in advance
Hello All,

we have a mobile application which is build in Titanium. what i am trying to do is to integrate the mobile app with salesforce. 

can any one explain how this works ?

emaple :  i created a account in mobile application and i want to push this data into salesforce account.

Thanks in advance 
hello all

i am working on a trigger in which i need to show an alret massege before deleting the record . how can i do it

{
      
            sale__c salesobj1=new sale__c();
            try
            {
            salesobj1=[select id from sale__c where Opportunity_Name__c=:a.id];
          
            delete salesobj1;
            }
            catch(exception e)
            {}
        }
    }
}

before salesobj1 gets deleted in need to show the alert massege to user and then let him save
URGENT : I am getting an error in apex class i am trying to insert oppurtunity and line items .

ERROR : System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry currency code does not match opportunity currency code): [PricebookEntryId]: 

Apex Class : public class UpdateOpptyLineItems{
    public static void UpdateLineItems(List<OpportunityLineItem> oliList,Double ExportQuantity,string Operation){
        List<OpportunityLineItem> oliListToBeUpdated = new List<OpportunityLineItem>();        
        Date PreviousDate = System.Today();
        Date CurrentDate = System.Today();
        Map<Date,List<OpportunityLineItem>> dateFinalOli = new Map<Date,List<OpportunityLineItem>>();
        for(OpportunityLineItem oli:oliList){
            if(dateFinalOli.containsKey(Date.ValueOf(oli.ServiceDate))){
                dateFinalOli.get(Date.ValueOf(oli.ServiceDate)).add(oli);
            }
            else{
                List<OpportunityLineItem> oliList1 = new List<OpportunityLineItem>();
                oliList1.add(oli);
                dateFinalOli.put(Date.ValueOf(oli.ServiceDate),oliList1);
            }
        }
        system.debug('dateFinalOli : ' + dateFinalOli);        
        for(Date dt:dateFinalOli.KeySet()){
            Integer i=0;
            for(OpportunityLineItem oli:dateFinalOli.get(dt)){                
                if(oli.Tipo__c == '1.Estoque Inicial'){                     
                    if(i != 0){
                        if(Operation == 'Remove'){
                            oliListToBeUpdated.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity - ExportQuantity, TotalPrice = oli.TotalPrice));       
                        }
                        if(Operation == 'Add'){
                            oliListToBeUpdated.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity + ExportQuantity, TotalPrice = oli.TotalPrice));       
                        }
                    }
                }                        
                if(oli.Tipo__c == '6.Estoque Final'){    
                    if(Operation == 'Remove'){
                        oliListToBeUpdated.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity - ExportQuantity,TotalPrice = oli.TotalPrice ));
                    }
                    if(Operation == 'Add'){
                        oliListToBeUpdated.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity + ExportQuantity,TotalPrice = oli.TotalPrice));
                    }
                }       
                i++;    
            }
        }
        system.debug('Final OLI List : ' + oliListToBeUpdated);
        if(!oliListToBeUpdated.isEmpty()){
            update oliListToBeUpdated;
        }
    }
    public static void UpsertLineItems(List<Opportunity> oppImportFinalRec,Integer StartingMonth,Id pbID,Double ImportQuantity, Decimal UnitPrice){
        List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
        List<OpportunityLineItem> oliListInsert = new List<OpportunityLineItem>();
        Map<Date,List<OpportunityLineItem>> dateFinalOli = new Map<Date,List<OpportunityLineItem>>();
        for(OpportunityLineItem oli:oppImportFinalRec[0].OpportunityLineItems){
            if(dateFinalOli.containsKey(Date.ValueOf(oli.ServiceDate))){
                dateFinalOli.get(Date.ValueOf(oli.ServiceDate)).add(oli);
            }
            else{
                List<OpportunityLineItem> oliList1 = new List<OpportunityLineItem>();
                oliList1.add(oli);
                dateFinalOli.put(Date.ValueOf(oli.ServiceDate),oliList1);
            }
        }       
        system.debug('dateFinalOli : ' + dateFinalOli); 
        for(Integer I=StartingMonth;i<=12;i++){
            Date ServiceDate = Date.newInstance(oppImportFinalRec[0].CloseDate.Year(), I, 1);
            System.debug('ServiceDate : ' + ServiceDate);
            if(dateFinalOli.containsKey(ServiceDate)){
                for(OpportunityLineItem oli:dateFinalOli.get(ServiceDate)){
                    if(oli.Tipo__c == '1.Estoque Inicial'){
                        if(I!= StartingMonth){
                            oliList.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity + ImportQuantity));
                        }
                    }
                    if(oli.Tipo__c == '6.Estoque Final'){
                        oliList.add(new OpportunityLineItem(Id = oli.Id,Quantity = oli.Quantity + ImportQuantity));
                    }
                }
            }
            else{           
                if(I!= StartingMonth){
                    oliListInsert.add(new OpportunityLineItem(ServiceDate = ServiceDate,PriceBookEntryId = pbID,OpportunityId = oppImportFinalRec[0].Id,Tipo__c = '1.Estoque Inicial',Quantity = ImportQuantity,UnitPrice = UnitPrice));
                }           
                oliListInsert.add(new OpportunityLineItem(ServiceDate = ServiceDate,PriceBookEntryId = pbID,OpportunityId = oppImportFinalRec[0].Id,Tipo__c = '6.Estoque Final',Quantity = ImportQuantity,UnitPrice = UnitPrice));
            }
        }
        system.debug(' Update List : ' + oliList);
        system.debug(' Insert List : ' + oliListInsert);
        if(!oliList.isEmpty()){
            update oliList;
        }
        if(!oliListInsert.isEmpty()){
            insert oliListInsert;
        }
    }
    public static void InsertLineItems(Integer StartingMonth,string OppID, Id pbID,Double ImportQuantity, Decimal UnitPrice){
        List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
        for(Integer I=StartingMonth;i<=12;i++){
            if(I!= StartingMonth){
                oliList.add(new OpportunityLineItem(PriceBookEntryId = pbID,OpportunityId = OppID,Tipo__c = '1.Estoque Inicial',Quantity = ImportQuantity,UnitPrice = UnitPrice));
            }
            oliList.add(new OpportunityLineItem(PriceBookEntryId = pbID,OpportunityId = OppID,Tipo__c = '6.Estoque Final',Quantity = ImportQuantity,UnitPrice = UnitPrice));
        }
        if(!oliList.isEmpty()){
           insert oliList;
       }   
    
    }
    public static Id InsertOpportunity(Id pbID,string AccountName,string AccountID,string RegionID,string RegionName,string MainYear,string ImportRegionOwner){
        ID recTypeOppPadrao = RecordTypeMemory.getRecType( 'Opportunity', 'Padrao' );
        Periodo_da_Oportunidade__c po = Periodo_da_Oportunidade__c.getInstance();
        system.debug(po.Periodo_Aberto_Ate__c);
        Database.saveresult insOpp;
        String oppName = '';
        oppName += AccountName;
        oppName += ' - '+ MainYear;
        oppName += ' - ' + RegionName;
        Opportunity opp = new Opportunity();
        opp.RecordTypeId = recTypeOppPadrao;
        opp.Name = oppName;
        opp.Owner = new User (Id = ImportRegionOwner);
        opp.AccountID = AccountID;
        opp.CloseDate = Date.ValueOf(po.Periodo_Aberto_Ate__c); 
        opp.Pricebook2Id  = pbID;
        //opp.CloseDate = System.today() + 90;   
        opp.StageName = 'RFC';
        opp.Micro_Regiao_Principal__c = RegionID;       
        insOpp = (Test.isRunningTest()) ? null : Database.insert(opp);
        return insOpp.getId();
    }   
}
hello all,

i am working on a visualforce page and i want to replace the dot in decimal with comma can and one help me please .

<apex:column headerValue="Preço de lista">
<apex:outputText value="{!oliWrapper.price}" id="unitPrice"/>
</apex:column>

Thanks in Advance

 
Hi All,

Is there a way around the error 'DML not supported for Folder' in a testMethod? This is being a real problem for me because it's preventing me from getting the 75% coverage I need for this class.

One thing I tried is using test code that tries to find one existing Folder object and using that. Like this:

        Folder[] folder = [SELECT Id FROM Folder LIMIT 1];

This works in development, but when I install the package that this code belongs to, I get this error mesage, and the install fails:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: FolderId (invalid folder): [FolderId]

Any help would be appreciated.

 

Andrew