• Erik Laramee
  • NEWBIE
  • 50 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 9
    Replies
Hey Folks,

I am writing my first non-tutorial trigger and could use some help. What is supposed to happen is that when an RFI record of record type A is created and child Submittal record should also be created. I need to set a bunch of field values but I am comfortable with that, just trying to get the skeleton to work. However, when I create an RFI with record type A no Submittal record is created. This is my trigger. Issue_Tracker__c is the lookup on the Submittal to the RFI

trigger NewSubmittal on Request_for_Information_RFI__c (after insert) {
    
    for ( Request_for_Information_RFI__c ss : trigger.new) {
        
        if( ss.RecordTypeId == '012800000007gsp' )
        
            continue;
        
        Submittal_1__c s = new Submittal_1__c();
        s.Issue_Tracker__c = ss.Id;
        
        insert s;
        
    }

}
Hey Folks, I have a validation rule on a field for NOT( ISCHANGED) ). I have a button that is triggering this rule when pressed even though the field has been changed. I can't figure out a way around it. Any ideas? This is the button:

{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")} 

try { 
var newRecords = []; 
var c = new sforce.SObject("Request_for_Information_RFI__c"); 
c.id ="{!Request_for_Information_RFI__c.Id}"; 
c.Submit_RFI__c= true; 
c.Approval_Submitted__c= true; 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 

if( result[0].getBoolean( "success" ) ) { 
window.location.reload(); 

else { 
alert( "An error has occurred. Error:" + result ); 


catch( e ) { 
alert( "An unexpected error has occurred. Error:" + e ); 
}

Hey Folks,

We have a two step approval process for one of our objects. The first step uses the standard approval process and once approved, the second step uses an existing OnClick javascript button to set the final approval status. The button just does a page refresh showing the new value without saving the record. This is preventing me from using workflows that trigger off the final value.

Previously the standard process locked the record which I believe is why the code was written this way. It has since been changed to unlock the record, so saving it post standard approval will no longer be an issue. I would like to be able to modify this button to save the record, if possible, so that I can trigger workflows. Can someone help me with the code or point me in the right direction? This is the code for the button:

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}  
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}  
var connection = sforce.connection; 

var ConReqID ="{!Con_Req__c.Id}"; 
var ChangeOrderType ="{!Con_Req__c.Change_Order_Type__c}"; 
var status="{!Con_Req__c.Status__c}"; 

if(status!='Approved'){ 
alert('Status should be Approved before pressing Approved By Customer Button'); 

else if (ConReqID && ConReqID != "") 

/* var ConReq = new sforce.SObject("Con_Req__c"); 
ConReq.Id = ConReqID; 
ConReq.Status__c = "Approved By Customer"; 
connection.update([ConReq]); */ 
sforce.apex.execute("ChangeOrderApprovalRequest","SendApprovalRequest", {id:ConReqID}); 
window.parent.location.href='/'+ConReqID ; 

I am trying to modify an existing trigger to change how a field is populated. The field is called Project PM on the Con Req Group object. Project PM is populated from the Owner field (lookup to User) on the Project object. I need to modify it so that Project PM is populated from the Project Manager field (also lookup to User) on the Site object. I believe this is done by line 63 of the code. I tried modifying it but am getting an invalid field message on line 63 - crg.Project_PM__c = pMap.get(crg.Project__c).OwnerId; . Can anyone assist in this?

trigger ConReqGroup on Con_Req_Group__c (after update, before delete, before insert, before update) {
    
    /*
     *    Before delete
     *        - only allow delete if the record is not locked
     *
     *    Before insert and before update
     *        - set the Project PM field to the OwnerId field of the associated Project
     *        - set the Ship To address fields from the related Site record
     *        - if before update, make sure the Sales Order field is not changed
     *
     *    After update
     *        - copy the "group" fields to the associated Sales Order Line records
     *
     */
    
    if (trigger.isBefore) {
        Set<Id> pIds = new Set<Id>();
        Set<Id> sIds = new Set<Id>();
        if (trigger.isDelete) {
            for (Con_Req_Group__c crg :trigger.old) {
                if (crg.IsLocked__c) {
                    crg.addError('Record is locked - cannot delete a locked record.');
                }
            }
        } else {
            for (Con_Req_Group__c crg :trigger.new) {
                if (trigger.isUpdate) {
                    // Don't allow a change to the Sales Order field
                    if (crg.Sales_Order__c != trigger.oldMap.get(crg.Id).Sales_Order__c) {
                        crg.Sales_Order__c.addError('Field is not writeable.');
                    }
                    
                    if (crg.Project__c != null && crg.Project__c != trigger.oldMap.get(crg.Id).Project__c) {
                        pIds.add(crg.Project__c);
                    }
                    
                    if (crg.Ship_To_Site__c != null && crg.Ship_To_Site__c != trigger.oldMap.get(crg.Id).Ship_To_Site__c) {
                        sIds.add(crg.Ship_To_Site__c);
                    }
                } else {
                    if (crg.Project__c != null) {
                        pIds.add(crg.Project__c);
                    }
                    if (crg.Ship_To_Site__c != null){
                        sIds.add(crg.Ship_To_Site__c);
                    }
                }
            }
            
            Map<Id, AcctSeed__Project__c> pMap = null;
            if (!pIds.isEmpty()) {
                pMap = new Map<Id, AcctSeed__Project__c>([select Id, OwnerId from AcctSeed__Project__c where Id in :pIds]);
            }
            
            Map<Id, Site__c> sMap = null;
            if (!sIds.isEmpty()) {
                sMap = new Map<Id, Site__c>([select Id, Site_Address__c, Site_City__c, Site_State__c, Site_Zip__c from Site__c where Id in :sIds]);
            }
            
            for (Con_Req_Group__c crg :trigger.new) {
                if (pMap != null && pMap.containsKey(crg.Project__c)) {
                    crg.Project_PM__c = pMap.get(crg.Project__c).OwnerId;
                }
                
                if (sMap != null && sMap.containsKey(crg.Ship_To_Site__c)) {
                    crg.Ship_To_Street__c = sMap.get(crg.Ship_To_Site__c).Site_Address__c;
                    crg.Ship_To_City__c = sMap.get(crg.Ship_To_Site__c).Site_City__c;
                    crg.Ship_To_State__c = sMap.get(crg.Ship_To_Site__c).Site_State__c;
                    crg.Ship_To_Zip__c = sMap.get(crg.Ship_To_Site__c).Site_Zip__c;
                }
            }
        }
    }
    
    if (trigger.isAfter) {
        List<Id> crgIds = new List<Id>();
        for (Con_Req_Group__c crg :trigger.new) {
            if ( (crg.Project__c != trigger.oldMap.get(crg.Id).Project__c) || 
                 (crg.Project_PM__c != trigger.oldMap.get(crg.Id).Project_PM__c) || 
                 (crg.Ship_to_Account__c != trigger.oldMap.get(crg.Id).Ship_to_Account__c) || 
                 (crg.Status__c != trigger.oldMap.get(crg.Id).Status__c) || 
                 (crg.Vendor__c != trigger.oldMap.get(crg.Id).Vendor__c) || 
                 (crg.Vendor_Contact__c != trigger.oldMap.get(crg.Id).Vendor_Contact__c) || 
                 (crg.Requested_Delivery_Date__c != trigger.oldMap.get(crg.Id).Requested_Delivery_Date__c) ) {
                crgIds.add(crg.Id);
            }
        }
        
        if (!crgIds.isEmpty()) {
            List<AcctSeedERP__Sales_Order_Line__c> solList = new List<AcctSeedERP__Sales_Order_Line__c> ();
            solList = [select Id, AcctSeedERP__Project__c, Project_PM__c, AcctSeedERP__Sales_Order__c, 
                        Ship_to_Account__c, Status__c, Vendor__c, Vendor_Contact__c, 
                        Requested_Delivery_Date__c, Con_Req_Group__c 
                        from AcctSeedERP__Sales_Order_Line__c where Con_Req_Group__c in :crgIds];
            
            for (AcctSeedERP__Sales_Order_Line__c sol :solList) {
                sol.AcctSeedERP__Project__c = trigger.newMap.get(sol.Con_Req_Group__c).Project__c;
                sol.Project_PM__c = trigger.newMap.get(sol.Con_Req_Group__c).Project_PM__c;
                sol.Ship_to_Account__c = trigger.newMap.get(sol.Con_Req_Group__c).Ship_to_Account__c;
                sol.Status__c = trigger.newMap.get(sol.Con_Req_Group__c).Status__c;
                sol.Vendor__c = trigger.newMap.get(sol.Con_Req_Group__c).Vendor__c;
                sol.Vendor_Contact__c = trigger.newMap.get(sol.Con_Req_Group__c).Vendor_Contact__c;
                sol.Requested_Delivery_Date__c = trigger.newMap.get(sol.Con_Req_Group__c).Requested_Delivery_Date__c;
            }
            
            if (!solList.isEmpty()) {
                update solList;
            }
        }
    }
}
I am the kind of person that 'knows enough to be dangerous' so I am trying to make a change to a VF page and having some difficulty with it. We use one VF page for New and Edit buttons for a custom object. Currently, we have a field 'Tax Group" that is read only on creation but editable after the record has been created. I'd like to change the 'Tax Group' field that displays on creation to a formula field from another object. A 2nd but less preferable solution is to hide the field from view with creating the record. Formula field (percent field type) is straightfoward - Object__r.Tax_Percent__c. This is what the section of that page currently looks like.

        <apex:pageBlockSection columns="2" title="Purchase Order Changes" collapsible="false"> 
                    <apex:inputField value="{!Con_Req__c.Tax_Rate__c}" rendered="{!taxExempt == false}"/>
                    <apex:outputField value="{!Con_Req__c.Tax_Rate__c}" rendered="{!taxExempt}"/>                         
                </apex:pageBlockSection> 

I've tried changing the first line under the page block section to this, hoping it was a simple tweak:
<apex:inputField value="{!Con_Req__c.Tax_Rate__c}" rendered="{!taxExempt == !Object__r.Tax_Percent__c}"/> but I get an error -
Unknown property 'Con_Req__cStandardController.Object__r'

This is the first line on the VF Page with the controller statement.
<apex:page standardController="Con_Req__c" extensions="con_req" action="{!setProj}">

Is anyone able to helpwith this? Again, being able to hide the field is an option if displaying the formula field is not.

Many thanks!
 
Can someone help me understand why this code works as a detail page button but not a list view button? I need to be able to multi-select before performing the action.

{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 

var po = new sforce.SObject("Object__c"); 
po.id = "{!Object__c.Id}"; 

po.Checkbox__c = true; 

result = sforce.connection.update([po]); 

window.location.reload();

With the developer console open I get this error:
connection.js:594 Refused to set unsafe header "User-Agent"send @ connection.js:594sforce.SoapTransport.send...
Hi Folks, I am trying to modify a class to include and additional profile (profile name is Procurement). This is the snippet I am attempting to modify.
        profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  Name = 'Engineering- Apps Engineer'];
        return !profiles.isEmpty();

I append ,'Procurement' to the line as such:
        profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  Name = 'Engineering- Apps Engineer','Procurement'];
        return !profiles.isEmpty();

But I get the error: Error: Compile Error: expecting right square bracket, found ',' at line 72 column 119. Can someone help me out with what I'm missing here? Thanks!
Hey Folks, I'm investigating a route mapping tool to best plan driving route - when users visit a location, it will plot out accounts along the way so that they have options to reach out etc. Doing my own searching on tthe AppEchange butwould welcome suggestions on good apps for that and feedback on how they worked, or did not meet expections etc.
Hey Folks,

I am writing my first non-tutorial trigger and could use some help. What is supposed to happen is that when an RFI record of record type A is created and child Submittal record should also be created. I need to set a bunch of field values but I am comfortable with that, just trying to get the skeleton to work. However, when I create an RFI with record type A no Submittal record is created. This is my trigger. Issue_Tracker__c is the lookup on the Submittal to the RFI

trigger NewSubmittal on Request_for_Information_RFI__c (after insert) {
    
    for ( Request_for_Information_RFI__c ss : trigger.new) {
        
        if( ss.RecordTypeId == '012800000007gsp' )
        
            continue;
        
        Submittal_1__c s = new Submittal_1__c();
        s.Issue_Tracker__c = ss.Id;
        
        insert s;
        
    }

}
Hey Folks, I have a validation rule on a field for NOT( ISCHANGED) ). I have a button that is triggering this rule when pressed even though the field has been changed. I can't figure out a way around it. Any ideas? This is the button:

{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")} 

try { 
var newRecords = []; 
var c = new sforce.SObject("Request_for_Information_RFI__c"); 
c.id ="{!Request_for_Information_RFI__c.Id}"; 
c.Submit_RFI__c= true; 
c.Approval_Submitted__c= true; 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 

if( result[0].getBoolean( "success" ) ) { 
window.location.reload(); 

else { 
alert( "An error has occurred. Error:" + result ); 


catch( e ) { 
alert( "An unexpected error has occurred. Error:" + e ); 
}
I am trying to modify an existing trigger to change how a field is populated. The field is called Project PM on the Con Req Group object. Project PM is populated from the Owner field (lookup to User) on the Project object. I need to modify it so that Project PM is populated from the Project Manager field (also lookup to User) on the Site object. I believe this is done by line 63 of the code. I tried modifying it but am getting an invalid field message on line 63 - crg.Project_PM__c = pMap.get(crg.Project__c).OwnerId; . Can anyone assist in this?

trigger ConReqGroup on Con_Req_Group__c (after update, before delete, before insert, before update) {
    
    /*
     *    Before delete
     *        - only allow delete if the record is not locked
     *
     *    Before insert and before update
     *        - set the Project PM field to the OwnerId field of the associated Project
     *        - set the Ship To address fields from the related Site record
     *        - if before update, make sure the Sales Order field is not changed
     *
     *    After update
     *        - copy the "group" fields to the associated Sales Order Line records
     *
     */
    
    if (trigger.isBefore) {
        Set<Id> pIds = new Set<Id>();
        Set<Id> sIds = new Set<Id>();
        if (trigger.isDelete) {
            for (Con_Req_Group__c crg :trigger.old) {
                if (crg.IsLocked__c) {
                    crg.addError('Record is locked - cannot delete a locked record.');
                }
            }
        } else {
            for (Con_Req_Group__c crg :trigger.new) {
                if (trigger.isUpdate) {
                    // Don't allow a change to the Sales Order field
                    if (crg.Sales_Order__c != trigger.oldMap.get(crg.Id).Sales_Order__c) {
                        crg.Sales_Order__c.addError('Field is not writeable.');
                    }
                    
                    if (crg.Project__c != null && crg.Project__c != trigger.oldMap.get(crg.Id).Project__c) {
                        pIds.add(crg.Project__c);
                    }
                    
                    if (crg.Ship_To_Site__c != null && crg.Ship_To_Site__c != trigger.oldMap.get(crg.Id).Ship_To_Site__c) {
                        sIds.add(crg.Ship_To_Site__c);
                    }
                } else {
                    if (crg.Project__c != null) {
                        pIds.add(crg.Project__c);
                    }
                    if (crg.Ship_To_Site__c != null){
                        sIds.add(crg.Ship_To_Site__c);
                    }
                }
            }
            
            Map<Id, AcctSeed__Project__c> pMap = null;
            if (!pIds.isEmpty()) {
                pMap = new Map<Id, AcctSeed__Project__c>([select Id, OwnerId from AcctSeed__Project__c where Id in :pIds]);
            }
            
            Map<Id, Site__c> sMap = null;
            if (!sIds.isEmpty()) {
                sMap = new Map<Id, Site__c>([select Id, Site_Address__c, Site_City__c, Site_State__c, Site_Zip__c from Site__c where Id in :sIds]);
            }
            
            for (Con_Req_Group__c crg :trigger.new) {
                if (pMap != null && pMap.containsKey(crg.Project__c)) {
                    crg.Project_PM__c = pMap.get(crg.Project__c).OwnerId;
                }
                
                if (sMap != null && sMap.containsKey(crg.Ship_To_Site__c)) {
                    crg.Ship_To_Street__c = sMap.get(crg.Ship_To_Site__c).Site_Address__c;
                    crg.Ship_To_City__c = sMap.get(crg.Ship_To_Site__c).Site_City__c;
                    crg.Ship_To_State__c = sMap.get(crg.Ship_To_Site__c).Site_State__c;
                    crg.Ship_To_Zip__c = sMap.get(crg.Ship_To_Site__c).Site_Zip__c;
                }
            }
        }
    }
    
    if (trigger.isAfter) {
        List<Id> crgIds = new List<Id>();
        for (Con_Req_Group__c crg :trigger.new) {
            if ( (crg.Project__c != trigger.oldMap.get(crg.Id).Project__c) || 
                 (crg.Project_PM__c != trigger.oldMap.get(crg.Id).Project_PM__c) || 
                 (crg.Ship_to_Account__c != trigger.oldMap.get(crg.Id).Ship_to_Account__c) || 
                 (crg.Status__c != trigger.oldMap.get(crg.Id).Status__c) || 
                 (crg.Vendor__c != trigger.oldMap.get(crg.Id).Vendor__c) || 
                 (crg.Vendor_Contact__c != trigger.oldMap.get(crg.Id).Vendor_Contact__c) || 
                 (crg.Requested_Delivery_Date__c != trigger.oldMap.get(crg.Id).Requested_Delivery_Date__c) ) {
                crgIds.add(crg.Id);
            }
        }
        
        if (!crgIds.isEmpty()) {
            List<AcctSeedERP__Sales_Order_Line__c> solList = new List<AcctSeedERP__Sales_Order_Line__c> ();
            solList = [select Id, AcctSeedERP__Project__c, Project_PM__c, AcctSeedERP__Sales_Order__c, 
                        Ship_to_Account__c, Status__c, Vendor__c, Vendor_Contact__c, 
                        Requested_Delivery_Date__c, Con_Req_Group__c 
                        from AcctSeedERP__Sales_Order_Line__c where Con_Req_Group__c in :crgIds];
            
            for (AcctSeedERP__Sales_Order_Line__c sol :solList) {
                sol.AcctSeedERP__Project__c = trigger.newMap.get(sol.Con_Req_Group__c).Project__c;
                sol.Project_PM__c = trigger.newMap.get(sol.Con_Req_Group__c).Project_PM__c;
                sol.Ship_to_Account__c = trigger.newMap.get(sol.Con_Req_Group__c).Ship_to_Account__c;
                sol.Status__c = trigger.newMap.get(sol.Con_Req_Group__c).Status__c;
                sol.Vendor__c = trigger.newMap.get(sol.Con_Req_Group__c).Vendor__c;
                sol.Vendor_Contact__c = trigger.newMap.get(sol.Con_Req_Group__c).Vendor_Contact__c;
                sol.Requested_Delivery_Date__c = trigger.newMap.get(sol.Con_Req_Group__c).Requested_Delivery_Date__c;
            }
            
            if (!solList.isEmpty()) {
                update solList;
            }
        }
    }
}
Can someone help me understand why this code works as a detail page button but not a list view button? I need to be able to multi-select before performing the action.

{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 

var po = new sforce.SObject("Object__c"); 
po.id = "{!Object__c.Id}"; 

po.Checkbox__c = true; 

result = sforce.connection.update([po]); 

window.location.reload();

With the developer console open I get this error:
connection.js:594 Refused to set unsafe header "User-Agent"send @ connection.js:594sforce.SoapTransport.send...
Hi Folks, I am trying to modify a class to include and additional profile (profile name is Procurement). This is the snippet I am attempting to modify.
        profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  Name = 'Engineering- Apps Engineer'];
        return !profiles.isEmpty();

I append ,'Procurement' to the line as such:
        profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  Name = 'Engineering- Apps Engineer','Procurement'];
        return !profiles.isEmpty();

But I get the error: Error: Compile Error: expecting right square bracket, found ',' at line 72 column 119. Can someone help me out with what I'm missing here? Thanks!
Hey Folks, I'm investigating a route mapping tool to best plan driving route - when users visit a location, it will plot out accounts along the way so that they have options to reach out etc. Doing my own searching on tthe AppEchange butwould welcome suggestions on good apps for that and feedback on how they worked, or did not meet expections etc.

Does anyone know why an email alert triggered from a workflow would not be creating the associated activity history? Emails sent through the interface, through Apex, and through the API are all logged in activity history (when the appropriate information is set). The email alert is set to be sent to the Contact Email (standard) field.

Thanks!