• Richard Pitfield 10
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 2
    Replies
Here is the trigger can anyone help please? 

trigger InboundFormTrigger on Inbound_Form__c (before insert, before update) {
    Trigger_Activation_Settings__c objCustomSetting = Trigger_Activation_Settings__c.getOrgDefaults();
    //test
    if(objCustomSetting != NULL && objCustomSetting.Is_Inbound_Form_Trigger_Active__c) {
        if(Trigger.New != NULL && Trigger.New.size() > 1) {
            System.debug('Not Supporting bulkification for this sprint.');
        } else {
            if (Trigger.IsBefore && (Trigger.isInsert || Trigger.isUpdate) && Trigger.New[0].Record_Validated__c && !Trigger.New[0].Is_Record_Processed__c) {
                
                Trigger.New[0].Is_Record_Processed__c = true;
                
                if(!String.isBlank(Trigger.New[0].Web_Form_Name__c)){
                    String strFormName = Trigger.New[0].Web_Form_Name__c.toLowerCase();
                    
                    if(strFormName == 'general enquiry form')
                        InboundFormTriggerHandler.generalEnquiryForm(Trigger.New);
                        
                    else if(strFormName == 'request for materials (donor)')
                        InboundFormTriggerHandler.requestForMaterialsDonor(Trigger.New);
                        
                    else if(strFormName == 'request for materials (press)')
                        InboundFormTriggerHandler.requestForMaterialsPress(Trigger.New);
                        
                    else if(strFormName == 'request for materials (solicitor)')
                        InboundFormTriggerHandler.requestForMaterialsSolicitor(Trigger.New);
                        
                    else if(strFormName == 'donor interest form')
                        InboundFormTriggerHandler.donorInterestForm(Trigger.New);
                        
                    else if(strFormName == 'solicitor registration')
                        InboundFormTriggerHandler.solicitorRegistration(Trigger.New);
                    
                    else if(strFormName == 'solicitor lookup')
                        InboundFormTriggerHandler.solicitorLookup(Trigger.New);
                    
                    else if(strFormName == 'solicitor enquiry')
                        InboundFormTriggerHandler.solicitorEnquiry(Trigger.New);  
                        
                    else if(strFormName == 'online donation form')
                        InboundFormTriggerHandler.onlineDonationForm(Trigger.New);                                     
                }
            }   
        }
    }
}

Hi there,

Below is some code I have in a custom button to tick a checkbox that runs a workflow rule

It has worked for almost a year and has now jut stopped working and I don't know why.

It runs the alerts but doesn't check the faculty Trial request box anymore, any help appreciated.

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject("Lead");
console.log("{!Lead.Faculty_Trial_test__c}");
if
("{!Lead.Faculty_Trial_test__c}" == "no")
{
alert("You can only request a Faculty Trial to SRM, Business or SAGE Video products. Plesae make sure you have added at least one of these products to the related Opportunity.");
}
if("{!Lead.Department__c}" == "")
{
alert("You must add a Department to request a Faculty Trial.");
}
if
("{!Lead.Email}" == "")
{
alert("You must add an Email to request a Faculty Trial.");
}
else
{
c.id ="{!Lead.Id}";
c.Faculty_Trial_Request__c = false;
c.Faculty_Trial_Request__c = true;
newRecords.push(c);
result = sforce.connection.update(newRecords);
window.location.reload();}
I have created the below script for a button on the lead object, it should tick the field Faculty Trial Request but doesn't any help appreciated, I've run this with for anotehr field Lead.Product in place of the Lead.FacultyTrial test field and it works fine.

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject("Lead");
if("{!Lead.Faculty_Trial_test__c}" == "no") {
alert("You can only request a Faculty Trial to SRM, Business or SAGE Video products. Pleae make sure you have added at least one of these products to the related Opportunity.");
}
if("{!Lead.Department__c}" == "") {
alert("You must add a Department to request a Faculty Trial.");
}
if("{!Lead.Email}" == "") {
alert("You must add an Email to request a Faculty Trial.");
} else {
c.id ="{!Lead.Id}";
c.Faculty_Trial_Request__c = false;
c.Faculty_Trial_Request__c = true;
newRecords.push(c);
result = sforce.connection.update(newRecords);
window.location.reload();}
I have the Custom Quote App installed and I have set some Formula fields on the Opportunity Quote Lineitem that sync and work fine with a custom field on the Quote Lineitem.
However when I run the tests it fails on the Formula field and states.

System.DmlException: Update failed. First exception on row 0 with id 0063300000j5pokAAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OppLineSyncTrigger: execution of AfterInsert

caused by: System.SObjectException: Field Total_Price__c is not editable

Trigger.OppLineSyncTrigger: line 128, column 1: []

It is saying that the Formula field is not editable, which is correct, but can anyone explain how to get around this so I can run succesful tests and add more triggers?

Why do the formula fields fail the test and how can I avoid this while keeping them syncing.

Regards

Rich
The trigger is failing tests this is the main fail reason. (The Field that's failing is a forumla field)
System.DmlException: Update failed. First exception on row 0 with id 0063300000j4vZzAAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OppLineSyncTrigger: execution of AfterInsert

caused by: System.SObjectException: Field Product_Type_quote_sync__c is not editable

Trigger.OppLineSyncTrigger: line 128, column 1: []

Here is the Trigger itself:

trigger OppLineSyncTrigger on OpportunityLineItem (before insert, after insert, after update) {
    
    if (trigger.isBefore && trigger.isInsert) {
        if (QuoteSyncUtil.isRunningTest) {
            for (OpportunityLineItem oli : trigger.new) {
                QuoteSyncUtil.populateRequiredFields(oli);
            }
        }    
        return;
    }
    
    if (TriggerStopper.stopOppLine) return;
       
    Set<String> quoteLineFields = QuoteSyncUtil.getQuoteLineFields();
    List<String> oppLineFields = QuoteSyncUtil.getOppLineFields();
    
    String qliFields = QuoteSyncUtil.getQuoteLineFieldsString();
    
    String oliFields =  QuoteSyncUtil.getOppLineFieldsString();
    
    String oliIds = '';
    for (OpportunityLineItem oli : trigger.new) {
        if (oliIds != '') oliIds += ', ';
        oliIds += '\'' + oli.Id + '\'';
    }

    String oliQuery = 'select Id, OpportunityId, PricebookEntryId, UnitPrice, Quantity, Discount, ServiceDate, SortOrder' + oliFields + ' from OpportunityLineItem where Id in (' + oliIds + ')';
    //System.debug(oliQuery); 
     
    List<OpportunityLineItem> olis = Database.query(oliQuery);
    
    Map<Id, List<OpportunityLineItem>> oppToOliMap = new Map<Id, List<OpportunityLineItem>>();    
    
    for (OpportunityLineItem oli : olis) {
        List<OpportunityLineItem> oliList = oppToOliMap.get(oli.OpportunityId);
        if (oliList == null) {
            oliList = new List<OpportunityLineItem>();
        } 
        oliList.add(oli);  
        oppToOliMap.put(oli.OpportunityId, oliList);       
    }

    Set<Id> oppIds = oppToOliMap.keySet();
    Map<Id, Opportunity> opps = new Map<Id, Opportunity>([select id, SyncedQuoteId from Opportunity where Id in :oppIds and SyncedQuoteId != null]);
    
    String quoteIds = '';
    for (Opportunity opp : opps.values()) {
        if (opp.SyncedQuoteId != null) {
           if (quoteIds != '') quoteIds += ', ';
           quoteIds += '\'' + opp.SyncedQuoteId + '\'';         
        }
    }
   
    if (quoteIds != '') {
           
        String qliQuery = 'select Id, QuoteId, PricebookEntryId, UnitPrice, Quantity, Discount, ServiceDate, SortOrder' + qliFields + ' from QuoteLineItem where QuoteId in (' + quoteIds + ')';   
        //System.debug(qliQuery);    
               
        List<QuoteLineItem> qlis = Database.query(qliQuery);
        
        Map<Id, List<QuoteLineItem>> quoteToQliMap = new Map<Id, List<QuoteLineItem>>();
        
        for (QuoteLineItem qli : qlis) {
            List<QuoteLineItem> qliList = quoteToQliMap.get(qli.QuoteId);
            if (qliList == null) {
                qliList = new List<QuoteLineItem>();
            } 
            qliList.add(qli);  
            quoteToQliMap.put(qli.QuoteId, qliList);       
        }
             
        Set<QuoteLineItem> updateQlis = new Set<QuoteLineItem>();
        Set<OpportunityLineItem> updateOlis = new Set<OpportunityLineItem>();
                        
        for (Opportunity opp : opps.values()) {  
        
            List<QuoteLineItem> quotelines = quoteToQliMap.get(opp.SyncedQuoteId);  
            
            // for opp line insert, there will not be corresponding quote line
            if (quotelines == null) continue;      
        
            Set<QuoteLineItem> matchedQlis = new Set<QuoteLineItem>();        
        
            for (OpportunityLineItem oli : oppToOliMap.get(opp.Id)) {
 
                boolean updateQli = false;
                OpportunityLineItem oldOli = null;
                
                if (trigger.isUpdate) {
                    //System.debug('Old oli: ' + oldOli.UnitPrice + ', ' + oldOli.Quantity + ', ' + oldOli.Discount + ', ' + oldOli.ServiceDate);
                    //System.debug('New oli: ' + oli.UnitPrice + ', ' + oli.Quantity + ', ' + oli.Discount + ', ' + oli.ServiceDate);
                                 
                    oldOli = trigger.oldMap.get(oli.Id);
                    if (oli.UnitPrice == oldOli.UnitPrice
                        && oli.Quantity == oldOli.Quantity
                        && oli.Discount == oldOli.Discount
                        && oli.ServiceDate == oldOli.ServiceDate
                        && oli.SortOrder == oldOli.SortOrder 
                       )
                        updateQli = true;  
                }
                                                   
                boolean hasChange = false;
                boolean match = false;
                                  
                for (QuoteLineItem qli : quotelines) {       
                    if (oli.pricebookentryid == qli.pricebookentryId 
                        && oli.UnitPrice == qli.UnitPrice 
                        && oli.Quantity == qli.Quantity 
                        && oli.Discount == qli.Discount
                        && oli.ServiceDate == qli.ServiceDate
                        && oli.SortOrder == qli.SortOrder
                       ) {
                       
                        if (updateQlis.contains(qli) || matchedQlis.contains(qli)) continue;
                        
                        matchedQlis.add(qli);                                                    
                                                                               
                        for (String qliField : quoteLineFields) {
                            String oliField = QuoteSyncUtil.getQuoteLineFieldMapTo(qliField);
                            Object oliValue = oli.get(oliField);                          
                            Object qliValue = qli.get(qliField);
                             
                            if (oliValue != qliValue) { 
                                                        
                                if (trigger.isInsert) {
                                    if (qliValue == null) oli.put(oliField, null);
                                   
 else oli.put(oliField, qliValue);
                                    hasChange = true;

                                } else if (trigger.isUpdate && !updateQli /*&& oldOli != null*/) {
                                    //Object oldOliValue = oldOli.get(oliField); 
                                    //if (oliValue == oldOliValue) {                                    
                                        if (qliValue == null) oli.put(oliField, null);
                                        else oli.put(oliField, qliValue);
                                        hasChange = true;
                                    //}    
                                                                        
                                } else if (trigger.isUpdate && updateQli) {
                                    if (oliValue == null) qli.put(qliField, null);
                                    else qli.put(qliField,  oliValue);
                                    hasChange = true;
                                }
                            }
                        }
                        if (hasChange) {
                            if (trigger.isInsert || (trigger.isUpdate && !updateQli)) { 
                                updateOlis.add(oli);
                            } else if (trigger.isUpdate && updateQli) { 
                                updateQlis.add(qli);
                            }                    
                        }
                        
                        match = true;                       
                        break;                
                    } 
                }
                                                                
                // NOTE: this cause error when there is workflow field update that fired during record create
                //if (trigger.isUpdate && updateQli) System.assert(match, 'No matching quoteline');     
            }
        }

        TriggerStopper.stopOpp = true;
        TriggerStopper.stopQuote = true;        
        TriggerStopper.stopOppLine = true;        
        TriggerStopper.stopQuoteLine = true;    
                    
        if (!updateOlis.isEmpty()) {  
            List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
            oliList.addAll(updateOlis);
                           
            Database.update(oliList);              
        }
        
        if (!updateQlis.isEmpty()) { 
            List<QuoteLineItem> qliList = new List<QuoteLineItem>();   
            qliList.addAll(updateQlis);
                          
            Database.update(qliList);            
        }                             
        
        TriggerStopper.stopOpp = false;
        TriggerStopper.stopQuote = false;         
        TriggerStopper.stopOppLine = false;          
        TriggerStopper.stopQuoteLine = false; 
    }
}

The line i've put ma strikethrough is the one causing the fail, any help would be very much appreciated.

Regards

Richard
trigger QuoteSentTrigger on Task (After insert) {
    List<Quote> QuoteToUpdate = new List<Quote>();

    for(Task t : Trigger.new) {
        if(t.WhatId.getSObjectType() == Quote.sObjectType &&
           t.Subject.startsWith('Email:')) {
                QuoteToUpdate.add(new Quote(Id = t.WhatId, Email_Quote_Sent__c = True));
        }
    }

    update QuoteToUpdate;
}

Most of the Test Failures state that "System.SObjectException: Field Product_Type_quote_sync__c is not editable" all of these fields appear on the opportunity object, i'm failry new to development, the trigger runs in the sandbox fine any help much appreciated.

Regards

Richard                             
Hi i'm looking to change the default send to, when the e-mail quote button is selected, from the Contact Roles object to my own personal contact field. How can I edit the e-mail quote button?

Regards
Rich

Hi there,

Below is some code I have in a custom button to tick a checkbox that runs a workflow rule

It has worked for almost a year and has now jut stopped working and I don't know why.

It runs the alerts but doesn't check the faculty Trial request box anymore, any help appreciated.

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject("Lead");
console.log("{!Lead.Faculty_Trial_test__c}");
if
("{!Lead.Faculty_Trial_test__c}" == "no")
{
alert("You can only request a Faculty Trial to SRM, Business or SAGE Video products. Plesae make sure you have added at least one of these products to the related Opportunity.");
}
if("{!Lead.Department__c}" == "")
{
alert("You must add a Department to request a Faculty Trial.");
}
if
("{!Lead.Email}" == "")
{
alert("You must add an Email to request a Faculty Trial.");
}
else
{
c.id ="{!Lead.Id}";
c.Faculty_Trial_Request__c = false;
c.Faculty_Trial_Request__c = true;
newRecords.push(c);
result = sforce.connection.update(newRecords);
window.location.reload();}
trigger QuoteSentTrigger on Task (After insert) {
    List<Quote> QuoteToUpdate = new List<Quote>();

    for(Task t : Trigger.new) {
        if(t.WhatId.getSObjectType() == Quote.sObjectType &&
           t.Subject.startsWith('Email:')) {
                QuoteToUpdate.add(new Quote(Id = t.WhatId, Email_Quote_Sent__c = True));
        }
    }

    update QuoteToUpdate;
}

Most of the Test Failures state that "System.SObjectException: Field Product_Type_quote_sync__c is not editable" all of these fields appear on the opportunity object, i'm failry new to development, the trigger runs in the sandbox fine any help much appreciated.

Regards

Richard