• sfdeveloper12
  • NEWBIE
  • 70 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 27
    Questions
  • 30
    Replies
hi,

How to create trigger which will create new order product when order is created or edited. Order product whcih we are going to inser will be quote line item on the quote object of order.
Hoe is this possible?
Hello,

My client created Professional Edition Sandbox but i want to create Coding stuff on this account. I want to change my existing Professional Edition Org into enterprise Edition. Is there any way to upgrade Professional edition org to Enterprise Edition?

Thanks & Best Regards,
Utkarsha
Hi, 
I have written Account sharing and delete sharing record for custom field. Its giving me following error. Account has "Private" acess in OWD.

Account {"Party_Sea_ID__c":3618,"Customer_Number__c":"C0354","Name":"LUXURY BRAND HOLDINGS INC.","DBA_Name__c":"LUXURY BRAND HOLDINGS","Customer_Group_Id__c":"a0028000015lr6gAAA","OwnerId":"00528000005HQRPAA4","owner1__c":"00528000003iGolAAE","Terms_Id__c":"a042800000oV27IAAS","Default_Currency__c":"US DOLLARS","Industry":"Jewelry","Website":"www.luxurybrandholdings.com","No_of_Doors__c":14,"NumberOfEmployees":0,"Store_Size__c":0,"Contact_Person__c":"0","Rolex_Dealer__c":"Y","Status__c":1,"Sales_Code__c":"ASSET AND MEMO","RecordTypeId":"01228000000QbiR","Asset_Credit_Limit__c":1000000.0,"Memo_Credit_Limit__c":1500000.0,"Outstanding_A_R_Balance__c":0.0,"Outstanding_Memo_Balance__c":0.0,"BillingStreet":"9 ROSS SIMONS DRIVE - 2920 , , ","BillingPostalCode":"2920"} Delete_Share: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00r28000020W8ELAA0; first error: DELETE_FAILED, cannot delete owner or rule share rows, id=00r28000020W8EL: [] Trigger.Delete_Share: line 89, column 1


Code is as below.
trigger Delete_Share on Account (before update) {
    
/*set<Id> AccountIDs = new Set<Id>();
for(Account a: trigger.new){
    
    //System.debug('Account IDs: '+ a.id);
    
  AccountIDs.add(a.id);
}
List<AccountShare> jobShares = new List<AccountShare>();

map<String,AccountShare>accountShareMap = new Map<String,AccountShare>();

for(AccountShare accShare : [select AccountId, UserOrGroupId,AccountAccesslevel,OpportunityAccessLevel from AccountShare where AccountId in :AccountIds])
{
 accountShareMap.put(String.valueOf(accShare.UserOrGroupId),accShare);

}

 
// for(Account a1 : trigger.new){
// Account oldAccount = Trigger.OldMap.get(a1.id);
// if(jobShares.isEmpty() == false ){

 //delete jobShares;
 //}
//}

for(Account a : trigger.new){
Account oldAccount = Trigger.OldMap.get(a.id);
    
    system.debug('old account:' + oldaccount);
    
if ((a.owner1__c != oldAccount.owner1__c) && (a.ownerId != oldAccount.owner1__c)){
    
    System.debug('Account: '+ a);
    
   AccountShare accountRecord = accountShareMap.get(string.valueOf(oldAccount.owner1__c)); 
    if (accountRecord  != null){
  jobShares.add(accountRecord);
    }
  }
 }

if(jobShares.isEmpty() == false ){ 
    //if(!jobShares.isEmpty()){
    delete jobShares;
    System.debug('deleted successfully...');
 
 } */



set<Id> AccountIDs = new Set<Id>();
for(Account a: trigger.new){
AccountIDs.add(a.id);
}
List<AccountShare> jobShares = new List<AccountShare>();

map<String,AccountShare>accountShareMap = new Map<String,AccountShare>();

for(AccountShare accShare : [select AccountId, UserOrGroupId from AccountShare where AccountId in :AccountIds])
{
 accountShareMap.put(String.valueOf(accShare.UserOrGroupId),accShare);

}

 
// for(Account a1 : trigger.new){
// Account oldAccount = Trigger.OldMap.get(a1.id);
// if(jobShares.isEmpty() == false ){

 //delete jobShares;
 //}
//}

for(Account a : trigger.new){
Account oldAccount = Trigger.OldMap.get(a.id);
if (((a.owner1__c != oldAccount.owner1__c) && (a.ownerId != oldAccount.ownerId)) || ((a.owner1__c !=oldAccount.owner1__c)  && (a.OwnerId ==oldAccount.OwnerId))  || ((a.owner1__c == oldAccount.owner1__c)  && (a.OwnerId != oldAccount.OwnerId))){
 
   AccountShare accountRecord = accountShareMap.get(string.valueOf(oldAccount.owner1__c)); 
    if (accountRecord  != null)
    jobShares.add(accountRecord);
  }
 }

if(jobShares.isEmpty() == false ){

 delete jobShares;
 }
 }

Can anybody please tell me why is this happening? Its working fine when i change Owner field manually in the salesforce. But i am using SEA to Salesforce integration where all data gets inserted throgh SEA. Its give me above error while transferring the data.

Thanks & Regards,
Utkarsha

 
Hello, 

I have written trigger where i have created custom field which has lookup to user. I am using standard owner field as well as custom field both are lookup to user. The thing is i am transferring all the data from SEA to Salesforce. SEA is integrated with salesforce. Account sharing is working well on salesforce but not when owner is changed from SEA. I am not getting exact solution to recover this issue. This problem is for one of the user which is deactivated from salesforce. So is it possible that trigger wont work for deactivated user ? but if i make changes from salesforce org then it works fine. 

My trigger is as below and i dont feel there is any problem in trigger.

trigger Account_Share on Account (after insert,after update) {

 List<AccountShare> jobShares = new List<AccountShare>();
    
 for(Account a : trigger.new){

if (a.owner1__c != null) {
 
   

   AccountShare accountRecord = new AccountShare();
   accountRecord.AccountId= a.Id;
    
   
   System.Debug('************* Account ID ******* '+a.Id);
   accountRecord.UserOrGroupId = a.owner1__c;
   System.Debug('************* Account ID ******* '+ a.owner1__c);
    
  
   accountRecord.AccountAccessLevel= 'edit';
   accountRecord.OpportunityAccessLevel='Read';
  System.debug('Acc_share_trigger Account Record: '+ accountRecord);
    
    
 // studentRecord.RowCause = Schema.Test_Share.RowCause.Student_Access__c;
   jobShares.add(accountRecord);
 }  

 /** Insert all of the newly created Share records and capture save result **/
 Database.SaveResult[] jobShareInsertResult = Database.insert(jobShares,false);

}
}

Thanks & Regards,
Utkarsha
Hello,

I am using visualforce page and apex controller to update csv file in my salesforce org. My code is working for any text or picklist value. but not for checkbox, lookup or date field. As i am using string in my code i need some conversion. I have tried Date.valueOf() and Date.Parse() but its not show any data. My code is as below.

public class importDataFromCSVController {

    public importDataFromCSVController(ApexPages.StandardController controller) {

    }

 
  public Blob csvFileBody{get;set;}
  public String csvAsString{get;set;}
  public String[] csvFileLines{get;set;}
  public List<Guests_Delegate__c> gdlist{get;set;}

  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    gdlist= New List<Guests_Delegate__c>(); 
  }
  
  public void importCSVFile(){
       try{
              // Read CSV file body and store it in variable
              csvAsString = csvFileBody.toString();
     
             // Split CSV String to lines
             csvFileLines = csvAsString.split('\n'); 
           
             // Iterate CSV file lines and retrieve one column at a time.
             for(Integer i=1; i < csvFileLines.size(); i++){
               Guests_Delegate__c gdObj = new Guests_Delegate__c() ;
               String[] csvRecordData = csvFileLines[i].split(',');
              // gdObj.Account__c= csvRecordData[0] ;             
              // 
              // gdObj.Occupancy__c= csvRecordData[2];
              
               gdObj.Allowances__c= csvRecordData[0];
               gdObj.Notes__c= csvRecordData[1];
              // gdObj.Booking__c= csvRecordData[2];
               gdObj.Number_Plate__c= csvRecordData[2];
               gdObj.Room_Type__c= csvRecordData[3];
               gdObj.Occupancy__c= csvRecordData[4];
               gdObj.Meal_Plan__c= csvRecordData[5];
               System.debug('gdObj.Meal_Plan__c'+gdObj.Meal_Plan__c);
               gdObj.Work_Phone__c= csvRecordData[6];
               
               //gdObj.Reconciled_by_Finance__c= Boolean.ValueOf('csvRecordData[6]');

            //  gdObj.Departure_Date__c=  Date.valueOf(csvRecordData[6]);
              // System.debug('Departure Date'+gdObj.Departure_Date__c);

               
              // gdObj.Sharing_With__c= csvRecordData[6];
            //   gdObj.Reconciled_by_Finance__c= csvRecordData[6];

                                                                                           
               gdlist.add(gdObj);   
             }
             // if all correct then insert Account into Org
             
             if(gdlist.size()>0)
               insert gdlist;
        }
        catch (Exception e)
        {


VF Page:
 <apex:page controller="importDataFromCSVController"  sidebar="false" showHeader="false">
    <apex:form >
        <apex:pagemessages />
        <apex:pageBlock >
            <apex:pageBlockSection columns="4"> 
                  <apex:inputFile value="{!csvFileBody}"  filename="{!csvAsString}"/>
                  <apex:commandButton value="Import G & D into Salesforce" action="{!importCSVFile}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock >
           <apex:pageblocktable value="{!gdlist}" var="gd">
              <apex:column value="{!gd.Allowances__c}" />
              <apex:column value="{!gd.Notes__c}" />
              <apex:column value="{!gd.Number_Plate__c}" />
              <apex:column value="{!gd.Room_Type__c}" />
              <apex:column value="{!gd.Occupancy__c}" />
              <apex:column value="{!gd.Meal_Plan__c}" />
              <apex:column value="{!gd.Work_Phone__c}" />
             
             


             <!-- 
              <apex:column value="{!gd.Reconciled_by_Finance__c}" />
              <apex:column value="{!gd.Departure_Date__c}" />

              <apex:column value="{!gd.Sharing_With__c}" />

              <apex:column value="{!gd.Booking__c}" />
              <apex:column value="{!gd.Id}" />
              <apex:column value="{!gd.Room_Type__c}" />
              <apex:column value="{!gd.Arrival_Date__c }" /> -->
              
        </apex:pageblocktable>
     </apex:pageBlock>
   </apex:form>
</apex:page>

Thanks & Regards,
Utkarsha
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importing data into Salesforce. Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}
Hello,

trigger UpdateAgreedRate on QuoteLineItem (before insert, before update) {
 system.debug('****************InTrigger**********************');
    
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        String QuoteID ;
        set<id> PIds = new set<id>();

        for (QuoteLineItem childObj : Trigger.new) {
            if(QuoteID == null) {
               QuoteID  = childObj.QuoteID;
            }
            if(childObj.Product2Id != null){
                PIds.add(childObj.Product2Id);
            }
            
        
        system.debug('QuoteID 18 -->'+QuoteID  );
        
            if(QuoteID  != null) {
               
              List<Quote> quotes = [select Id, AccountId, Venue__c, Opportunity.Guest_Name__r.Name from Quote where Id =:QuoteID  ]; 
               if(quotes.size() > 0) {
                   Quote QuoteDetails = quotes[0];
                   
                   system.debug('QuoteDetails 26 -->'+QuoteDetails );
                   
                    for (QuoteLineItem item : Trigger.new) {
                    system.debug('item 29 -->'+item );
                      
                   item.Guest1__c= quotes[0].Opportunity.Guest_Name__r.Name;

                for(Product2 product :[select id, name from Product2 where Id IN : PIds]){
                 system.debug('product 33 -->'+product );


      
 
           
for(Rates_Commissions__c rate: [select id, Name, Product_Item__c, Client_Account__c, Venue_Hotel__c , Agreed_Rate__c, AgreedRes__c from Rates_Commissions__c   where Product_Item__c =: product.id])
    {
    
      system.debug('rate 42 -->'+rate ); 
      if(rate.Product_Item__c == product.id && quotes[0].AccountId == rate.Client_Account__c && quotes[0].Venue__c == rate.Venue_Hotel__c)
                   {          
                       system.debug('ProductId-->'+product.id  );
                       system.debug('RateProductItem-->'+rate.Product_Item__c  );
                       system.debug('QuoteAccId-->'+quotes[0].AccountId  );
                       system.debug('RateAccId-->'+rate.Client_Account__c  );
                       system.debug('QuoteVenueHotel-->'+quotes[0].Venue__c  );
                       system.debug('RateVenueHotel-->'+rate.Venue_Hotel__c  );


              item.PSL_Rate__C =  rate.Agreed_Rate__c ;
              item.Commission_Percentage_PSL__c = rate.AgreedRes__c;
               system.debug('rate.Agreed_Rate__c -->'+ rate.Agreed_Rate__c );
               system.debug(' rate.AgreedRes__c -->'+ rate.AgreedRes__c );


            }
            

    }
              }
             } 
            }
              }             
            } 
            
            
        }        
        
         if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
         for(QuoteLineItem o : Trigger.new)
         {
        if(o.PSL_Rate__C < o.Online_Rate__c)
        {
        o.Recommended_Sales_Price__c=  o.PSL_Rate__C;
        }
        else if(o.Online_Rate__c < o.PSL_Rate__C){
         o.Recommended_Sales_Price__c=  o.Online_Rate__c ;
        }
        else if(o.Online_Rate__c == null || o.Online_Rate__c == 0 ){
         o.Recommended_Sales_Price__c=  o.PSL_Rate__C;
        }
        else if(o.PSL_Rate__C == 0 || o.PSL_Rate__C == null)
        {
         o.Recommended_Sales_Price__c=  o.Online_Rate__c ;
        }
        

        }
        }
    }

My code is hitting governor limit exception. Can anybody help me to resolve this issue

Thanks,
Utkarsha
Hello,
I want to create automatic opportuinty line item when opportunity is created. How is this possible. I want to create of particular Product name suppose "Accomodation". I have written a code. 
trigger insertOppLineItem on Opportunity (after insert, after update) {
 system.debug('****************InTrigger**********************');
    
    if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate)){
        String OpportunityID ;
        
    for(Opportunity o : Trigger.new){ 
        system.debug('OpportunityID 8 -->'+o.Id);
        OpportunityID = o.Id;
    
        if(OpportunityID  != null) 
        {
            List<Opportunity> opp = [select Id , No_of_Nights__c from Opportunity where ID =:  OpportunityID  ]; 
               system.debug('Opportunity 14.......... -->'+opp );

          //  List<OpportunityLineItem> vList = new List<OpportunityLineItem >();
           for(OpportunityLineItem v : trigger.new){
            o.No_of_Nights__c = v.Quantity;
        
                //vList.add(v);          
             }
               

        } 
        upsert v; 
    }   
}
}


How is this achivable?


Thanks &Regards,
Utkarsha
Hello,

I am creating a formula field where i am taking minimum value form Online Rate field or PSL rate field.
This is possible using min funcion or in if condition by comparing two values.

Next thing is. If PSL rate is blank then Online rate value should be populated in my formula field. '
If Online rate is blank then Psl rate should be populate in formula filed.

OR(IF(ISNULL(PSL_Rate__c), PSL_Rate__c, Online_Rate__c),IF(ISNULL(Online_Rate__c), Online_Rate__c, PSL_Rate__c))

I used this . But its giving me an error expexcted boolean received number. I have to show whatever will be value in this field. I cant keep it as boolean. What to do now?

Best Regards,
Utkarsha
Hello,

I am writing a code where i am almost done. but i dont know how to get rid of this error. I want to compare accounts on quote object and one of the object which is child object (rate and commision) of product object. When this 2 are same then i want to update field on rate and commision object on quote line item object. can anyone help me with this?
trigger UpdateAgreedRate on QuoteLineItem (before insert, before update) {
 system.debug('****************InTrigger**********************');
    
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        String QuoteID ;
        set<id> PIds = new set<id>();


        for (QuoteLineItem childObj : Trigger.new) {
            if(QuoteID == null) {
               QuoteID  = childObj.QuoteID;
            }
            if(childObj.Product2Id != null){
                PIds.add(childObj.Product2Id);
            }
            
        }
        system.debug('QuoteID 19 -->'+QuoteID  );
        
            if(QuoteID  != null) {
               
              List<Quote> quotes = [select Id, AccountId, Venue__c from Quote where Id =:QuoteID  ];
               if(quotes.size() > 0) {
                   Quote QuoteDetails = quotes[0];
                   
                   system.debug('QuoteDetails 26 -->'+QuoteDetails );
                   
                    for (QuoteLineItem item : Trigger.new) {
                    system.debug('item 29 -->'+item );
                      
                      


                for(Product2 product :[select id, name from Product2 where Id IN : PIds]){
                 system.debug('product 34 -->'+product );


      //List<Rates_Commissions__c> rate = [select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c, Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name  ];
       //   for(Rates_Commissions__c rate :[select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name ])
 
           
for(Rates_Commissions__c rate: [select id, Name, Product_Item__c, Client_Account__c, Venue_Hotel__c , Agreed_Rate__c, AgreedRes__c from Rates_Commissions__c  where Product_Item__c =: product.id ])
    {
    
      system.debug('rate 42 -->'+rate );
      if(quotes.AccountId == rate.Client_Account__c && quotes.Venue__c == rate.Venue_Hotel__c)
            {
            rate.Agreed_Rate__c = item.PSL_Rate__C;
            rate.AgreedRes__c = item.Commission_Percentage_PSL__c;
            }
            

    }
              }
             }
            }
              }             
            } //if quote
            // (quotes.AccountId == rate.Client_Account__c AND  quotes.Venue__c == rate.Venue_Hotel__c)
            /* if(quotes.AccountId == rate.Client_Account__c && quotes.Venue__c == rate.Venue_Hotel__c)
            {
            rate.Agreed_Rate__c = item.PSL_Rate__C;
            rate.AgreedRes__c = item.Commission_Percentage_PSL__c;
            }
            */
            
                 // select Id,agrredrate from rate ommison where productrc=pid && ratecommison.clinetacc=quoteacc && ratecommisonvenue = qotevenue ====== Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:item.Product2Id
    }





Thanks , Utkarsha
Hello,
I am writing code where i am stuck as i am not getting list of child object(Rate and Commision) in partent object(Product).
I have checked using debug statement. My code is giving me list of products selected in quote line item. But not the list of record and commsion objects record in product.

trigger UpdateAgreedRate on QuoteLineItem (before insert, before update) {
 system.debug('****************InTrigger**********************');
    
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        String QuoteID ;
        set<id> PIds = new set<id>();
       // set<id> RCIds = new set<id>();


        for (QuoteLineItem childObj : Trigger.new) {
            if(QuoteID == null) {
               QuoteID  = childObj.QuoteID;
            }
            if(childObj.Product2Id != null){
                PIds.add(childObj.Product2Id);
            }
            
        }
        system.debug('QuoteID 19 -->'+QuoteID  );
        
            if(QuoteID  != null) {
               
              List<Quote> quotes = [select Id, AccountId, Venue__c from Quote where Id =:QuoteID  ]; 
               if(quotes.size() > 0) {
                   Quote QuoteDetails = quotes[0];
                   system.debug('QuoteDetails 26 -->'+QuoteDetails );
                   
                    for (QuoteLineItem item : Trigger.new) {
                    system.debug('item 29 -->'+item );
                      
                      }   
                 
                 for(Product2 product :[select id, name, (select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c, Venue_Hotel__c from Rates_Commissions__r) from Product2 where Id IN : PIds]){
                 system.debug('product 34 -->'+product );


      List<Rates_Commissions__c> rate = [select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c, Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name  ]; 
       //   for(Rates_Commissions__c rate :[select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name ])
      system.debug('rate 39 -->'+rate ); 
              }
            }
                           
            }
            
            /* if(quotes.AccountId == rate.Client_Account__c && quotes.Venue__c == rate.Venue_Hotel__c)
            {
            rate.Agreed_Rate__c = item.PSL_Rate__C;
            }
            */
            
                 // select Id,agrredrate from rate ommison where productrc=pid && ratecommison.clinetacc=quoteacc && ratecommisonvenue = qotevenue ====== Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:item.Product2Id
    }
}

This is my code. Sometimes i get error that loop variable must be of quote line item. Can anyone help to get list of child records?

Thanks & Regards,
Utkarsha
Hello,

I have to update field on Quote line item(PSL Rate).
I am updating this value from "Agreed Rate" field on "Rate & commision" object. "Rate and Commision" object is child object of Product.
On quote line item when i will add the product. My trigger will check for Account field on Quote object and account(lookup) field on Rate and commisio object.
If this both account is same then i will update field on rate and commison object on qoute line item object.
Rate and commision object have multiple records. So i have to choose record having same name in quote object.

I have written a code. Its giving me product id. As in both 'quote line item' and 'Rate and commsion' object Product object is common.

I dont know how to take Rate and commision now in trigger with same product id

trigger UpdateAgreedRate on QuoteLineItem (before insert, before update) {
 system.debug('****************InTrigger**********************');
    
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        String QuoteID ;
    set<id> PIds = new set<id>();

        for (QuoteLineItem childObj : Trigger.new) {
            if(QuoteID == null) {
               QuoteID  = childObj.QuoteID;
            }
            if(childObj.Product2Id != null){
                PIds.add(childObj.Product2Id);
            }
        }
        system.debug('QuoteID 16 -->'+QuoteID  );
            if(QuoteID  != null) {
               
              List<Quote> quotes = [select Id, AccountId,  Venue__c from Quote where Id =:QuoteID  ]; 
               if(quotes.size() > 0) {
                   Quote QuoteDetails = quotes[0];
                   system.debug('QuoteDetails -->'+QuoteDetails );
                   
                    for (QuoteLineItem item : Trigger.new) {
     
                     // item.PSL_Rate__c = 5500;
                      //List<Rates_Commissions__c> rate = [select Id, Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:item.Product2Id]; 

                      system.debug('item -->'+item );
                      //system.debug('rate -->'+rate );


             //  update item;
                   
               }   
                   for(Product2 product :[select id, name   from Product2 where Id IN : PIds]){
                                             system.debug('product -->'+product );
                       
 //  List<Rates_Commissions__c> rate = [select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name ]; 
         
                   for(Rates_Commissions__c rate :[select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name ])
        {
            system.debug('rate -->'+rate ); 
            
        }   
                   }
                   
        }
                           
            }
                 // select Id,agrredrate from rate ommison where productrc=pid && ratecommison.clinetacc=quoteacc && ratecommisonvenue = qotevenue ====== Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:item.Product2Id
    }
}

           
Hello,

I am creating new contact on the lookup filed. But whenever i create new contact it does not asociate with any account. so contact gets stored without an account. I want to add account name field while contact creation. How to achive that?

Thanks,
Utkarsha
Hello,

Code coverage of my test class is 54%. I want to cover if else condition. But i dont know how to cover if else condirtion in test class. 

My trigger and test class is as follows.

Apex Trigger:


trigger QuoteSynchingValidation on Quote (before insert,before update) {
     if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        
        
        String recordType;
        
        Id customerAccountRecordTypeId = Schema.SObjectType.Quote.getRecordTypeInfosByName().get('BenderINC - Industrial Quotes').getRecordTypeId();
   
        Boolean inRange ;

    
        for (Quote childObj : Trigger.new) {
            if(childObj.IsSyncing ) {
                 recordType = childObj.RecordTypeId; /* Record type is taken in formula filed on child object(QLI) as its originally on parent object(Q). */
                 if(recordType == customerAccountRecordTypeId )  {
                      if(childObj.Approval_Status__c == 'Awaiting Approval' || childObj.Approval_Status__c == 'Declined'){
                         childObj.addError('You cannot sync this Quote as Discount Approval is needed and has not been granted.');  
                      }
                      
                       
                      else 
                      {
       
                 checkSycnhhasclicked.hasClick = true;
                                     system.debug('59--->>checkSycnhhasclicked-->'+checkSycnhhasclicked.hasClick);
                      }
                 }
            }    
        }
         
    }
}


Test Class:

@isTest(seeAllData = true)
private class TestQuoteSynchingValidation {
 
    static testMethod void myUnitTest() {
   
    //Test Account Insert

    Account a = new Account();
    a.Name = 'Test Account';
    a.Account_Sector__c = 'Healthcare';
    a.Account_Type__c = 'Competitor';
    a.Country_List__c = 'England'; 
    a.BillingCity = 'Pune';
    a.BillingCountry = 'India';
    a.BillingState = 'MH';
    a.BillingStreet = 'Hadapsar';
    a.BillingPostalCode = '411028';
    insert a;

     Contact  c = new Contact();
     c.LastName = 'Patils';
     c.Title = 'Employee';
     c.LeadSource = 'Advertisement';
     c.AccountId = a.id;
     insert c;
     
    Product2 p = new Product2();
    p.Name = ' Test Product ';
    p.Description='Test Product Entry 1';
    p.productCode = 'ABC';
    p.isActive = true;
    insert p;
   
   

    Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true];
    
    Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
    insert customPB;

    PricebookEntry standardPrice = new PricebookEntry();
    standardPrice.Pricebook2Id = standardPb.Id;
    standardPrice.Product2Id = p.Id;
    standardPrice.UnitPrice = 1;
    standardPrice.isActive = true;
    //standardPrice.IsStandard = false;
    //standardPrice.UseStandardPrice = true;
    insert standardPrice ;
    
    PricebookEntry custompbe= new PricebookEntry();
    custompbe.Pricebook2Id = customPB.Id;
    custompbe.Product2Id = p.Id;
    custompbe.UnitPrice = 1;
    custompbe.IsActive = true;
   // custompbe.IsStandard = false;
    custompbe.UseStandardPrice = true;
    insert custompbe;
    
    //Test Order Insert
   
    Opportunity o = new Opportunity();
    o.Name = 'Test Order ';
    o.Type = 'Medical';
    //o.EffectiveDate = system.today();
    o.CloseDate= system.today() + 4;
    o.AccountId = a.id;
    o.Pricebook2Id =customPB.Id ;
    o.LeadSource = 'Advertisement';
    o.ForecastCategoryName = 'Pipeline';
    o.StageName = 'Needs Analysis';
    o.Amount = 200.20 ;
    o.Products_Required__c = 'IMD';
    insert o;
   
    Quote i = new Quote();
    i.OpportunityId = o.id;
    i.Name= '170724508 - REV 001';
    i.Pricebook2Id = customPB.id;
    i.RecordTypeId = '012b00000001AxG';
    i.Approval_Status__c = 'Awaiting Approval';
    insert i;
     
    Quote i2 = new Quote();
    i2.OpportunityId = o.id;
    i2.Name= '170724508 - REV 001';
    i2.Pricebook2Id = customPB.id;
    i2.RecordTypeId = '012b00000001AxG';
    i2.Approval_Status__c = 'Declined';
    insert i2;
    
    QuoteLineItem Ql = new QuoteLineItem();
    Ql.QuoteId = i.id;
    Ql.Quantity = 24;
    Ql.UnitPrice = 240;
    Ql.Product2id = p.id;
    Ql.PricebookEntryId=custompbe.id;
    insert Ql;
    //QuoteLineItem  Q2 = [Select ];
    
    if(i2.IsSyncing )
       {
           i2.RecordTypeId = '012b00000001AxG';
           if(i2.RecordTypeId == '012b00000001AxG' )  
           {
               if(i2.Approval_Status__c == 'Declined'){
           
               i2.addError('You cannot sync this Quote as Discount Approval is needed and has not been granted.');  
           }
           }
       }
    
        } 
    
    static testMethod void myUnitTest2() 
    {
    
        Account a = new Account();
    a.Name = 'Test Account';
    a.Account_Sector__c = 'Healthcare';
    a.Account_Type__c = 'Competitor';
    a.Country_List__c = 'England'; 
    a.BillingCity = 'Pune';
    a.BillingCountry = 'India';
    a.BillingState = 'MH';
    a.BillingStreet = 'Hadapsar';
    a.BillingPostalCode = '411028';
    insert a;

     Contact  c = new Contact();
     c.LastName = 'Patils';
     c.Title = 'Employee';
     c.LeadSource = 'Advertisement';
     c.AccountId = a.id;
     insert c;
     
    Product2 p = new Product2();
    p.Name = ' Test Product ';
    p.Description='Test Product Entry 1';
    p.productCode = 'ABC';
    p.isActive = true;
    insert p;
   
   

    Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true];
    
    Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
    insert customPB;

    PricebookEntry standardPrice = new PricebookEntry();
    standardPrice.Pricebook2Id = standardPb.Id;
    standardPrice.Product2Id = p.Id;
    standardPrice.UnitPrice = 1;
    standardPrice.isActive = true;
    //standardPrice.IsStandard = false;
    //standardPrice.UseStandardPrice = true;
    insert standardPrice ;
    
    PricebookEntry custompbe= new PricebookEntry();
    custompbe.Pricebook2Id = customPB.Id;
    custompbe.Product2Id = p.Id;
    custompbe.UnitPrice = 1;
    custompbe.IsActive = true;
   // custompbe.IsStandard = false;
    custompbe.UseStandardPrice = true;
    insert custompbe;
    
    //Test Order Insert
   
    Opportunity o = new Opportunity();
    o.Name = 'Test Order ';
    o.Type = 'Medical';
    //o.EffectiveDate = system.today();
    o.CloseDate= system.today() + 4;
    o.AccountId = a.id;
    o.Pricebook2Id =customPB.Id ;
    o.LeadSource = 'Advertisement';
    o.ForecastCategoryName = 'Pipeline';
    o.StageName = 'Needs Analysis';
    o.Amount = 200.20 ;
    o.Products_Required__c = 'IMD';
    insert o;
   
    Quote i = new Quote();
    i.OpportunityId = o.id;
    i.Name= '170724508 - REV 001';
    i.Pricebook2Id = customPB.id;
    i.RecordTypeId = '012b00000001AxG';
    i.Approval_Status__c = 'Awaiting Approval';
    insert i;
     
    Quote i2 = new Quote();
    i2.OpportunityId = o.id;
    i2.Name= '170724508 - REV 001';
    i2.Pricebook2Id = customPB.id;
    i2.RecordTypeId = '012b00000001AxG';
    i2.Approval_Status__c = 'Granted';
    insert i2;
    
    QuoteLineItem Ql = new QuoteLineItem();
    Ql.QuoteId = i.id;
    Ql.Quantity = 24;
    Ql.UnitPrice = 240;
    Ql.Product2id = p.id;
    Ql.PricebookEntryId=custompbe.id;
    insert Ql;
    
        if(i.IsSyncing )
       {
           i.RecordTypeId = '012b00000001AxG';
           if(i.RecordTypeId == '012b00000001AxG' )  
           {
               if(i.Approval_Status__c == 'Awaiting Approval'){
           
               i.addError('You cannot sync this Quote as Discount Approval is needed and has not been granted.');  
               }
            }
         }
    }
}

Can anyone please help me.

Thanks,
Utz
Hello,

I want to fire my  trigger on particular reocrd type only. But i am getting error. 
 Apex trigger QuotelineItemApproval caused an unexpected exception, contact your administrator: QuotelineItemApproval: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0Q07E000000dz9aSAA; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3017E0000002lA7. Flow error messages: An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []: Trigger.QuotelineItemApproval: line 95, column 1  


trigger QuotelineItemApproval on QuoteLineItem (after insert, after update) {

    List<Quote> parentObjList = new List<Quote>();
    List<ID> listIds = new List<ID>();
    List<Quote> listIds1 = new List<Quote>();
    Id devRecordTypeId = Schema.SObjectType.Quote.getRecordTypeInfosByName().get('BenderINC - Industrial Quotes').getRecordTypeId();
    
    if(devRecordTypeId == '012b00000001AxG')
            system.debug('***********+devRecordTypeId +*************'+devRecordTypeId );

  {
    
    Boolean inRange ;
    
    String status  ='Not Required';
    String QuoteID ;
    Boolean isAwaiting = false;
    
    
    for (QuoteLineItem childObj : Trigger.new) {
        if(QuoteID == null) {
             QuoteID  = childObj.QuoteID;
        }    
    }
    
    Boolean changed = false;
    
    if(QuoteID  != null) {
        for(List<QuoteLineItem> items : [select ID, Discount_Flag1__c,Quantity ,Discount  from QuotelineItem where QuoteId= : QuoteID  ]) {
            for(QuoteLineItem item : items ) {
                inRange = false;
                changed  = true;
                if(item.Quantity >= 0 && item.Quantity <= 9 &&  item.Discount <= 0) {
                       inRange = true;
                } else {
                   if(item.Quantity >= 10 && item.Quantity <= 25 &&  item.Discount <= 5) {
                     inRange = true;
                   } else {
                      if(item.Quantity >= 26 && item.Quantity <= 49 &&  item.Discount <= 7) {
                         inRange = true;
                      } else {
                         if(item.Quantity >= 50  &&  item.Discount <= 10) {
                             inRange = true;
                         }
                      }
                   }
                }
                
                if(!inRange) {
                   isAwaiting  = true;              
                }  
                
                system.debug('***********+Quantity +*************'+item.Quantity);
                system.debug('***********+Discount +*************'+item.Discount);
                 
                system.debug('***********+inRange +*************'+inRange );
        
            } 
        } 
        
        
        system.debug('***********+isAwaiting  +*************'+isAwaiting  );
         
        if(changed ) {
           
           Id retVal = null;
           for(ProcessInstanceWorkitem workItem  : [Select p.Id from ProcessInstanceWorkitem p   where p.ProcessInstance.TargetObjectId =: QuoteID]) {
                retVal  =  workItem.Id;
           } 
           
           if(isAwaiting  ) {  
               status = 'Awaiting Approval'; 
           } else {
               status = 'Not Required';           
           }
           
           List<Quote> quotes = [select Id,Approval_Status__c  from Quote where Id =:QuoteID  ]; 
           
           if(quotes.size() > 0) {
               Quote QuoteDetails = quotes[0];
               if(retVal != null && status == 'Not Required') {
                       Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
                       req.setComments('Automatically approved as Approval is no longer required.'); 
                       req.setAction('Approve');
                       req.setNextApproverIds(new Id[] {UserInfo.getUserId()});  
                       req.setWorkitemId(retVal );    
                       Approval.ProcessResult result =  Approval.process(req);
               } 
                
               
               
           
               //QuoteDetails.IsSynching = false;
               QuoteDetails.Approval_Status__c  = status;
               update QuoteDetails;
           } 
        } 
    }
   
    
  }   
 
}

Thanks & Regards,
Utkarsha
Hello, 

I want to make dicount filed 0 if it left blank. How is it possible?

trigger QuotelineItemApproval on QuoteLineItem (after insert, after update) {

    List<Quote> parentObjList = new List<Quote>();
    List<ID> listIds = new List<ID>();
    List<Quote> listIds1 = new List<Quote>();
    
    //List <QuotelineItem> m3 = [select ID, Discount_Flag1__c from QuotelineItem where Discount_Flag1__c = : '1'];
    Boolean inRange ;
    
    String status  ='Not Required';
    String QuoteID ;
    Boolean isAwaiting = false;
    
    
    for (QuoteLineItem childObj : Trigger.new) {
        if(QuoteID == null) {
             QuoteID  = childObj.QuoteID;
        }    
    }
    
    Boolean changed = false;
    
    if(QuoteID  != null) {
        for(List<QuoteLineItem> items : [select ID, Discount_Flag1__c,Quantity ,Discount  from QuotelineItem where QuoteId= : QuoteID  ]) {
            for(QuoteLineItem item : items ) {
                inRange = false;
                changed  = true;
                if(item.Quantity >= 0 && item.Quantity <= 9 &&  item.Discount <= 0) {
                       inRange = true;
                } else {
                   if(item.Quantity >= 10 && item.Quantity <= 25 &&  item.Discount <= 5) {
                     inRange = true;
                   } else {
                      if(item.Quantity >= 26 && item.Quantity <= 49 &&  item.Discount <= 7) {
                         inRange = true;
                      } else {
                         if(item.Quantity >= 50  &&  item.Discount <= 10) {
                             inRange = true;
                         }
                      }
                   }
                }
                
                if(!inRange) {
                   isAwaiting  = true;              
                }  
                
                system.debug('***********+Quantity +*************'+item.Quantity);
                system.debug('***********+Discount +*************'+item.Discount);
                 
                system.debug('***********+inRange +*************'+inRange );
        
            } 
        } 
        
        
        system.debug('***********+isAwaiting  +*************'+isAwaiting  );
         
        if(changed ) {
           
           Id retVal = null;
           for(ProcessInstanceWorkitem workItem  : [Select p.Id from ProcessInstanceWorkitem p   where p.ProcessInstance.TargetObjectId =: QuoteID]) {
                retVal  =  workItem.Id;
           } 
           
           if(isAwaiting  ) {  
               status = 'Awaiting Approval'; 
           } else {
               status = 'Not Required';           
           }
           
           List<Quote> quotes = [select Id,Approval_Status__c  from Quote where Id =:QuoteID  ]; 
           
           if(quotes.size() > 0) {
               Quote QuoteDetails = quotes[0];
               if(retVal != null && status == 'Not Required') {
                       Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
                       req.setComments('Automatically approved as Approval is no longer required.'); 
                       req.setAction('Approve');
                       req.setNextApproverIds(new Id[] {UserInfo.getUserId()});  
                       req.setWorkitemId(retVal );    
                       Approval.ProcessResult result =  Approval.process(req);
               } 
                
               
               
           
               //QuoteDetails.IsSynching = false;
               QuoteDetails.Approval_Status__c  = status;
               update QuoteDetails;
           } 
        } 
    }
    
    
    
}

Thanks & Regards,
Utkarsha
Hello,

I want to make picklist field read only. There is no permission set. I make it read only from page layout, Field level security and profile too. Still its read only. What will be another option to make it rad only?

Thanks & Reagrds,
Utkarsha
Hello,

Is there any way to make standard sync button enable or disable on particular picklist condition?
Supposte Status= granted then i should able to sync and if Status = awaiting for approval then it should not sync.
I want to control it on statndard sync button on quote object

Thanks & Regards,
Utkarsha
Hello,

I am working on a quote object. In this approval process is not working. If below criteria is satisfied then approval process should fire and assigned approval should get notification to approve or reject record.
Quote Record Type: BenderINC - Industrial Quotes.

I dont know why this is happening. It was working earlier.

Thanks & Regards,
Utkarsha
Hello,

In related list of opportunity object we are using qoute. We are not able to create a qoute after click in on new button. New button on the qoute object is custom button which contains link. this link redirect us to the production. So as we dont have access of production we are not able to create new quote. We were trying to add buttons from page layout of related list of opportunity object. but when we click on setting icon it opens empty panel. We need a help to add standard new button on quote object. Is this possible?

Thanks & regards,
Utkarsha
Hello, 

I am writting a trigger where i am using salesforce standard account owner field and custom account owner field. Both field have lookup to get USER.
I wrote "Account Share" trigger when we change any account owner then all the data transfer to the new account owner and  data assigned to old account owner gets deleted. But when this two that means standard and custom account owner is same then it throws an error "Delete_Share: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00r28000020WLxjAAG; first error: DELETE_FAILED, cannot delete owner or rule share rows, id=00r28000020WLxj: [] Trigger.Delete_Share: line 33, column 1". Please tell me what to over here.

trigger Delete_Share on Account (before update) {


set<Id> AccountIDs = new Set<Id>();
for(Account a: trigger.new){
AccountIDs.add(a.id);
}
List<AccountShare> jobShares = new List<AccountShare>();

map<String,AccountShare>accountShareMap = new Map<String,AccountShare>();

for(AccountShare accShare : [select AccountId, UserOrGroupId from AccountShare where AccountId in :AccountIds])
{
 accountShareMap.put(String.valueOf(accShare.UserOrGroupId),accShare);

}


for(Account a : trigger.new){
Account oldAccount = Trigger.OldMap.get(a.id);
if (a.owner1__c != null) {
 
   AccountShare accountRecord = accountShareMap.get(string.valueOf(oldAccount.owner1__c));
    if (accountRecord  != null)
    jobShares.add(accountRecord);
  }
 }
for(Account a1 : trigger.new){
Account oldAccount = Trigger.OldMap.get(a1.id);
if(jobShares.isEmpty() == false  && a1.owner1__c == a1.OwnerID){
//if(jobShares.isEmpty() == false ){

 delete jobShares;
 }
}
}

Thanks & Regards,
Utkarsha
Hello,
I want to create automatic opportuinty line item when opportunity is created. How is this possible. I want to create of particular Product name suppose "Accomodation". I have written a code. 
trigger insertOppLineItem on Opportunity (after insert, after update) {
 system.debug('****************InTrigger**********************');
    
    if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate)){
        String OpportunityID ;
        
    for(Opportunity o : Trigger.new){ 
        system.debug('OpportunityID 8 -->'+o.Id);
        OpportunityID = o.Id;
    
        if(OpportunityID  != null) 
        {
            List<Opportunity> opp = [select Id , No_of_Nights__c from Opportunity where ID =:  OpportunityID  ]; 
               system.debug('Opportunity 14.......... -->'+opp );

          //  List<OpportunityLineItem> vList = new List<OpportunityLineItem >();
           for(OpportunityLineItem v : trigger.new){
            o.No_of_Nights__c = v.Quantity;
        
                //vList.add(v);          
             }
               

        } 
        upsert v; 
    }   
}
}


How is this achivable?


Thanks &Regards,
Utkarsha
Hi, 
I have written Account sharing and delete sharing record for custom field. Its giving me following error. Account has "Private" acess in OWD.

Account {"Party_Sea_ID__c":3618,"Customer_Number__c":"C0354","Name":"LUXURY BRAND HOLDINGS INC.","DBA_Name__c":"LUXURY BRAND HOLDINGS","Customer_Group_Id__c":"a0028000015lr6gAAA","OwnerId":"00528000005HQRPAA4","owner1__c":"00528000003iGolAAE","Terms_Id__c":"a042800000oV27IAAS","Default_Currency__c":"US DOLLARS","Industry":"Jewelry","Website":"www.luxurybrandholdings.com","No_of_Doors__c":14,"NumberOfEmployees":0,"Store_Size__c":0,"Contact_Person__c":"0","Rolex_Dealer__c":"Y","Status__c":1,"Sales_Code__c":"ASSET AND MEMO","RecordTypeId":"01228000000QbiR","Asset_Credit_Limit__c":1000000.0,"Memo_Credit_Limit__c":1500000.0,"Outstanding_A_R_Balance__c":0.0,"Outstanding_Memo_Balance__c":0.0,"BillingStreet":"9 ROSS SIMONS DRIVE - 2920 , , ","BillingPostalCode":"2920"} Delete_Share: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00r28000020W8ELAA0; first error: DELETE_FAILED, cannot delete owner or rule share rows, id=00r28000020W8EL: [] Trigger.Delete_Share: line 89, column 1


Code is as below.
trigger Delete_Share on Account (before update) {
    
/*set<Id> AccountIDs = new Set<Id>();
for(Account a: trigger.new){
    
    //System.debug('Account IDs: '+ a.id);
    
  AccountIDs.add(a.id);
}
List<AccountShare> jobShares = new List<AccountShare>();

map<String,AccountShare>accountShareMap = new Map<String,AccountShare>();

for(AccountShare accShare : [select AccountId, UserOrGroupId,AccountAccesslevel,OpportunityAccessLevel from AccountShare where AccountId in :AccountIds])
{
 accountShareMap.put(String.valueOf(accShare.UserOrGroupId),accShare);

}

 
// for(Account a1 : trigger.new){
// Account oldAccount = Trigger.OldMap.get(a1.id);
// if(jobShares.isEmpty() == false ){

 //delete jobShares;
 //}
//}

for(Account a : trigger.new){
Account oldAccount = Trigger.OldMap.get(a.id);
    
    system.debug('old account:' + oldaccount);
    
if ((a.owner1__c != oldAccount.owner1__c) && (a.ownerId != oldAccount.owner1__c)){
    
    System.debug('Account: '+ a);
    
   AccountShare accountRecord = accountShareMap.get(string.valueOf(oldAccount.owner1__c)); 
    if (accountRecord  != null){
  jobShares.add(accountRecord);
    }
  }
 }

if(jobShares.isEmpty() == false ){ 
    //if(!jobShares.isEmpty()){
    delete jobShares;
    System.debug('deleted successfully...');
 
 } */



set<Id> AccountIDs = new Set<Id>();
for(Account a: trigger.new){
AccountIDs.add(a.id);
}
List<AccountShare> jobShares = new List<AccountShare>();

map<String,AccountShare>accountShareMap = new Map<String,AccountShare>();

for(AccountShare accShare : [select AccountId, UserOrGroupId from AccountShare where AccountId in :AccountIds])
{
 accountShareMap.put(String.valueOf(accShare.UserOrGroupId),accShare);

}

 
// for(Account a1 : trigger.new){
// Account oldAccount = Trigger.OldMap.get(a1.id);
// if(jobShares.isEmpty() == false ){

 //delete jobShares;
 //}
//}

for(Account a : trigger.new){
Account oldAccount = Trigger.OldMap.get(a.id);
if (((a.owner1__c != oldAccount.owner1__c) && (a.ownerId != oldAccount.ownerId)) || ((a.owner1__c !=oldAccount.owner1__c)  && (a.OwnerId ==oldAccount.OwnerId))  || ((a.owner1__c == oldAccount.owner1__c)  && (a.OwnerId != oldAccount.OwnerId))){
 
   AccountShare accountRecord = accountShareMap.get(string.valueOf(oldAccount.owner1__c)); 
    if (accountRecord  != null)
    jobShares.add(accountRecord);
  }
 }

if(jobShares.isEmpty() == false ){

 delete jobShares;
 }
 }

Can anybody please tell me why is this happening? Its working fine when i change Owner field manually in the salesforce. But i am using SEA to Salesforce integration where all data gets inserted throgh SEA. Its give me above error while transferring the data.

Thanks & Regards,
Utkarsha

 
Hello,

trigger UpdateAgreedRate on QuoteLineItem (before insert, before update) {
 system.debug('****************InTrigger**********************');
    
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        String QuoteID ;
        set<id> PIds = new set<id>();

        for (QuoteLineItem childObj : Trigger.new) {
            if(QuoteID == null) {
               QuoteID  = childObj.QuoteID;
            }
            if(childObj.Product2Id != null){
                PIds.add(childObj.Product2Id);
            }
            
        
        system.debug('QuoteID 18 -->'+QuoteID  );
        
            if(QuoteID  != null) {
               
              List<Quote> quotes = [select Id, AccountId, Venue__c, Opportunity.Guest_Name__r.Name from Quote where Id =:QuoteID  ]; 
               if(quotes.size() > 0) {
                   Quote QuoteDetails = quotes[0];
                   
                   system.debug('QuoteDetails 26 -->'+QuoteDetails );
                   
                    for (QuoteLineItem item : Trigger.new) {
                    system.debug('item 29 -->'+item );
                      
                   item.Guest1__c= quotes[0].Opportunity.Guest_Name__r.Name;

                for(Product2 product :[select id, name from Product2 where Id IN : PIds]){
                 system.debug('product 33 -->'+product );


      
 
           
for(Rates_Commissions__c rate: [select id, Name, Product_Item__c, Client_Account__c, Venue_Hotel__c , Agreed_Rate__c, AgreedRes__c from Rates_Commissions__c   where Product_Item__c =: product.id])
    {
    
      system.debug('rate 42 -->'+rate ); 
      if(rate.Product_Item__c == product.id && quotes[0].AccountId == rate.Client_Account__c && quotes[0].Venue__c == rate.Venue_Hotel__c)
                   {          
                       system.debug('ProductId-->'+product.id  );
                       system.debug('RateProductItem-->'+rate.Product_Item__c  );
                       system.debug('QuoteAccId-->'+quotes[0].AccountId  );
                       system.debug('RateAccId-->'+rate.Client_Account__c  );
                       system.debug('QuoteVenueHotel-->'+quotes[0].Venue__c  );
                       system.debug('RateVenueHotel-->'+rate.Venue_Hotel__c  );


              item.PSL_Rate__C =  rate.Agreed_Rate__c ;
              item.Commission_Percentage_PSL__c = rate.AgreedRes__c;
               system.debug('rate.Agreed_Rate__c -->'+ rate.Agreed_Rate__c );
               system.debug(' rate.AgreedRes__c -->'+ rate.AgreedRes__c );


            }
            

    }
              }
             } 
            }
              }             
            } 
            
            
        }        
        
         if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
         for(QuoteLineItem o : Trigger.new)
         {
        if(o.PSL_Rate__C < o.Online_Rate__c)
        {
        o.Recommended_Sales_Price__c=  o.PSL_Rate__C;
        }
        else if(o.Online_Rate__c < o.PSL_Rate__C){
         o.Recommended_Sales_Price__c=  o.Online_Rate__c ;
        }
        else if(o.Online_Rate__c == null || o.Online_Rate__c == 0 ){
         o.Recommended_Sales_Price__c=  o.PSL_Rate__C;
        }
        else if(o.PSL_Rate__C == 0 || o.PSL_Rate__C == null)
        {
         o.Recommended_Sales_Price__c=  o.Online_Rate__c ;
        }
        

        }
        }
    }

My code is hitting governor limit exception. Can anybody help me to resolve this issue

Thanks,
Utkarsha
Hello,
I want to create automatic opportuinty line item when opportunity is created. How is this possible. I want to create of particular Product name suppose "Accomodation". I have written a code. 
trigger insertOppLineItem on Opportunity (after insert, after update) {
 system.debug('****************InTrigger**********************');
    
    if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate)){
        String OpportunityID ;
        
    for(Opportunity o : Trigger.new){ 
        system.debug('OpportunityID 8 -->'+o.Id);
        OpportunityID = o.Id;
    
        if(OpportunityID  != null) 
        {
            List<Opportunity> opp = [select Id , No_of_Nights__c from Opportunity where ID =:  OpportunityID  ]; 
               system.debug('Opportunity 14.......... -->'+opp );

          //  List<OpportunityLineItem> vList = new List<OpportunityLineItem >();
           for(OpportunityLineItem v : trigger.new){
            o.No_of_Nights__c = v.Quantity;
        
                //vList.add(v);          
             }
               

        } 
        upsert v; 
    }   
}
}


How is this achivable?


Thanks &Regards,
Utkarsha
Hello,

I am creating a formula field where i am taking minimum value form Online Rate field or PSL rate field.
This is possible using min funcion or in if condition by comparing two values.

Next thing is. If PSL rate is blank then Online rate value should be populated in my formula field. '
If Online rate is blank then Psl rate should be populate in formula filed.

OR(IF(ISNULL(PSL_Rate__c), PSL_Rate__c, Online_Rate__c),IF(ISNULL(Online_Rate__c), Online_Rate__c, PSL_Rate__c))

I used this . But its giving me an error expexcted boolean received number. I have to show whatever will be value in this field. I cant keep it as boolean. What to do now?

Best Regards,
Utkarsha
Hello,

I am writing a code where i am almost done. but i dont know how to get rid of this error. I want to compare accounts on quote object and one of the object which is child object (rate and commision) of product object. When this 2 are same then i want to update field on rate and commision object on quote line item object. can anyone help me with this?
trigger UpdateAgreedRate on QuoteLineItem (before insert, before update) {
 system.debug('****************InTrigger**********************');
    
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        String QuoteID ;
        set<id> PIds = new set<id>();


        for (QuoteLineItem childObj : Trigger.new) {
            if(QuoteID == null) {
               QuoteID  = childObj.QuoteID;
            }
            if(childObj.Product2Id != null){
                PIds.add(childObj.Product2Id);
            }
            
        }
        system.debug('QuoteID 19 -->'+QuoteID  );
        
            if(QuoteID  != null) {
               
              List<Quote> quotes = [select Id, AccountId, Venue__c from Quote where Id =:QuoteID  ];
               if(quotes.size() > 0) {
                   Quote QuoteDetails = quotes[0];
                   
                   system.debug('QuoteDetails 26 -->'+QuoteDetails );
                   
                    for (QuoteLineItem item : Trigger.new) {
                    system.debug('item 29 -->'+item );
                      
                      


                for(Product2 product :[select id, name from Product2 where Id IN : PIds]){
                 system.debug('product 34 -->'+product );


      //List<Rates_Commissions__c> rate = [select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c, Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name  ];
       //   for(Rates_Commissions__c rate :[select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name ])
 
           
for(Rates_Commissions__c rate: [select id, Name, Product_Item__c, Client_Account__c, Venue_Hotel__c , Agreed_Rate__c, AgreedRes__c from Rates_Commissions__c  where Product_Item__c =: product.id ])
    {
    
      system.debug('rate 42 -->'+rate );
      if(quotes.AccountId == rate.Client_Account__c && quotes.Venue__c == rate.Venue_Hotel__c)
            {
            rate.Agreed_Rate__c = item.PSL_Rate__C;
            rate.AgreedRes__c = item.Commission_Percentage_PSL__c;
            }
            

    }
              }
             }
            }
              }             
            } //if quote
            // (quotes.AccountId == rate.Client_Account__c AND  quotes.Venue__c == rate.Venue_Hotel__c)
            /* if(quotes.AccountId == rate.Client_Account__c && quotes.Venue__c == rate.Venue_Hotel__c)
            {
            rate.Agreed_Rate__c = item.PSL_Rate__C;
            rate.AgreedRes__c = item.Commission_Percentage_PSL__c;
            }
            */
            
                 // select Id,agrredrate from rate ommison where productrc=pid && ratecommison.clinetacc=quoteacc && ratecommisonvenue = qotevenue ====== Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:item.Product2Id
    }





Thanks , Utkarsha
Hello,

I am creating new contact on the lookup filed. But whenever i create new contact it does not asociate with any account. so contact gets stored without an account. I want to add account name field while contact creation. How to achive that?

Thanks,
Utkarsha
Hello,

Code coverage of my test class is 54%. I want to cover if else condition. But i dont know how to cover if else condirtion in test class. 

My trigger and test class is as follows.

Apex Trigger:


trigger QuoteSynchingValidation on Quote (before insert,before update) {
     if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        
        
        String recordType;
        
        Id customerAccountRecordTypeId = Schema.SObjectType.Quote.getRecordTypeInfosByName().get('BenderINC - Industrial Quotes').getRecordTypeId();
   
        Boolean inRange ;

    
        for (Quote childObj : Trigger.new) {
            if(childObj.IsSyncing ) {
                 recordType = childObj.RecordTypeId; /* Record type is taken in formula filed on child object(QLI) as its originally on parent object(Q). */
                 if(recordType == customerAccountRecordTypeId )  {
                      if(childObj.Approval_Status__c == 'Awaiting Approval' || childObj.Approval_Status__c == 'Declined'){
                         childObj.addError('You cannot sync this Quote as Discount Approval is needed and has not been granted.');  
                      }
                      
                       
                      else 
                      {
       
                 checkSycnhhasclicked.hasClick = true;
                                     system.debug('59--->>checkSycnhhasclicked-->'+checkSycnhhasclicked.hasClick);
                      }
                 }
            }    
        }
         
    }
}


Test Class:

@isTest(seeAllData = true)
private class TestQuoteSynchingValidation {
 
    static testMethod void myUnitTest() {
   
    //Test Account Insert

    Account a = new Account();
    a.Name = 'Test Account';
    a.Account_Sector__c = 'Healthcare';
    a.Account_Type__c = 'Competitor';
    a.Country_List__c = 'England'; 
    a.BillingCity = 'Pune';
    a.BillingCountry = 'India';
    a.BillingState = 'MH';
    a.BillingStreet = 'Hadapsar';
    a.BillingPostalCode = '411028';
    insert a;

     Contact  c = new Contact();
     c.LastName = 'Patils';
     c.Title = 'Employee';
     c.LeadSource = 'Advertisement';
     c.AccountId = a.id;
     insert c;
     
    Product2 p = new Product2();
    p.Name = ' Test Product ';
    p.Description='Test Product Entry 1';
    p.productCode = 'ABC';
    p.isActive = true;
    insert p;
   
   

    Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true];
    
    Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
    insert customPB;

    PricebookEntry standardPrice = new PricebookEntry();
    standardPrice.Pricebook2Id = standardPb.Id;
    standardPrice.Product2Id = p.Id;
    standardPrice.UnitPrice = 1;
    standardPrice.isActive = true;
    //standardPrice.IsStandard = false;
    //standardPrice.UseStandardPrice = true;
    insert standardPrice ;
    
    PricebookEntry custompbe= new PricebookEntry();
    custompbe.Pricebook2Id = customPB.Id;
    custompbe.Product2Id = p.Id;
    custompbe.UnitPrice = 1;
    custompbe.IsActive = true;
   // custompbe.IsStandard = false;
    custompbe.UseStandardPrice = true;
    insert custompbe;
    
    //Test Order Insert
   
    Opportunity o = new Opportunity();
    o.Name = 'Test Order ';
    o.Type = 'Medical';
    //o.EffectiveDate = system.today();
    o.CloseDate= system.today() + 4;
    o.AccountId = a.id;
    o.Pricebook2Id =customPB.Id ;
    o.LeadSource = 'Advertisement';
    o.ForecastCategoryName = 'Pipeline';
    o.StageName = 'Needs Analysis';
    o.Amount = 200.20 ;
    o.Products_Required__c = 'IMD';
    insert o;
   
    Quote i = new Quote();
    i.OpportunityId = o.id;
    i.Name= '170724508 - REV 001';
    i.Pricebook2Id = customPB.id;
    i.RecordTypeId = '012b00000001AxG';
    i.Approval_Status__c = 'Awaiting Approval';
    insert i;
     
    Quote i2 = new Quote();
    i2.OpportunityId = o.id;
    i2.Name= '170724508 - REV 001';
    i2.Pricebook2Id = customPB.id;
    i2.RecordTypeId = '012b00000001AxG';
    i2.Approval_Status__c = 'Declined';
    insert i2;
    
    QuoteLineItem Ql = new QuoteLineItem();
    Ql.QuoteId = i.id;
    Ql.Quantity = 24;
    Ql.UnitPrice = 240;
    Ql.Product2id = p.id;
    Ql.PricebookEntryId=custompbe.id;
    insert Ql;
    //QuoteLineItem  Q2 = [Select ];
    
    if(i2.IsSyncing )
       {
           i2.RecordTypeId = '012b00000001AxG';
           if(i2.RecordTypeId == '012b00000001AxG' )  
           {
               if(i2.Approval_Status__c == 'Declined'){
           
               i2.addError('You cannot sync this Quote as Discount Approval is needed and has not been granted.');  
           }
           }
       }
    
        } 
    
    static testMethod void myUnitTest2() 
    {
    
        Account a = new Account();
    a.Name = 'Test Account';
    a.Account_Sector__c = 'Healthcare';
    a.Account_Type__c = 'Competitor';
    a.Country_List__c = 'England'; 
    a.BillingCity = 'Pune';
    a.BillingCountry = 'India';
    a.BillingState = 'MH';
    a.BillingStreet = 'Hadapsar';
    a.BillingPostalCode = '411028';
    insert a;

     Contact  c = new Contact();
     c.LastName = 'Patils';
     c.Title = 'Employee';
     c.LeadSource = 'Advertisement';
     c.AccountId = a.id;
     insert c;
     
    Product2 p = new Product2();
    p.Name = ' Test Product ';
    p.Description='Test Product Entry 1';
    p.productCode = 'ABC';
    p.isActive = true;
    insert p;
   
   

    Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true];
    
    Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
    insert customPB;

    PricebookEntry standardPrice = new PricebookEntry();
    standardPrice.Pricebook2Id = standardPb.Id;
    standardPrice.Product2Id = p.Id;
    standardPrice.UnitPrice = 1;
    standardPrice.isActive = true;
    //standardPrice.IsStandard = false;
    //standardPrice.UseStandardPrice = true;
    insert standardPrice ;
    
    PricebookEntry custompbe= new PricebookEntry();
    custompbe.Pricebook2Id = customPB.Id;
    custompbe.Product2Id = p.Id;
    custompbe.UnitPrice = 1;
    custompbe.IsActive = true;
   // custompbe.IsStandard = false;
    custompbe.UseStandardPrice = true;
    insert custompbe;
    
    //Test Order Insert
   
    Opportunity o = new Opportunity();
    o.Name = 'Test Order ';
    o.Type = 'Medical';
    //o.EffectiveDate = system.today();
    o.CloseDate= system.today() + 4;
    o.AccountId = a.id;
    o.Pricebook2Id =customPB.Id ;
    o.LeadSource = 'Advertisement';
    o.ForecastCategoryName = 'Pipeline';
    o.StageName = 'Needs Analysis';
    o.Amount = 200.20 ;
    o.Products_Required__c = 'IMD';
    insert o;
   
    Quote i = new Quote();
    i.OpportunityId = o.id;
    i.Name= '170724508 - REV 001';
    i.Pricebook2Id = customPB.id;
    i.RecordTypeId = '012b00000001AxG';
    i.Approval_Status__c = 'Awaiting Approval';
    insert i;
     
    Quote i2 = new Quote();
    i2.OpportunityId = o.id;
    i2.Name= '170724508 - REV 001';
    i2.Pricebook2Id = customPB.id;
    i2.RecordTypeId = '012b00000001AxG';
    i2.Approval_Status__c = 'Granted';
    insert i2;
    
    QuoteLineItem Ql = new QuoteLineItem();
    Ql.QuoteId = i.id;
    Ql.Quantity = 24;
    Ql.UnitPrice = 240;
    Ql.Product2id = p.id;
    Ql.PricebookEntryId=custompbe.id;
    insert Ql;
    
        if(i.IsSyncing )
       {
           i.RecordTypeId = '012b00000001AxG';
           if(i.RecordTypeId == '012b00000001AxG' )  
           {
               if(i.Approval_Status__c == 'Awaiting Approval'){
           
               i.addError('You cannot sync this Quote as Discount Approval is needed and has not been granted.');  
               }
            }
         }
    }
}

Can anyone please help me.

Thanks,
Utz
Hello, 

I want to make dicount filed 0 if it left blank. How is it possible?

trigger QuotelineItemApproval on QuoteLineItem (after insert, after update) {

    List<Quote> parentObjList = new List<Quote>();
    List<ID> listIds = new List<ID>();
    List<Quote> listIds1 = new List<Quote>();
    
    //List <QuotelineItem> m3 = [select ID, Discount_Flag1__c from QuotelineItem where Discount_Flag1__c = : '1'];
    Boolean inRange ;
    
    String status  ='Not Required';
    String QuoteID ;
    Boolean isAwaiting = false;
    
    
    for (QuoteLineItem childObj : Trigger.new) {
        if(QuoteID == null) {
             QuoteID  = childObj.QuoteID;
        }    
    }
    
    Boolean changed = false;
    
    if(QuoteID  != null) {
        for(List<QuoteLineItem> items : [select ID, Discount_Flag1__c,Quantity ,Discount  from QuotelineItem where QuoteId= : QuoteID  ]) {
            for(QuoteLineItem item : items ) {
                inRange = false;
                changed  = true;
                if(item.Quantity >= 0 && item.Quantity <= 9 &&  item.Discount <= 0) {
                       inRange = true;
                } else {
                   if(item.Quantity >= 10 && item.Quantity <= 25 &&  item.Discount <= 5) {
                     inRange = true;
                   } else {
                      if(item.Quantity >= 26 && item.Quantity <= 49 &&  item.Discount <= 7) {
                         inRange = true;
                      } else {
                         if(item.Quantity >= 50  &&  item.Discount <= 10) {
                             inRange = true;
                         }
                      }
                   }
                }
                
                if(!inRange) {
                   isAwaiting  = true;              
                }  
                
                system.debug('***********+Quantity +*************'+item.Quantity);
                system.debug('***********+Discount +*************'+item.Discount);
                 
                system.debug('***********+inRange +*************'+inRange );
        
            } 
        } 
        
        
        system.debug('***********+isAwaiting  +*************'+isAwaiting  );
         
        if(changed ) {
           
           Id retVal = null;
           for(ProcessInstanceWorkitem workItem  : [Select p.Id from ProcessInstanceWorkitem p   where p.ProcessInstance.TargetObjectId =: QuoteID]) {
                retVal  =  workItem.Id;
           } 
           
           if(isAwaiting  ) {  
               status = 'Awaiting Approval'; 
           } else {
               status = 'Not Required';           
           }
           
           List<Quote> quotes = [select Id,Approval_Status__c  from Quote where Id =:QuoteID  ]; 
           
           if(quotes.size() > 0) {
               Quote QuoteDetails = quotes[0];
               if(retVal != null && status == 'Not Required') {
                       Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
                       req.setComments('Automatically approved as Approval is no longer required.'); 
                       req.setAction('Approve');
                       req.setNextApproverIds(new Id[] {UserInfo.getUserId()});  
                       req.setWorkitemId(retVal );    
                       Approval.ProcessResult result =  Approval.process(req);
               } 
                
               
               
           
               //QuoteDetails.IsSynching = false;
               QuoteDetails.Approval_Status__c  = status;
               update QuoteDetails;
           } 
        } 
    }
    
    
    
}

Thanks & Regards,
Utkarsha
Hello,

I want to make picklist field read only. There is no permission set. I make it read only from page layout, Field level security and profile too. Still its read only. What will be another option to make it rad only?

Thanks & Reagrds,
Utkarsha
Hello,

Is there any way to make standard sync button enable or disable on particular picklist condition?
Supposte Status= granted then i should able to sync and if Status = awaiting for approval then it should not sync.
I want to control it on statndard sync button on quote object

Thanks & Regards,
Utkarsha
Hello,

I am working on a quote object. In this approval process is not working. If below criteria is satisfied then approval process should fire and assigned approval should get notification to approve or reject record.
Quote Record Type: BenderINC - Industrial Quotes.

I dont know why this is happening. It was working earlier.

Thanks & Regards,
Utkarsha
Hello,

In related list of opportunity object we are using qoute. We are not able to create a qoute after click in on new button. New button on the qoute object is custom button which contains link. this link redirect us to the production. So as we dont have access of production we are not able to create new quote. We were trying to add buttons from page layout of related list of opportunity object. but when we click on setting icon it opens empty panel. We need a help to add standard new button on quote object. Is this possible?

Thanks & regards,
Utkarsha
Hello,

I am doing task where i want to delete share record but its giving me an error as shown below. 
"Insufficient Privileges
You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. For more information, see Insufficient Privileges Errors."

Account {"Party_Sea_ID__c":8375,"Customer_Number__c":"C3092","Name":"VILLAGE JEWELRY OUTLET OF KANNAPOLIS, INC.","DBA_Name__c":"VILLAGE JEWELRY OUTLET OF KANNAPOLIS, INC.","Customer_Group_Id__c":"a0028000015lr7TAAQ","OwnerId":"00528000003iGolAAE","owner1__c":"00528000003iL8FAAU","Terms_Id__c":"a042800000oV26ZAAS","Default_Currency__c":"US DOLLARS","No_of_Doors__c":0,"NumberOfEmployees":0,"Store_Size__c":0,"Status__c":0,"Sales_Code__c":"NONE","RecordTypeId":"01228000000QbiM","Asset_Credit_Limit__c":0,"Memo_Credit_Limit__c":0,"Outstanding_A_R_Balance__c":0,"Outstanding_Memo_Balance__c":0} Delete_Share: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00r28000020WN31AAG; first error: DELETE_FAILED, cannot delete owner or rule share rows, id=00r28000020WN31: [] Trigger.Delete_Share: line 29, column 1

My trigger is as followed.

trigger Delete_Share on Account (before update) {


set<Id> AccountIDs = new Set<Id>();
for(Account a: trigger.new){
AccountIDs.add(a.id);
}
List<AccountShare> jobShares = new List<AccountShare>();

map<String,AccountShare>accountShareMap = new Map<String,AccountShare>();

for(AccountShare accShare : [select AccountId,UserOrGroupId from AccountShare where AccountId in :AccountIds])
{
 accountShareMap.put(String.valueOf(accShare.UserOrGroupId),accShare);

}

for(Account a : trigger.new){
Account oldAccount = Trigger.OldMap.get(a.id);
if (a.owner1__c != null && a.owner1__c !=oldAccount.owner1__c) {
 
   AccountShare accountRecord = accountShareMap.get(string.valueOf(oldAccount.owner1__c)); 
    if (accountRecord  != null)
    jobShares.add(accountRecord);
  }
 }

if(jobShares.isEmpty() == false){
 delete jobShares;
 }
}

29th line is this :  delete jobShares;

Please help me. i dont know why is this happening.

Thanks & Best Regards,
Utkarsha