• Margaret Fleischaker
  • NEWBIE
  • 65 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 10
    Replies

Hello, I'm hoping someone can help me out! 

So this code is pretty basic in idea. A custom object is created or edited. It has numerous lookups to the user table (each representing a different type of relationship, for example: Field Rep).

The user table as number fields that this code is meant to decrement or increment.

The issue is this; when i made an adjustment to the user table, if i set a static value--its fine, example:

 

u.Sales_Area_Field_Rep__c=10;

But if I do something like the following, I get the de-reference error
u.Sales_Area_Field_Rep__c++;
u.Sales_Area_Field_Rep__c+=1;
u.Sales_Area_Field_Rep__c=u.Sales_Area_Field_Rep__c+1;

Here is a big snippet of the code. Any help would be REALLY appreciated. 

 

trigger UpdateSalesAreaToUserCount on Sales_Area__c (before insert, before update) {
    
String prefix = User.sObjectType.getDescribe().keyPrefix;
   
list <User> usersToUpdate= new List <User>{};
    if(Trigger.IsUpdate){
       for (Sales_Area__c co : Trigger.new) { 
  		 Sales_Area__c coOld = Trigger.oldMap.get(co.Id);
         
          //Begin Field Rep
 		   	if(coOld.Field_Rep__c != co.Field_Rep__c){
			if(!String.isBlank(coOld.Field_Rep__c))
            {
                User u = new User(Id = coOld.Field_Rep__c, Sales_Area_Field_Rep__c=coOld.Field_Rep__r.Sales_Area_Field_Rep__c);
                u.Sales_Area_Field_Rep__c++;
                usersToUpdate.add(u);           
            }
            if(!String.isBlank(co.Field_Rep__c))
            {
                User u = new User(Id = co.Field_Rep__c, Sales_Area_Field_Rep__c=co.Field_Rep__r.Sales_Area_Field_Rep__c);
                u.Sales_Area_Field_Rep__c=10;
                usersToUpdate.add(u);              
            }
I have a lightning component that includes an apex class to return a string. I would like the string that is returned to set a value in an event listener in the component's doInit function.

I can tell that communityURL is eventually getting set with the right string, so my connection to the apex class is working. However, I believe because I'm using $A.enqueueAction(action), it's happening AFTER I've already tried to set vfOrigin. So my vfOrigin is null, instead of the returned string. But if I don't use $A.enqueueAction(action), it doesn't appear to call the apex class at all.

Any suggestions for what I'm missing?
 
({
    doInit : function(component, event, helper) {
        // create a one-time use instance of the getCommunityURL action
        // in the server-side controller
        var action = component.get("c.getCommunityURL");
        console.log("[mf] action: " + action);

        var communityURL = '';
        action.setCallback(this, function(response){
        	var state = response.getState();
            if (state === "SUCCESS"){
                // alert the user with the value returned from the server
                alert("From server: " + response.getReturnValue());
                communityURL = response.getReturnValue();
                
            } else {
                console.log(state);
            }
        });
        $A.enqueueAction(action);

		// this section handles the reCaptcha that is in the embedded VF page
		// when the reCaptcha passes, make the submit button clickable
        // TODO: update with correct origin for production     
        //let vfOrigin = "https://mflei-eventbritecommunity.cs61.force.com";
        alert('[MF] communityURL: ' + communityURL);
        let vfOrigin = communityURL;
        window.addEventListener("message", function(event) {
            console.log(event.data);
            if (event.origin !== vfOrigin) {
                // Not the expected origin: Reject the message!
                alert('vfOrigin: ' + vfOrigin);
                alert('Not the expected origin: ' + event.origin);
                return;
            } 
            if (event.data==="Unlock"){ 
              let myButton = component.find("myButton");
              myButton.set('v.disabled', false);
            }            
        }, false);
    },

 
I'm creating a case in a custom lightning component using the Lightning Data Service. If I wanted the case assignment rules to fire, would I also have to have an apex class that uses the Database.DMLOptions? I'm assuming I can't use the following directly from the javascript controller?
 
//Fetching the assignment rules on case
AssignmentRule AR = new AssignmentRule();
AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];

//Creating the DMLOptions for "Assign using active assignment rules" checkbox
Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;

Case newCase = new Case(Status = 'New') ;
//Setting the DMLOption on Case instance
newCase.setOptions(dmlOpts);


 
I have a lightning component that is used in a community page to allow guests to create cases. I want to set the case origin by default without them seeing the value, so I've created a lightning:input field that I will eventually hide using CSS. I'm trying to set the value of that input field based on an attribute, but it's not working correctly. No values are getting set, and the console log I put after trying to set the value isn't getting logged, so something is clearly going wrong.

Any ideas of the correct way to do this? I feel like I must be missing something simple (hopefully). Below is the component and controller; I've tried to strip out unrelated code so it's easier to read and made the super relevant lines bold.
<aura:component implements="forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global" >
    <aura:attribute name="newCase" type="Object"/>
    <aura:attribute name="simpleNewCase" type="Object"/>    
    <aura:attribute name="caseOrigin" type="String" default="Email - Attendee TF Music"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <force:recordData aura:id="caseRecordCreator"
                      layoutType="FULL"
                      targetRecord="{!v.newCase}"
                      targetFields="{!v.simpleNewCase}"
                      targetError="{!v.recordSaveError}"/>
    
    <!-- Display the new case form -->
    <aura:if isTrue="{!v.showForm}">
    	<div class="Create Case">
            <lightning:input aura:id="caseField" label="Full Name" value="{!v.simpleNewCase.SuppliedName}" required="true" maxlength="80"/><br/>
            <lightning:input aura:id="caseField" label="Email" value="{!v.simpleNewCase.SuppliedEmail}" type="Email" required="true" maxlength="80"/><br/>
             
            <!-- hidden input to set the case origin by default-->
            <lightning:input aura:id="caseField" name="originField" label="Case Origin" value="{!v.simpleNewCase.Origin}"/><br/>
    
        <aura:set attribute="else">
            <p>Thank you for reaching out.</p>
            <p>The support team has received your email and will get back to you shortly.</p>
        </aura:set>
    </aura:if>

</aura:component>
({
    doInit : function(component, event, helper) {
		// Prepare a new record from template
		
		component.find("caseRecordCreator").getNewRecord(
        "Case", // sObjecttype
         "01239000000EGzv", // recordTypeId
         false, // skip cache
            $A.getCallback(function() {
                var rec = component.get("v.newCase");
                var error = component.get("v.recordSaveError");
                if(error || (rec === null)) {
                    alert("Error initializing record template" + error);
                    return;
                }

                var caseOrigin = component.get("v.caseOrigin");
                console.log("[MF] caseOrigin:" + caseOrigin);
                console.log("[MF] v.originField before: " + component.get("v.originField"));
 
                component.set(component.get("v.originField"), caseOrigin);
                // I've also tried the following, with no success:
                // component.set("v.originField", caseOrigin);

                console.log("[MF] v.originField after: " + component.get("v.originField"));
            })
        );
    },


 
I'm using the 'Create Case Form' component in a lightning community page, and I've enabled reCaptcha for it. I've verified by site keys are correct, but the reCaptcha isn't displaying properly on the page. I'm also not getting any sort of error message (even if I put in bogus keys). Any ideas what may be going wrong? Could it be related to the fact that I'm trying to use reCAPTCHA v2?

What I'm seeing:
User-added image

What I would expect to see (more or less)
User-added image
I'm trying to use the HTML generated from the web-to-case form to add reCaptcha to a web-to-case form in a Lightning Community component. I'm running into the error that the script tag is not allowed. I'm assuming this is because it is in Lightning. Is there a simple workaround? I've seen some comments online about building a Visualforce page with the  and including it in the HTML component as an iframe; is that the best approach?
 
<script src="https://www.google.com/recaptcha/api.js"></script>
<script>
 function timestamp() { var response = document.getElementById("g-recaptcha-response"); if (response == null || response.value.trim() == "") {var elems = JSON.parse(document.getElementsByName("captcha_settings")[0].value);elems["ts"] = JSON.stringify(new Date().getTime());document.getElementsByName("captcha_settings")[0].value = JSON.stringify(elems); } } setInterval(timestamp, 500); 
</script>

 
I have a quote trigger on after update. When I update the quote directly, the AccountId is included. However, when the quote is updated via a class that runs when a quote line item is saved, the AccountId is blank.

Here is a snippet of the code that updates the quote. This is in a controller extension for a visualforce page.
qlis.add(qli);
System.debug('qlis ' + qlis);
if(myQuote!=null){
	System.debug('[MF] myQuote: ' + myQuote);
	update myQuote;
}
upsert qlis;
return null;

/** The debug log**/
USER_DEBUG [260]|DEBUG|[MF] myQuote: Quote:{Id=0Q0Q0000000OkFDKA0, CurrencyIsoCode=USD}_

 Then, when I debug Trigger.new, the other quote fields are filled out, with the exception of AccountId. (I've removed some below for readability)
13:40:41:792 USER_DEBUG [3]|DEBUG|[MF] Trigger.new: (Quote:{Id=0Q0Q0000000OkFDKA0, OwnerId=00570000004PSo5AAG, IsDeleted=false, Name=Sol Food- - 00002565, CurrencyIsoCode=USD, OpportunityId=006Q000000Fl8mzIAB, Pricebook2Id=01sQ00000003jdzIAA, ContactId=003Q000001E0EFLIA3, QuoteNumber=00002565, IsSyncing=true, ExpirationDate=2017-10-26 00:00:00, AccountId=null, Discount=0.00, GrandTotal=4198.00, Start_Date__c=2017-10-26 00:00:00, Term_Months__c=24, End_Date__c=2019-10-25 00:00:00)
Why would AccountId be null in this scenario? Shouldn't all fields automatically be included in the trigger context? When I make an edit to the Quote directly, it is included.

Thanks in advance for any help!
 
Does anyone know if it's possible to write a trigger to automatically send out an event/meeting request with suggested times by Salesforce using the Cloud Scheduler functionality? I would like automate the steps where the user enters a subject, meeting place, indicates that salesforce should submit time options and the message (basically, everything in the screenshots below).

I can't find any documentation indicating if this is possible or not. Thanks!

User-added image

User-added image
We need to add a trigger on Lead insert that calls a web service and returns a value, setting a field on the Lead.

I know that I'll have to use the @future annotation. But am I going to run into limits if say, 500 leads are inserted at the same time? Instead of the below code...
Trigger newLeadTrigger on Trigger (after insert)
    for(Lead l : Trigger.new){
       Util.callWebService(l);
   }
} 


public class Util {
@future
  public void callWebService(Lead l){
     /* 
        Web service callout.
    */
  }
}
Would it be possible to do something like this, and only do one callout rather than 500?
Trigger newLeadTrigger on Trigger (after insert)
        Util.callWebService(Trigger.new);
}

public class Util {
@future
  public void callWebService(List<Lead> leads){
     /* 
        Web service callout.
    */
  }
}

I haven't worked with web services before and I'm obviously a little lost, so any guidance would be appreciated. Thanks!

 
I'm creating a case in a custom lightning component using the Lightning Data Service. If I wanted the case assignment rules to fire, would I also have to have an apex class that uses the Database.DMLOptions? I'm assuming I can't use the following directly from the javascript controller?
 
//Fetching the assignment rules on case
AssignmentRule AR = new AssignmentRule();
AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];

//Creating the DMLOptions for "Assign using active assignment rules" checkbox
Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;

Case newCase = new Case(Status = 'New') ;
//Setting the DMLOption on Case instance
newCase.setOptions(dmlOpts);


 
I have a lightning component that includes an apex class to return a string. I would like the string that is returned to set a value in an event listener in the component's doInit function.

I can tell that communityURL is eventually getting set with the right string, so my connection to the apex class is working. However, I believe because I'm using $A.enqueueAction(action), it's happening AFTER I've already tried to set vfOrigin. So my vfOrigin is null, instead of the returned string. But if I don't use $A.enqueueAction(action), it doesn't appear to call the apex class at all.

Any suggestions for what I'm missing?
 
({
    doInit : function(component, event, helper) {
        // create a one-time use instance of the getCommunityURL action
        // in the server-side controller
        var action = component.get("c.getCommunityURL");
        console.log("[mf] action: " + action);

        var communityURL = '';
        action.setCallback(this, function(response){
        	var state = response.getState();
            if (state === "SUCCESS"){
                // alert the user with the value returned from the server
                alert("From server: " + response.getReturnValue());
                communityURL = response.getReturnValue();
                
            } else {
                console.log(state);
            }
        });
        $A.enqueueAction(action);

		// this section handles the reCaptcha that is in the embedded VF page
		// when the reCaptcha passes, make the submit button clickable
        // TODO: update with correct origin for production     
        //let vfOrigin = "https://mflei-eventbritecommunity.cs61.force.com";
        alert('[MF] communityURL: ' + communityURL);
        let vfOrigin = communityURL;
        window.addEventListener("message", function(event) {
            console.log(event.data);
            if (event.origin !== vfOrigin) {
                // Not the expected origin: Reject the message!
                alert('vfOrigin: ' + vfOrigin);
                alert('Not the expected origin: ' + event.origin);
                return;
            } 
            if (event.data==="Unlock"){ 
              let myButton = component.find("myButton");
              myButton.set('v.disabled', false);
            }            
        }, false);
    },

 
I have a lightning component that is used in a community page to allow guests to create cases. I want to set the case origin by default without them seeing the value, so I've created a lightning:input field that I will eventually hide using CSS. I'm trying to set the value of that input field based on an attribute, but it's not working correctly. No values are getting set, and the console log I put after trying to set the value isn't getting logged, so something is clearly going wrong.

Any ideas of the correct way to do this? I feel like I must be missing something simple (hopefully). Below is the component and controller; I've tried to strip out unrelated code so it's easier to read and made the super relevant lines bold.
<aura:component implements="forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global" >
    <aura:attribute name="newCase" type="Object"/>
    <aura:attribute name="simpleNewCase" type="Object"/>    
    <aura:attribute name="caseOrigin" type="String" default="Email - Attendee TF Music"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <force:recordData aura:id="caseRecordCreator"
                      layoutType="FULL"
                      targetRecord="{!v.newCase}"
                      targetFields="{!v.simpleNewCase}"
                      targetError="{!v.recordSaveError}"/>
    
    <!-- Display the new case form -->
    <aura:if isTrue="{!v.showForm}">
    	<div class="Create Case">
            <lightning:input aura:id="caseField" label="Full Name" value="{!v.simpleNewCase.SuppliedName}" required="true" maxlength="80"/><br/>
            <lightning:input aura:id="caseField" label="Email" value="{!v.simpleNewCase.SuppliedEmail}" type="Email" required="true" maxlength="80"/><br/>
             
            <!-- hidden input to set the case origin by default-->
            <lightning:input aura:id="caseField" name="originField" label="Case Origin" value="{!v.simpleNewCase.Origin}"/><br/>
    
        <aura:set attribute="else">
            <p>Thank you for reaching out.</p>
            <p>The support team has received your email and will get back to you shortly.</p>
        </aura:set>
    </aura:if>

</aura:component>
({
    doInit : function(component, event, helper) {
		// Prepare a new record from template
		
		component.find("caseRecordCreator").getNewRecord(
        "Case", // sObjecttype
         "01239000000EGzv", // recordTypeId
         false, // skip cache
            $A.getCallback(function() {
                var rec = component.get("v.newCase");
                var error = component.get("v.recordSaveError");
                if(error || (rec === null)) {
                    alert("Error initializing record template" + error);
                    return;
                }

                var caseOrigin = component.get("v.caseOrigin");
                console.log("[MF] caseOrigin:" + caseOrigin);
                console.log("[MF] v.originField before: " + component.get("v.originField"));
 
                component.set(component.get("v.originField"), caseOrigin);
                // I've also tried the following, with no success:
                // component.set("v.originField", caseOrigin);

                console.log("[MF] v.originField after: " + component.get("v.originField"));
            })
        );
    },


 
I'm trying to use the HTML generated from the web-to-case form to add reCaptcha to a web-to-case form in a Lightning Community component. I'm running into the error that the script tag is not allowed. I'm assuming this is because it is in Lightning. Is there a simple workaround? I've seen some comments online about building a Visualforce page with the  and including it in the HTML component as an iframe; is that the best approach?
 
<script src="https://www.google.com/recaptcha/api.js"></script>
<script>
 function timestamp() { var response = document.getElementById("g-recaptcha-response"); if (response == null || response.value.trim() == "") {var elems = JSON.parse(document.getElementsByName("captcha_settings")[0].value);elems["ts"] = JSON.stringify(new Date().getTime());document.getElementsByName("captcha_settings")[0].value = JSON.stringify(elems); } } setInterval(timestamp, 500); 
</script>

 
Just last week I started getting issues with picklists that have restricted values.  I am creating records in a test and I have copied the value right from the picklist when I recreate it in my test.. however, the test is failing due to, "System.DmlException: Insert failed. First exception on row 1; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, bad value for restricted picklist field: Inter-Plan Preparing: [Cede_Status__c]"

I'm hoping there is just something I'm missing here?  

thanks!!

Fred
  • March 22, 2017
  • Like
  • 0

Hello, I'm hoping someone can help me out! 

So this code is pretty basic in idea. A custom object is created or edited. It has numerous lookups to the user table (each representing a different type of relationship, for example: Field Rep).

The user table as number fields that this code is meant to decrement or increment.

The issue is this; when i made an adjustment to the user table, if i set a static value--its fine, example:

 

u.Sales_Area_Field_Rep__c=10;

But if I do something like the following, I get the de-reference error
u.Sales_Area_Field_Rep__c++;
u.Sales_Area_Field_Rep__c+=1;
u.Sales_Area_Field_Rep__c=u.Sales_Area_Field_Rep__c+1;

Here is a big snippet of the code. Any help would be REALLY appreciated. 

 

trigger UpdateSalesAreaToUserCount on Sales_Area__c (before insert, before update) {
    
String prefix = User.sObjectType.getDescribe().keyPrefix;
   
list <User> usersToUpdate= new List <User>{};
    if(Trigger.IsUpdate){
       for (Sales_Area__c co : Trigger.new) { 
  		 Sales_Area__c coOld = Trigger.oldMap.get(co.Id);
         
          //Begin Field Rep
 		   	if(coOld.Field_Rep__c != co.Field_Rep__c){
			if(!String.isBlank(coOld.Field_Rep__c))
            {
                User u = new User(Id = coOld.Field_Rep__c, Sales_Area_Field_Rep__c=coOld.Field_Rep__r.Sales_Area_Field_Rep__c);
                u.Sales_Area_Field_Rep__c++;
                usersToUpdate.add(u);           
            }
            if(!String.isBlank(co.Field_Rep__c))
            {
                User u = new User(Id = co.Field_Rep__c, Sales_Area_Field_Rep__c=co.Field_Rep__r.Sales_Area_Field_Rep__c);
                u.Sales_Area_Field_Rep__c=10;
                usersToUpdate.add(u);              
            }