+ Start a Discussion
Sid LightningSid Lightning 

I have a field 'Site' on Users, which gets mapped to Opportunity once the user from that site creates an opportunity.

So , lets say if a user from Site A creates an opportunity , Opportunity will be stamped with Site A.

Now sometimes, there are transfers, so user from Site A gets transferred to Site B, I want to write an apex trigger , whenver a user gets transfferd from Site A to Site B. for All the opportunites created by him  , oppotunity owner should change to Site A manager..( sort of handover)  , Site A store managers role is "Site A".

How can we achieve this
Best Answer chosen by Sid Lightning
Martha VMartha V
To transfer the opportunities to the manager, you shouldn't use a trigger, but rather a button to run a process ( a flow, or apex code). The better choice would be a flow, and this seems to be a good case for it. 
The trigger could be the one to add the Site field to the opportunity, but you could also do this easier with Process Builder.
Roger Bannister 53Roger Bannister 53 
I have added a custom button to Quote object including an IF conditional statement , when the statement is true it functions correctly however if false instead of showing error message statement I get URL No Longer Exists error - please see code below. What can I do to fix this?
{!IF( ISPICKVAL( Quote.Status , 'Approved') , 

URLFOR('/apex/dsfs__DocuSign_CreateEnvelope', null, [SourceID = Quote.Id, 
CRL='Email~'+Quote.Email+';LastName~'+Quote.Full_Name__c+';Role~Signer 1,LoadDefaultContacts~0', 
]), "Quote must be submitted for approval") 

Best Answer chosen by Roger Bannister 53
Roger Bannister 53Roger Bannister 53
Thanks Sekar , I actually found the fix for this I needed to create a VF page (Error Message) and then reference it as URLFOR - see code below.

Regards, Roger

{!IF( ISPICKVAL( Quote.Status , 'Approved') , 
URLFOR('/apex/dsfs__DocuSign_CreateEnvelope', null, [SourceID = Quote.Id, 
CRL='Email~'+Quote.Email+';LastName~'+Quote.Full_Name__c+';Role~Signer 1,LoadDefaultContacts~0']), URLFOR('/apex/DocuSignQuoteNotApproved'))}
Matt Bronen 1Matt Bronen 1 
I'm trying to build a seemingly normal nested IF formula but when I use two different fields for the logical tests the second one doesn't seem to impact the reults. Original and updated formula below
ORIGINAL (Works normally):
IF(ISPICKVAL(Opportunity_Source__c, "Inbound"),0,Account.SDR_Sales_Contest_Value__c)

UPDATED (New condition doesn't seem to work):
IF(ISPICKVAL(Opportunity_Source__c, "Inbound"),0,IF( ISPICKVAL(Network__c, "Executive Referral (Advisors, Friends, Board)"),0, Account.SDR_Sales_Contest_Value__c))

Is there a way to change this to work with both picklists included? Thanks!
Best Answer chosen by Matt Bronen 1
Ajay K DubediAjay K Dubedi
Hi Matt,
Please check the type of your formula field that you have created and the type of SDR_Sales_Contest_Value__c field of account, if they both are text then replace 0 bt '0' from your formula as:
iF(ISPICKVAL(Opportunity_Source__c, "Inbound"), '0', IF( ISPICKVAL(Network__c, "Executive Referral (Advisors, Friends, Board)"), '0',  Account.SDR_Sales_Contest_Value__c))
The SDR_Sales_Contest_Value__c, formula field and value that you specify in your formula when the condition is true (0in your case) must be of the same type.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Ajay Dubedi
Hi Guys,

I'm trying to build a lightning component which will be used on Opportunity lightning UI. The component is placed in the right panel. The component loads pretty well on any Opportunity record view.

The problem here is when I try to update the opportunity record (which comes as popup block) the component in the right panel is not getting refreshed. By this the updated values are not showing up on the lightint component.

Need to find a way to refresh the lightning component on record save.

Any help would be appreciated!! 

Best Answer chosen by shra1_dev
Dave The GhostDave The Ghost
Here is the code from my test app. My use case was in context of the Accounts and contacts but it should apply to any object. As far as my understanding when ever an object is saved then the current view is refreshed. This is visible by the spinner that is displayed over the top panel of the object. I added a handler to my component that uses the force:refreshView (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_refreshView.htm) and just recalled my init method but could call another method if need be. This basically ensured that any time the object that was hosting the component was refreshed that my component would also refresh as well.

Here is the Component Code:
<aura:component controller="editRecordSimulationController"
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:dependency resource="markup://force:editRecord" type="EVENT" />
    <aura:handler event="force:refreshView" action="{!c.doInit}" />

    <aura:attribute name="recordId" type="string" />
    <aura:attribute name="accType" type="String" />
    <aura:attribute name="accObj" type="account" default="{ sObjectType: 'Account'}"/>
    <ui:inputText label="Record Id" value="{!v.recordId}" required="true"/>
	<ui:button class="btn" label="Submit" press="{!c.setOutput}"/>
    <br />
    <br />
    <br />
    Account Type: <ui:outputText value="{!v.accObj.Type}" />

Here is my Controller Code:
    doInit : function(component, event, helper) {
        var recordId = component.get("v.recordId");
        var action = component.get("c.getTypeFromAccount");
            	recordId: recordId
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var acc = response.getReturnValue();
                component.set("v.accType", acc.Type);
                component.set("v.accObj", acc)
	setOutput : function(component, event, helper) {
        var editRecordEvent = $A.get("e.force:editRecord");
             "recordId": component.get("v.recordId")

Kelly TetlockKelly Tetlock 
I am very new to Salesforce and have been struggling with writing a validation rule for a week now and am getting nowhere fast!  Essentially I want 3 fields to become required when data is entered into another field.  When a new Contact is created and an Email address is added to the Contact I want a picklist that will capture the Source of the Email, a date field that will capture when the Email was obtained and a text field that will capture who obtained the Email to become mandatory. On a net new record the rule should only run if an Email address is added.  To make matters even more difficult I will also have Contacts in my system that have been imported from a legacy CRM system.  These Contacts may not have an existing Email address.  I also want this rule to run if an Email is added to one of these existing records, or if the Email address on the existing record is changed and the three required fields I note above are blank.
I started out small with just the following.  The appropriate error message does show, but when I choose a picklist value and try to save the error message won't go away and won't let me save the record.


As I've mentioned, I'm very new to Salesforce and am still trying to understand how this validation function works. Any suggestions would be appreciated.
Best Answer chosen by Kelly Tetlock
Hi Kelly,

I think the formula will look like below (I also included the ISCLONE(), in case the record is cloned). You probably also need to change the field names below since I don't know their real API names.

   OR(ISBLANK(Email_Source__c), ISBLANK(Email_Date__c), ISBLANK(Email_Person__c))


So, I have the code running to create the .xfdf and attach it to the proper account.  Everything looked perfect, until I went to open my file.  Instead of the .xfdf opening and overlaying the online form, it instead downloads a new copy of itself.  Is there an issue in my xlm?  What am I doing wrong here.  Below is the code, and I have verified the .xfdf's are coming out correctly.


public with sharing class CreateIO {

    DateTime nowDT=System.now();
    String formatted=nowDT.format('MM-dd-yyyy');

private String getXmlString(JJSale__c a)

    String s = '<?xml version="1.0" encoding="UTF-8"?>' +
        '<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">' +
        '<f href="https://na11.salesforce.com/resource/1300398748000/IO_JJ"/>' +
        '<fields>' +
        '<field name="Acct Rep"><value>' + a.CreatedBy.Name + '</value></field>' +
        '<field name="Ad Cost"><value>' + a.Ad_Price__c + '</value></field>' +
        '<field name="Address"><value>' + a.Organization__r.BillingStreet + '</value></field>' +
        '<field name="Advertiser"><value>' + a.Organization__r.Name + '</value></field>' +
        '<field name="Bill to"><value>x</value></field>' +
        '<field name="City"><value>' + a.Organization__r.BillingCity + '</value></field>' +
        '<field name="Contact"><value>' + a.Contact__r.Name + '</value></field>' +
        '<field name="Date"><value>' + formatted + '</value></field>' +
        '<field name="Email"><value>' + a.Contact__r.Email + '</value></field>' +
        '<field name="Fax"><value>' + a.Contact__r.Fax + '</value></field>' +
        '<field name="INSERTION DATES AND NOTES 1"><value>' + a.Journal_Issue__r.Name + '</value></field>' +
        '<field name="INSERTION DATES AND NOTES 2"><value>' +
            a.Page_Requested__c + ', ' + a.Insertion_Notes__c + '</value></field>' +
        '<field name="Phone"><value>' + a.Contact__r.Phone + '</value></field>' +
        '<field name="State"><value>' + a.Organization__r.BillingState + '</value></field>' +
        '<field name="Todays Date"><value>' + formatted + '</value></field>' +
        '<field name="Zip"><value>' + a.Organization__r.BillingPostalCode + '</value></field>' +
        '</fields><ids original="CB86FA72BFC7A2744D5052A67D1686EE" modified="C0A949601A5BB74AB94C1DAA08D65D2F"/>' +
    return s;

public PageReference XFDFInit()
    JJSale__c a = [SELECT Id, CreatedBy.Name, Ad_Price__c, Organization__r.BillingStreet, Organization__r.Name,
                         Organization__r.BillingCity, Contact__r.Name, Contact__r.Email, Contact__r.Fax,
                         Journal_Issue__r.Name, Page_Requested__c, Insertion_Notes__c, Contact__r.Phone,
                         Organization__r.BillingState, Organization__r.BillingPostalCode
                         FROM JJSale__c
                         WHERE id = :ApexPages.currentPage().getParameters().get('id')];
    String xmlContent = getXmlString(a);
    Attachment attachment = new Attachment();
        attachment.Body = Blob.valueof(xmlContent);
        attachment.Name = a.Organization__r.Name + '_' + formatted + '.XFDF';
        attachment.ParentId = a.Organization__r.Id;
        insert attachment;
    PageReference orgPage = new PageReference('/' + a.Organization__r.id);
    return orgPage;

Best Answer chosen by Admin (Salesforce Developers) 

Thank you Ron Hess for solving my problem.  Its a browser issue.  The file didn't want to open in Chrome.  It actually does work!

Catalina OnukCatalina Onuk 
Hello everyone,
I’m struggling creating a formula.
I have created 2 date fields:
Employment Start Date, Employment Finish Date and addicionaly there are 3 fields (checkbox)
Employment sustained 3 Months
Employment sustained 6 Months
Employment sustained 12 Months
If the difference between Employment Finish date and Start date is greater than 3 months so the checkbox Employment sustained 3 Months must be checked equally for 6 and 12 months.
Addicionally, if the Employment finish date is blank and the difference between today’s date and start date is greater than 3 then the Employment sustained 3 Months must be checked.
I don’t know how to add all this conditions in a formula.
Could you help me please?
thanks in advance
Best Answer chosen by Catalina Onuk
Andrew GAndrew G
Assuming that the 3 x check boxes are formula fields.
Create a formula field - named "Day Count" - type Number - formula (don't display on page layout if not required to be seen)
IF( ISBLANK( End_Date__c), TODAY() - Start_Date__c, End_Date__c - Start_Date__c)

for each individual check box, formula field = type checkbox
 3 Months - IF( Day_Count__c > 90, TRUE, FALSE)
 6 Months -  IF( Day_Count__c > 180, TRUE, FALSE)
12 Months -  IF( Day_Count__c > 365, TRUE, FALSE)

Rudimentary, but would do the job.

Olavo ZapataOlavo Zapata 
Hi all,

I'm trying to create a trigger to generate an autonumber that will only count in specific use cases on Customer Object.
For example, when the client has Active Status and has a project end date.

However, with the code I wrote this giving me an error when I'm trying to update or insert any information to the Customer.
trigger AutonumberOnlyISOnb on JBCXM__CustomerInfo__c (after insert, after update) {
    list<JBCXM__CustomerInfo__c> l= [SELECT Id,Name,IS_Autonumber__c FROM JBCXM__CustomerInfo__c where IS_Autonumber__c !=:null order by IS_Autonumber__c desc limit 1];
    decimal maxacc = l[0].IS_Autonumber__c;
   for(JBCXM__CustomerInfo__c li:trigger.new) {
       if(li.JBCXM__Status__c == 'a0U1a000000H1GiEAK' &&
           li.Onboarding_End_Date__c != null
     li.IS_Autonumber__c = Integer.valueOf(maxacc)+1;
Error:Apex trigger AutonumberOnlyISOnb caused an unexpected exception, contact your administrator: AutonumberOnlyISOnb: execution of AfterUpdate caused by: System.FinalException: Record is read-only: ()
Do you know what could be?

Best Answer chosen by Olavo Zapata
Olavo ZapataOlavo Zapata
Hi Glyn and Craig,

With both your help now it is working. Thanks a lot for that.

In the first time, I was trying to do the action with a before instead an after but was showing me an error of no record to update.
With Craig's help, I create the list to save the information from the loop as his example. But that showed some errors as well.
Now backing to use an before its working.

The final code if someone would like to try:
trigger AutonumberOnlyISOnb on JBCXM__CustomerInfo__c (before insert, before update){
    list<JBCXM__CustomerInfo__c> l= [SELECT Id,Name,IS_Autonumber__c FROM JBCXM__CustomerInfo__c WHERE IS_Autonumber__c !=:null ORDER BY IS_Autonumber__c DESC LIMIT 1];
    decimal maxacc = l[0].IS_Autonumber__c;
    List<JBCXM__CustomerInfo__c> LiList = new List<JBCXM__CustomerInfo__c>();
    for(JBCXM__CustomerInfo__c li:trigger.new) {
        if(li.JBCXM__Status__c == 'a0U1a000000H1GiEAK' && li.Onboarding_End_Date__c != null) {
            li.IS_Autonumber__c = Integer.valueOf(maxacc)+1;
Thanks guys,
Peter Davids 4Peter Davids 4 

Hi all,

We need to implement the following pattern at my org:
  • callout to external data source
  • if that callout takes too long (according to some configurable threshold), log an error (ie do some DML)
  • if that callout timed out on the remote server, try it again
Recognizing the potential for the dreaded "You have uncommitted work pending. Please commit or rollback before calling out." error, I put the error logging code in a future method, thus isolating the DML from the callouts. However, the error is still being thrown. I reduced the issue down to this pattern:
public static void foo() {
    Http http = new Http();
    HttpRequest req = new Httprequest();
    req.setEndpoint('https://test.salesforce.com'); //whatever endpoint
    http.send(req); //works fine
    http.send(req); //throws calloutexception

@future public static void bar() {

Am I correct to assume that calling a future method counts as a DML operation? Is there any documentation I'm missing somewhere?

Best Answer chosen by Peter Davids 4
Peter Davids 4Peter Davids 4
Muhariz JabeerMuhariz Jabeer 
Is it possible to pass tokens (i.e.: custom field values within a Work Order or Service Appointment) from the FSL Mobile App to the Salesforce App, without using a fully qualified url?

I have successfully created a custom App Extension (under Field Service Mobile Settings) to launch the main Salesforce App and bring up a Lightning Page Tab. I simply specified the name of the Lightning Page in the Launch Value of the App Extension.

However, this lightning page houses a VisualForce page that requires parameters to be sent to it from the FSL app. I have not been able to do this using the above method.

Thoug, I have managed to get it working by explicitly setting the Launch Value in the App Extension to the URL of the VisualForce page (with the parameter I want tacked to the end. (i.e.: https://XXX/apex/FSLExtensionA?myparameter=someValue). This method works fine on Android, as Android prompts whether to open this link via the Salesforce App (as opposed to a web browser). It does NOT work on iOS as it simply opens the link on safari.

In summary, is there a way to pass parameters to a VisualForce page without using a fully qualified url? The Doco claims it is possible, if you house a VisualForce page within a lightning tab in the Salesforce app --> https://help.salesforce.com/articleView?id=mfs_extension.htm&type=5  - unfortunately I haven't been able to figure out how.
Best Answer chosen by Muhariz Jabeer
Muhariz JabeerMuhariz Jabeer
I found that the answer is Salesforce Deep Links - You can navigate to the Salesforce app from an external app(s) using Salesforce Deep Links: