• Smike25
  • NEWBIE
  • 35 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 19
    Replies
Hello,

Looking for some assistance with a custom button i'm trying to create.  We use Conga Composer to send our sales orders and i'd like to prevent users from being able to generate the sales order they fully complete the customers billing address on the account.  I'm using Execute JavaScript trying to accomplish this, but getting the error "missing ) after arguement list.  It is probably something simple i'm missing.  Could someone take a look?
 
{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/37.0/apex.js")} 

if('{!Opportunity.Billing_Information_Complete_On_Account__c} <> true'){ 
alert ("Billing information on the Account must be completed"); 
} 
else{ 
window.open(https://composer.congamerge.com 
?sessionId={!API.Session_ID} 
&serverUrl={!API.Partner_Server_URL_290} 
&id={!Opportunity.Id} 
&ReportId=00Oi0000005RNJJ?pv0={!Opportunity.Id} 
&Contactid={!Opportunity.ContactId__c} 
&EmailToId={!Opportunity.ContactId__c} 
&EmailRelatedToId={!Opportunity.Id} 
&EmailSubject=Sales+Order+For+{!Opportunity.Sales_Order_Name_Calc__c} 
&TemplateId=a09i000000I8bbH 
&EmailTemplateID=00X31000000FstC 
&EmailTemplateAttachments=1 
&FP0=1 
&DS0=0 
&DS4=1 
&DS8=0 
&SC0=1 
&SC1=Attachments 
&UF0=1'); 
}

If possible i'd like to the throw in a redirect the that particular customers account url so the user can update the correct record, but right now i'm more concerned with just having the button function correctly
Hello,

I use a custom setting to allow me to disable workflow rules, validation rules, and processes in process builder. This has worked fine for months until today. We use this custom setting to allow administrators to be able to go around some of the rules in place for upserts, etc. while all other profiles are not affected by this.  Well today suddenly none of our processes are firing.  When the custom setting is removed from the criteria within the process it works fine and also works fine when logged in as an administrator. 

The code snippet we use in all the processes:

"NOT($Setup.Super_Admin_Settings__c.Disable_Validation_Rules__c)"

Looking for any help as this is now a major impact on our ORG and support ticket told us to use the communities for help.
Hello, 

Our ORG was trying to fire workflow rules off formula values.  After seeing that couldn't be done with a WFR, we decided to use a trigger.  The trigger is on the Account and checks the field Activity_Test__c.  If that date changes, we need that date value to change the value in the other field Activity_Status_Date__c.

The Trigger:
trigger CheckActivityDate on Account (before insert, before update) 
{
    for(Account a:Trigger.new)
    {
        if(system.trigger.OldMap.get(a.Id).Activity_Test__c != system.trigger.NewMap.get(a.Id).Activity_Test__c)
        {
            a.Activity_Status_Date__c = a.Activity_Test__c;
        }
    }
}
Upon running that it works correctly and is covered 75% through other test classes.  The only line that wasn't covered is "a.Activity_Status_Date__c = a.Activity_Test__c;" which is what i'm assuming my problem lies.  Do I need to build a standalone test class for this trigger or modify an existing one?  It is causing the other triggers to error with "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CheckActivityDate: execution of BeforeInsert"
 
Hey all!

Looking for some assistance with a trigger that would be used to count the total number of cases that are listed on a custom object we've built.  Trucks_Under_Warranty__c is the custom object we have built. 

Under Cases we have the field "Truck Under Warranty__c" which is a lookup(Trucks Under Warranty) Indexed and its controlling field is Account Name.  Gets a little confusing for the "Truck/Trucks" in the field names.  
Case field TUW

The field used to hold the count is named Case Count (Case_Count__c).  I could use some direction on the trigger due to it being on this custom object.  We're wanting a way to designate if a truck is problematic or not based upon how many cases are generated under it.

I had been trying to look at a snippit of code someone posted for counting cases on an contact to understand it and translate it to our ORG
trigger tskUpdatetrigger on Case (after insert, after update,after delete) {
    List<Case> lstCase = [select id, ContactId from Case where id in: trigger.newmap.keyset()];
    set<Id> sAccId = new set<Id>();

    for(Case cs: lstCase){
        if(cs.ContactId != null){
            sAccId.add(cs.ContactId);
        }
    }
    if(sAccId != null && sAccId.size() > 0){
        List<Contact> lstContact = [select id, Cases__c, (select id from Cases) from Contact where id in: sAccId];
        if(lstContact.size() > 0){
            for(Contact acc: lstContact){
                acc.Cases__c = acc.Cases.size();
            }
                      update lstContact;
            }
    }
}

But i'm not sure what to change "ContactId" to and it work with our custom object.  I've also tried to read through sfdcfox's example ( https://developer.salesforce.com/forums/?id=906F00000008zIxIAI ) but it is still a little out of my apex knowledge base.  

TLDR: Would love some help with writing a trigger to count the number of cases on a custom object
We are trying to create a trigger that will automatically change the owner of an opportunity based on a change from a set account name to a new one.

For instance, lets say we have an account named "John's Apples" that we house numerous opportunities under.  When someone opens and opportunity under it and changes the Account name from "John's Apples" to "Suzie's Oranges" we want the opportunity owner to change to whoever the owner is of "Suzie's Oranges".  Anyone think they'd be able to assist with that?
Hello Everyone, 

I've been trying to work on code that was left to our ORG by a developer who is no longer supporting us.  Not being too familiar with Apex, this is proving to be a daunting task for us and blocking us from implementing the triggers/classes that we've been working on.  I know it's a lengthy bit of code, but if someone could offer some assistance we'd be really grateful.  Currently we're getting the SQOL 101 errors with this code:
 
trigger UpdateTruckInventoryByOpportunity_Trgr on Opportunity (before update,before insert,after update, after insert, after delete, after undelete) {
    List<Truck_Inventory__c> lstTruck2Update = new List<Truck_Inventory__c>();
    
    Set<String> rt2bypass = new Set<String>{'Used Truck Quote','Accessory Order'};     
    Map<Id,RecordType> usedTruckQuoteRT = new Map<Id,RecordType>([Select SobjectType,Name,Id From RecordType Where SobjectType ='Opportunity' and Name in :rt2bypass]);
    
    RecordType usedRT = [Select SobjectType,Name,Id From RecordType Where SobjectType ='Truck_Inventory__c' and Name = 'Used' LIMIT 1];
    Map<Id,Truck_Inventory__c> mapNotUsedTruckInv = new Map<Id,Truck_Inventory__c>([Select Id,RecordTypeId From Truck_Inventory__c Where RecordTypeId =:usedRT.Id]);
    Set<String> setTruckInventories = new Set<String>();
    
    if(Trigger.isAfter){
        if(Trigger.isUpdate){
            for(Opportunity opp:Trigger.new){
                if(usedTruckQuoteRT.get(opp.RecordTypeId)==null){
                    

                     if(opp.Truck_Inventory__c!=null){
                        if(opp.StageName == 'Lost Deal - Truck Built' || opp.StageName == 'Lost Deal - Truck Not Built'){
                            lstTruck2Update.add(new Truck_Inventory__c(Id=opp.Truck_Inventory__c,Sold__c=false, Related_Quote_SO__c=null, Customer__c = null));
                        }else if(opp.StageName == 'Sales Order - Pending' || opp.StageName == 'Sales Order - Complete'){
                            lstTruck2Update.add(new Truck_Inventory__c(Id = opp.Truck_Inventory__c,Customer__c = opp.AccountId, Sold__c=true,Related_Quote_SO__c=opp.Id));
                        }else{
                            lstTruck2Update.add(new Truck_Inventory__c(Id=opp.Truck_Inventory__c, Sold__c=true,Related_Quote_SO__c=opp.Id));
                        }
                    }
                    
                    Opportunity oldOpp = Trigger.oldmap.get(opp.Id);
                    if(oldOpp.Truck_Inventory__c!=null && oldOpp.Truck_Inventory__c != opp.Truck_Inventory__c){
                        lstTruck2Update.add(new Truck_Inventory__c(Id=oldOpp.Truck_Inventory__c,Sold__c=false, Related_Quote_SO__c=null, Customer__c = null));
                    }
                    
                }
            }
        }else if(Trigger.isInsert || Trigger.isUndelete){
            for(Opportunity opp:Trigger.new){
                if(usedTruckQuoteRT.get(opp.RecordTypeId)==null) {
                    if(opp.Truck_Inventory__c!=null){         
                        lstTruck2Update.add(new Truck_Inventory__c(Id=opp.Truck_Inventory__c, Sold__c=true,Related_Quote_SO__c=opp.Id));
                    }
                }
            }
        }else if(Trigger.isDelete){
            for(Opportunity opp:Trigger.old){
                if(usedTruckQuoteRT.get(opp.RecordTypeId)==null){
                    if(opp.Truck_Inventory__c!=null){
                        lstTruck2Update.add(new Truck_Inventory__c(id=opp.Truck_Inventory__c,Sold__c=false, Related_Quote_SO__c=null));
                    }
                }
            }
        }
        if(!lstTruck2Update.isEmpty()){
            update lstTruck2Update;
        }
    
    }
    else{
        
        for(Opportunity opp:Trigger.new){
            if(usedTruckQuoteRT.get(opp.RecordTypeId)==null) {
                if(opp.Truck_Inventory__c!=null){
                    if(!mapNotUsedTruckInv.containsKey(opp.Truck_Inventory__c)){    
                        setTruckInventories.add(opp.Truck_Inventory__c);
                    }          
                }
            }
        }
        
        if(!setTruckInventories.isEmpty()){
            Map<String,String> mTruckInParent = new Map<String,String>();
            for(Truck_Inventory__c ti :[Select Truck__c, Id From Truck_Inventory__c where Id in :setTruckInventories]){
                mTruckInParent.put(ti.Id, ti.Truck__c);
            }
         
            for(Opportunity opp:Trigger.new){
                if(usedTruckQuoteRT.get(opp.RecordTypeId)==null) {
                    opp.Truck__c = mTruckInParent.get(opp.Truck_Inventory__c);
                }
            }
        }
    }
}

 
Looking for some help on writing my first trigger.  I have two custom objects ( Payroll [Payroll__c] and Commissions [Commissions__c] ).  The commissions object has the Master-Detail(Payroll) rollup field (Bonus Program [Bonus_Program__c]).

Payroll has two records record ID's in it, but i'm only concerned with one of them.  Any commission record created now will be eligible for a Bonus, and needs to be stamped with the Bonus record ID from Payroll (a0s230000008Rft).  The other ID contains all the records that were not eligible for a bonus.  I have a process that automatically creates a commission record based upon certain criteria, however now the process wont fire due to the "Bonus_Program__c" field being blank.  I can't seem to use process builder to automaticcaly assign the ID, so i'm looking at trying to create the trigger.  I've been trying some of the help posts through the community, but no luck so far getting much of anywhere.  
Hello, 

Our ORG was trying to fire workflow rules off formula values.  After seeing that couldn't be done with a WFR, we decided to use a trigger.  The trigger is on the Account and checks the field Activity_Test__c.  If that date changes, we need that date value to change the value in the other field Activity_Status_Date__c.

The Trigger:
trigger CheckActivityDate on Account (before insert, before update) 
{
    for(Account a:Trigger.new)
    {
        if(system.trigger.OldMap.get(a.Id).Activity_Test__c != system.trigger.NewMap.get(a.Id).Activity_Test__c)
        {
            a.Activity_Status_Date__c = a.Activity_Test__c;
        }
    }
}
Upon running that it works correctly and is covered 75% through other test classes.  The only line that wasn't covered is "a.Activity_Status_Date__c = a.Activity_Test__c;" which is what i'm assuming my problem lies.  Do I need to build a standalone test class for this trigger or modify an existing one?  It is causing the other triggers to error with "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CheckActivityDate: execution of BeforeInsert"
 
Hey all!

Looking for some assistance with a trigger that would be used to count the total number of cases that are listed on a custom object we've built.  Trucks_Under_Warranty__c is the custom object we have built. 

Under Cases we have the field "Truck Under Warranty__c" which is a lookup(Trucks Under Warranty) Indexed and its controlling field is Account Name.  Gets a little confusing for the "Truck/Trucks" in the field names.  
Case field TUW

The field used to hold the count is named Case Count (Case_Count__c).  I could use some direction on the trigger due to it being on this custom object.  We're wanting a way to designate if a truck is problematic or not based upon how many cases are generated under it.

I had been trying to look at a snippit of code someone posted for counting cases on an contact to understand it and translate it to our ORG
trigger tskUpdatetrigger on Case (after insert, after update,after delete) {
    List<Case> lstCase = [select id, ContactId from Case where id in: trigger.newmap.keyset()];
    set<Id> sAccId = new set<Id>();

    for(Case cs: lstCase){
        if(cs.ContactId != null){
            sAccId.add(cs.ContactId);
        }
    }
    if(sAccId != null && sAccId.size() > 0){
        List<Contact> lstContact = [select id, Cases__c, (select id from Cases) from Contact where id in: sAccId];
        if(lstContact.size() > 0){
            for(Contact acc: lstContact){
                acc.Cases__c = acc.Cases.size();
            }
                      update lstContact;
            }
    }
}

But i'm not sure what to change "ContactId" to and it work with our custom object.  I've also tried to read through sfdcfox's example ( https://developer.salesforce.com/forums/?id=906F00000008zIxIAI ) but it is still a little out of my apex knowledge base.  

TLDR: Would love some help with writing a trigger to count the number of cases on a custom object
Hello Everyone, 

I've been trying to work on code that was left to our ORG by a developer who is no longer supporting us.  Not being too familiar with Apex, this is proving to be a daunting task for us and blocking us from implementing the triggers/classes that we've been working on.  I know it's a lengthy bit of code, but if someone could offer some assistance we'd be really grateful.  Currently we're getting the SQOL 101 errors with this code:
 
trigger UpdateTruckInventoryByOpportunity_Trgr on Opportunity (before update,before insert,after update, after insert, after delete, after undelete) {
    List<Truck_Inventory__c> lstTruck2Update = new List<Truck_Inventory__c>();
    
    Set<String> rt2bypass = new Set<String>{'Used Truck Quote','Accessory Order'};     
    Map<Id,RecordType> usedTruckQuoteRT = new Map<Id,RecordType>([Select SobjectType,Name,Id From RecordType Where SobjectType ='Opportunity' and Name in :rt2bypass]);
    
    RecordType usedRT = [Select SobjectType,Name,Id From RecordType Where SobjectType ='Truck_Inventory__c' and Name = 'Used' LIMIT 1];
    Map<Id,Truck_Inventory__c> mapNotUsedTruckInv = new Map<Id,Truck_Inventory__c>([Select Id,RecordTypeId From Truck_Inventory__c Where RecordTypeId =:usedRT.Id]);
    Set<String> setTruckInventories = new Set<String>();
    
    if(Trigger.isAfter){
        if(Trigger.isUpdate){
            for(Opportunity opp:Trigger.new){
                if(usedTruckQuoteRT.get(opp.RecordTypeId)==null){
                    

                     if(opp.Truck_Inventory__c!=null){
                        if(opp.StageName == 'Lost Deal - Truck Built' || opp.StageName == 'Lost Deal - Truck Not Built'){
                            lstTruck2Update.add(new Truck_Inventory__c(Id=opp.Truck_Inventory__c,Sold__c=false, Related_Quote_SO__c=null, Customer__c = null));
                        }else if(opp.StageName == 'Sales Order - Pending' || opp.StageName == 'Sales Order - Complete'){
                            lstTruck2Update.add(new Truck_Inventory__c(Id = opp.Truck_Inventory__c,Customer__c = opp.AccountId, Sold__c=true,Related_Quote_SO__c=opp.Id));
                        }else{
                            lstTruck2Update.add(new Truck_Inventory__c(Id=opp.Truck_Inventory__c, Sold__c=true,Related_Quote_SO__c=opp.Id));
                        }
                    }
                    
                    Opportunity oldOpp = Trigger.oldmap.get(opp.Id);
                    if(oldOpp.Truck_Inventory__c!=null && oldOpp.Truck_Inventory__c != opp.Truck_Inventory__c){
                        lstTruck2Update.add(new Truck_Inventory__c(Id=oldOpp.Truck_Inventory__c,Sold__c=false, Related_Quote_SO__c=null, Customer__c = null));
                    }
                    
                }
            }
        }else if(Trigger.isInsert || Trigger.isUndelete){
            for(Opportunity opp:Trigger.new){
                if(usedTruckQuoteRT.get(opp.RecordTypeId)==null) {
                    if(opp.Truck_Inventory__c!=null){         
                        lstTruck2Update.add(new Truck_Inventory__c(Id=opp.Truck_Inventory__c, Sold__c=true,Related_Quote_SO__c=opp.Id));
                    }
                }
            }
        }else if(Trigger.isDelete){
            for(Opportunity opp:Trigger.old){
                if(usedTruckQuoteRT.get(opp.RecordTypeId)==null){
                    if(opp.Truck_Inventory__c!=null){
                        lstTruck2Update.add(new Truck_Inventory__c(id=opp.Truck_Inventory__c,Sold__c=false, Related_Quote_SO__c=null));
                    }
                }
            }
        }
        if(!lstTruck2Update.isEmpty()){
            update lstTruck2Update;
        }
    
    }
    else{
        
        for(Opportunity opp:Trigger.new){
            if(usedTruckQuoteRT.get(opp.RecordTypeId)==null) {
                if(opp.Truck_Inventory__c!=null){
                    if(!mapNotUsedTruckInv.containsKey(opp.Truck_Inventory__c)){    
                        setTruckInventories.add(opp.Truck_Inventory__c);
                    }          
                }
            }
        }
        
        if(!setTruckInventories.isEmpty()){
            Map<String,String> mTruckInParent = new Map<String,String>();
            for(Truck_Inventory__c ti :[Select Truck__c, Id From Truck_Inventory__c where Id in :setTruckInventories]){
                mTruckInParent.put(ti.Id, ti.Truck__c);
            }
         
            for(Opportunity opp:Trigger.new){
                if(usedTruckQuoteRT.get(opp.RecordTypeId)==null) {
                    opp.Truck__c = mTruckInParent.get(opp.Truck_Inventory__c);
                }
            }
        }
    }
}

 
Looking for some help on writing my first trigger.  I have two custom objects ( Payroll [Payroll__c] and Commissions [Commissions__c] ).  The commissions object has the Master-Detail(Payroll) rollup field (Bonus Program [Bonus_Program__c]).

Payroll has two records record ID's in it, but i'm only concerned with one of them.  Any commission record created now will be eligible for a Bonus, and needs to be stamped with the Bonus record ID from Payroll (a0s230000008Rft).  The other ID contains all the records that were not eligible for a bonus.  I have a process that automatically creates a commission record based upon certain criteria, however now the process wont fire due to the "Bonus_Program__c" field being blank.  I can't seem to use process builder to automaticcaly assign the ID, so i'm looking at trying to create the trigger.  I've been trying some of the help posts through the community, but no luck so far getting much of anywhere.