• Banwari Kevat
  • NEWBIE
  • 30 Points
  • Member since 2017
  • R System International

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 20
    Replies
Hi ,
I am trying to create a trigger to update two custom fields on Lead object with two values from a Custom object. The trigger is getting executed but it is not working as expected i.e. Branch Name and Distance to Branch are not getting populated. 

Here is the Trigger code
trigger UpdateBranchAndDistanceToBranch on Lead (before insert) {
Set<Id> lstLeadsToUpdate = new Set<Id>();    
    for( Lead l : trigger.new )
    {  system.debug('l.PostalCode....' + l.PostalCode);
        //Get the list of all leads that need an update
        If(l.PostalCode != null && l.Branch_Name__C == null )
        {    
            lstLeadsToUpdate.add(l.Id);
        }
    }
    if(lstLeadsToUpdate.isEmpty() == false)
    {
     List<Lead> finallstLeadsToUpdate=new List<Lead>();
     List<Lead> listLeads = [SELECT id,Branch_Name__c,Distance_To_Branch__c, PostalCode  from Lead WHERE Id in :lstLeadsToUpdate];
       system.debug('listLeads ...' + listLeads);
     For (Lead oLead : listLeads) 
        {   
         Serviced_Postal_Code__c sp=[select Sub_Branch__c,Distance_From_Branch_mi__c from Serviced_Postal_Code__c where Postal_Code__c= : oLead.PostalCode];
         Lead c=new Lead(Id=oLead.Id);
       
         system.debug('sp.Sub_Branch__c..' + sp.Sub_Branch__c);
         system.debug('sp.Distance_From_Branch_mi__c..' + sp.Distance_From_Branch_mi__c);
       
         c.Branch_Name__c =  sp.Sub_Branch__c;
         c.Distance_To_Branch__c  =  sp.Distance_From_Branch_mi__c; 
         finallstLeadsToUpdate.add(c);   
         }  
      
        if (finallstLeadsToUpdate.size()>0)
           {
                update finallstLeadsToUpdate;
            }  
    }               

}
First debug statement(system.debug('l.PostalCode....' + l.PostalCode);) is displaying the postal code that i am keying in for the lead.
The debug log is showing zero rows for "SELECT id,Branch_Name__c,Distance_To_Branch__c, PostalCode  from Lead WHERE Id in :lstLeadsToUpdate"

I am unable to figure out what am I missing in the code that is causing the issue.

Kindly let me know where am I going wrong.

Thanks
Rao

 
  • January 11, 2019
  • Like
  • 0
I am getting the  error at following line
 User-added image
component.set("v.items",items);

Controller code: 
({
    doInit : function(component, event, helper){
        var getItemsAction = component.get("c.getItems");
        getItemsAction.setCallback(scope, function(response){
            var state = response.getState();
            if(state=="SUCCESS"){
                var items = response.getReturnValue();
                component.set("v.items",items);
            }
            
        });
        $A.enqueueAction(getItemsAction);
        
    },
    clickCreateItem : function(component, event, helper) {
           helper.createItem(component);
    }
})

and Helper
({
    createItem : function(component) {
        var newItem = component.get("v.newItem");
        var newItem1 = JSON.parse(JSON.stringify(newItem));
        var items = component.get("v.items");
        items.push(newItem1);
        component.set("v.items",items);
        component.set("v.newItem", {'sobjectType':'Camping_Item__c','Name':'','Quantity__c':0,'Price__c':0,'Packed__c':false});
        /*var saveItemAction = component.get("c.saveItem");
        saveItemAction.setParams({campingItem:newItem1});
        saveItemAction.setCallback(scope, function(response){
            var state = response.getState(); alert(state);
            if(state=="SUCCESS"){
            }
        });
        $A.enqueueAction(saveItemAction); */
    }
})

coponent code
<aura:component controller="CampingListController">
    <aura:attribute name="newItem" Type="Camping_Item__c" default="{'sObjectType':'Camping_Item__c','Quantity__c':0,'Price__c':0,'Name':'test'}"/>
    <aura:attribute name="items" Type="Camping_Item__c[]" />
    <aura:handler name="init" action="{!c.doInit}" value="{!this}" />
    
    <ol>
        <li>Bug Spray</li>
        <li>Bear Repellant</li>
        <li>Goat Food</li>
    </ol>
    
    <form class="slds-form--stacked" aura:id="campingform">
        <lightning:input  aura:id="newItemName" label="Camping Item Name" value="{!v.newItem.Name}" />
        <lightning:input aura:id="newItemPrice" label="Price" value="{!v.newItem.Price__c}" Type="number"
                         namename="campingPrice"
                         min="0.1"
                         formatter="currency"
                         step="0.1"
                         messageWhenRangeUnderflow="Enter an Price that's at least 0.1."/>
        <lightning:input aura:id="newItemQuantity" label="Quantity" type="Integer" value="{!v.newItem.Quantity__c}" min="1"/>
        <lightning:input aura:id="newItemPacked" label ="Packed" checked="{!v.newItem.Packed__c}" type="checkbox"/>
        <lightning:button label="Submit" onclick="{! c.clickCreateItem}" />
    </form>
    
    <div class ="slds-card slds-p-top--meduim">
        <header class ="slds-card__header">
            <h3 class = "slds-text-heading--small">Items</h3>
        </header>
        <section class ="slds-card__body">
            <div id="list" class = "row">
                <aura:iteration items="{!v.items}" var="itemVar">
                    <c:campingListItem item="{!itemVar}"/>
                </aura:iteration>
            </div>
        </section>
    </div>
</aura:component>



Please help me on the issue.

 
Hi experts,
 I am unable to see any element in Palette, Resources or explorer.
You can see as below screenshots

User-added imageUser-added imageUser-added image

Any help will be appreciated.
Hi Team,

I want to hide Liightning componet Close Button(Top right corner) or cross button.User-added image 
when i click on quick action then one of lightning component assosciated with it and open, but need to remove close button.

Please suggest

 
Create a field on Account object:
Field Label: Number OF Contacts
Data Type: Number (2,0)
Visible to All Profiles and Add it to the Page Layouts.
Write an apex trigger to populate the new field in case if Account undergoes any update with Count of Contact records under it. Example: Account "ABC Corp" has 3 contacts. I update this account record today, new field should have a value of 3. If I create a new account then this field should have value as 0. If now I create a contact under it, count should be increased to 1. If I delete a contact, the count should be reduced by 1.
Hi
I'm playing with an Apex trigger for Work Order Object.   In the trigger,I have a need to reference a list of Work Types on multiple occassions, in different parts of the trigger.  The question relates to how do I minimise the number of times I do a SOQL to get those work types.
Example of Trigger
trigger cs_workorderTrigger on WorkOrder (before insert, after insert, after update) {
    if ( trigger.isBefore ) {
        if ( trigger.isInsert ) {
            CS_WorkOrderTriggerHandler.handleBeforeInsert( trigger.new );
	}
    } else {  //trigger is after
        if ( trigger.isInsert ) {
            CS_WorkOrderTriggerHandler.handleAfterInsert( trigger.new );
        } else {
            CS_WorkOrderTriggerHandler.handleAfterUpdate( trigger.new );
	}
    }
}
And my (cut down) hanlder looks like:
public with sharing class CS_WorkOrderTriggerHandler {
			
	public static void handleBeforeInsert(List<WorkOrder> newWorkOrders) {
		populateWorkOrder( newWorkOrders );
	}

	public static void handleAfterInsert(List<WorkOrder> workOrders){
		//declare some variables 
		List<Id> listWorkTypeIds = new List<Id>();

		//List of Ids where their is an auto generate feature enabled
		List<Worktype> workTypes = new List<WorkType>([SELECT Id FROM WorkType WHERE ShouldAutoCreateSvcAppt = TRUE]);

		for ( WorkOrder workOrder : workOrders ) {
			//do some stuff with work Order - like checking the work type Id
		}
	}


	public static void handleAfterUpdate(List<WorkOrder> oldWorkOrders, List<WorkOrder> workOrders, Map<Id,WorkOrder> newValues, Map<Id,WorkOrder> oldValues) {
		//declare some variables 
		List<Id> listWorkTypeIds = new List<Id>();

		//List of Ids where their is an auto generate feature enabled - HEY , THIS IS THE SAME AS THE AFTER INSERT QUERY

		for ( WorkOrder workOrder : workOrders ) {
			//do some other stuff with the work orders, and I still need the work type ids, but this work here is different to the after Insert stuff so i can't combine into a single method.
		}
	}

	public static void populateWorkOrder(List<WorkOrder>workOrders) {
		System.debug('DEBUG: populate Work Order');
		//Here I am going to do some other stuff, and I need that slightly different list of that Work Type Ids
		//something like 
		List<workType> workTypes = new List<WorkType>([SELECT Id,Customer_Type__c,Name FROM WorkType WHERE ShouldAutoCreateSvcAppt = TRUE]);
		//and play with the list a bit differently
	}

	public static void createServiceAppointments(WorkOrder workOrder, Integer saToCreate ) {
		//Create some records here
	}
	
}

I tried doing a constructor at the top of the trigger handler, but I was getting errors like "non static method can be called form static method" or something like that.  It basically broke the other methods I have within the trigger handler.

Any pointers appreciated.

Andrew G
Hi ,

We have requirement where we need to fetch maximum number of records from Salesforce by calling SOQL through SOAP Api in our DotNet Code. Keeping in view the governor limits we set Limit 50000 in our SOQL and it was working fine for months but now in past few 2 weeks it started giving following error when SOQL runs through SOAP API.

INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session hash: CoCuOVP4fYbJhzxMKONd9HFIw7kGz9/ZEBHwT7Ed0PY= This error usually occurs after a session expires or a user logs out._

if we reduce the limit size to 4000 or less SOQL runs without any issues.Please suggest what could have gone wrong ?

Thank you in advance!!!
 

Hi 
As per my understanding in REST service  following annotation we can use
            @HttpGet     : get record read access only
            @HttpPost     : create new record
            @HttpDelete : Delete record
            @HttpPut     : upsert data
            @HttpPatch  : update data 

Can we  delete record in @HttpGet method() in REST call as HttpGet is just used to read record

Hi all,

I am trying to write trigger which throws an error on account delete if Contact Type contains Signatory and Application Status is Approved.

Code works fine if I only try to write trigger based on Contact Type field, but when I try to add second condition it does nothing.

trigger preventSigAccDeletion on Account (before delete) {
        for(Account acc : trigger.old){
            if( acc.Contact_type__c.contains ('Signatory')
             && acc.Application_status__c == 'Approved')
           
            
            acc.adderror('Signatory Accounts cannot be deleted. Please contact administrator if you need it to be deleted or merged');
}
}

Thanks in advance.

 
Hi ,
I am trying to create a trigger to update two custom fields on Lead object with two values from a Custom object. The trigger is getting executed but it is not working as expected i.e. Branch Name and Distance to Branch are not getting populated. 

Here is the Trigger code
trigger UpdateBranchAndDistanceToBranch on Lead (before insert) {
Set<Id> lstLeadsToUpdate = new Set<Id>();    
    for( Lead l : trigger.new )
    {  system.debug('l.PostalCode....' + l.PostalCode);
        //Get the list of all leads that need an update
        If(l.PostalCode != null && l.Branch_Name__C == null )
        {    
            lstLeadsToUpdate.add(l.Id);
        }
    }
    if(lstLeadsToUpdate.isEmpty() == false)
    {
     List<Lead> finallstLeadsToUpdate=new List<Lead>();
     List<Lead> listLeads = [SELECT id,Branch_Name__c,Distance_To_Branch__c, PostalCode  from Lead WHERE Id in :lstLeadsToUpdate];
       system.debug('listLeads ...' + listLeads);
     For (Lead oLead : listLeads) 
        {   
         Serviced_Postal_Code__c sp=[select Sub_Branch__c,Distance_From_Branch_mi__c from Serviced_Postal_Code__c where Postal_Code__c= : oLead.PostalCode];
         Lead c=new Lead(Id=oLead.Id);
       
         system.debug('sp.Sub_Branch__c..' + sp.Sub_Branch__c);
         system.debug('sp.Distance_From_Branch_mi__c..' + sp.Distance_From_Branch_mi__c);
       
         c.Branch_Name__c =  sp.Sub_Branch__c;
         c.Distance_To_Branch__c  =  sp.Distance_From_Branch_mi__c; 
         finallstLeadsToUpdate.add(c);   
         }  
      
        if (finallstLeadsToUpdate.size()>0)
           {
                update finallstLeadsToUpdate;
            }  
    }               

}
First debug statement(system.debug('l.PostalCode....' + l.PostalCode);) is displaying the postal code that i am keying in for the lead.
The debug log is showing zero rows for "SELECT id,Branch_Name__c,Distance_To_Branch__c, PostalCode  from Lead WHERE Id in :lstLeadsToUpdate"

I am unable to figure out what am I missing in the code that is causing the issue.

Kindly let me know where am I going wrong.

Thanks
Rao

 
  • January 11, 2019
  • Like
  • 0
Hi All,

We are facing a strange error while saving a record.
We have multicurrecy enable for our org and on opportunity we have a field "Net Value" which is a curreny field (18,0) and we have written a custom lightning component to create/edit a opportunity, we do not use classic anymore.
Issue which we are seeing are coming only for european countries but not on all opportunity records.

On some records when user which is also the owner of opportunity tries to save opportunity they get NUMBER_OUTSIDE_VALID_RANGE error on "Net Value" field but we do not have any code written which change field value. But when same record is been saved by Admin who is not the owner of opportunity then error do not comes and goes away permanently. 

We are not able to understand why Lightning behaving like this, Did anyone come across any error like this.

Thanks in Advance,
Puneet.
Hey guys,

I would like to create a date formula that takes the last day of the current month and subtracts 7 business days from it. This part isn't too complicated to do with the Weekday function, but how would be the best way to deal with holidays. For example Christmas is right around the corner, so how could I tell this formula, without necessarily hardcoding it every year, to not ever count the 25th day of December? Here's kind of the foundation of my formula: (IF( MONTH( TODAY() ) = 12,
DATE( YEAR( TODAY() ), 12, 31 ),
DATE( YEAR( TODAY() ), MONTH( TODAY() ) + 1, 1) - 1) - 7
but I'm not sure where to start on the Holidays issue and I haven't had much luck using the Sobject Holidays..

Thanks!!!
Hi,

I am working on salesforce integration with Amazon using Amazon MWS. I am getting error code 403 and status : Forbidden.
"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details." 

I have used every possible way to resolve this but getting same error again and again.
Code is given below:
public class Amazon_Integration {
    
    public String action = 'SubmitFeed';
    public String FeedType ='_POST_PRODUCT_DATA_';
    Public string accessKey = 'AKIexampleOKHWA';
    Public string MarketplaceId = 'AexampleDER';
    Public string SellerId = 'AUexampleRCX';
    Public string SignatureMethod='HmacSHA256';
    Public string SignatureVersion='2';    
    Public string version='2009-01-01';
    Public string amazonSecretKey='9YexampleWQMeM';
    Public string mwstoken = 'amzn.mws.example.9f650';
    public string endpoint = 'https://mws.amazonservices.com/Feeds/2009-01-01';        
    
    //Prepare the feed 
	public String prepare_body(String sellerId){
        
       String xmlBody = '<?xml version="1.0" encoding="UTF-8"?>' + 
                     '<AmazonEnvelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">'+
                         '<Header>' +
                         '<DocumentVersion>1.01</DocumentVersion>' +
                         '<MerchantIdentifier>' + sellerId + '</MerchantIdentifier>' +
                         '</Header>' +
                         '<MessageType>Product</MessageType>' +                         
                         '<Message>' +
                             '<MessageID>1</MessageID>' +
                             '<OperationType>Update</OperationType>' +
                             '<Product>' +
                                 '<SKU>56789</SKU>' +
                                 '<StandardProductID>' +
                                 '<Type>ASIN</Type>' +
                                 '<Value>B0EXAMPLEG</Value>' +
                                 '</StandardProductID>' +
                                 '<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>' +
                                 '<DescriptionData>' +
                                     '<Title>Example Product Title</Title>' +
                                     '<Brand>Example Product Brand</Brand>' +
                                     '<Description>This is an example product description.</Description>' +
                                     '<BulletPoint>Example Bullet Point 1</BulletPoint>' +
                                     '<BulletPoint>Example Bullet Point 2</BulletPoint>' +
                                     '<MSRP currency="USD">25.19</MSRP>' +
                                     '<Manufacturer>Example Product Manufacturer</Manufacturer>' +
                                     '<ItemType>example-item-type</ItemType>' +
                                  '</DescriptionData>' +
                                  '<ProductData>' +
                                    '<Health>' +
                                      '<ProductType>' +
                                        '<HealthMisc>' +
                                          '<Ingredients>Example Ingredients</Ingredients>' +
                                          '<Directions>Example Directions</Directions>' +
                                        '</HealthMisc>' +
                                      '</ProductType>' +
                                     '</Health>' +
                                   '</ProductData>' +
                                '</Product>' +
                             '</Message>' +
                           '</AmazonEnvelope>';                                              
            
            return xmlBody;
    }
    
    public String get_contentmd5(String xmlBody){
        	Blob targetBlob = Blob.valueOf(xmlBody);
        	Blob hash = Crypto.generateDigest('MD5', targetBlob);    
        	String contentMD5 = EncodingUtil.base64Encode(hash);
        	contentMD5 =  EncodingUtil.URLENCODE(contentMD5,'UTF-8');                    
        	return contentMD5;
    }
    
    public string send_feed_to_amazon(String xmlBody, String ContentMD5){

        String timestamp = datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'');
        timestamp = EncodingUtil.urlEncode(timestamp,'UTF-8');
        
        //Construct a query string with the query information
        String queryString = 'AWSAccessKeyId=' + accessKey + 
            '&Action=SubmitFeed'+
            '&ContentMD5Value=' + ContentMD5 +
            '&FeedType=_POST_PRODUCT_DATA_'+
            '&MWSAuthToken=' + mwstoken +   
            '&MarketplaceId.Id.1=' + MarketplaceId  +
            '&SellerId=' + SellerId +                                         
            '&SignatureMethod=' + SignatureMethod  +
            '&SignatureVersion=' + SignatureVersion  +
            '&Timestamp=' + timestamp  +
            '&Version=' + version;

        String stringtoSign = 'POST' + '\n' +
            'mws.amazonservices.com' + '\n' +
            '/Feeds/2009-01-01' + '\n' +
            queryString;               
        
        //Covert query string to signature using Amazon secret key as key
        Blob mac = Crypto.generateMac('HMacSHA256', 
        blob.valueof(stringtoSign),blob.valueof(amazonSecretKey));

        String signature = EncodingUtil.base64Encode(mac);
        signature = EncodingUtil.urlEncode(signature,'UTF-8');        

       //Create a new request
       HttpRequest request = new HttpRequest();    
        
       request.setEndpoint(endpoint +'?AWSAccessKeyId=' + accessKey +
                		   '&Action=SubmitFeed'+                                                                                 
                           '&FeedType=_POST_PRODUCT_DATA_'+                                                      
                           '&MWSAuthToken=' + mwstoken +
                           '&MarketplaceIdList.Id.1=' + marketplaceId +
                           '&SellerId=' + sellerId +
                           '&ContentMD5Value=' + ContentMD5 +
                           '&SignatureMethod='+ signatureMethod +
                           '&SignatureVersion=2' +
                           '&Timestamp=' + timestamp +
                           '&Version=' + version +                           
                           '&Signature=' + signature);
        
        request.setMethod('POST');
        request.setHeader('Content-type', 'text/xml');        
        request.setBody(xmlBody);        
        
        Http http = new Http();
        try {
            HttpResponse response = http.send(request);
            string status=response.getStatus();           
            System.debug(response.getStatus());
            System.debug(response.getStatusCode());            
            System.debug(response.getBody());            
            return status;
        } 
        catch(System.CalloutException e) {
            System.debug(e);
            return string.valueOf(e);
        }        
	}
}

Please help!!

Thanks in advance!!
 
Hi experts,
 I am unable to see any element in Palette, Resources or explorer.
You can see as below screenshots

User-added imageUser-added imageUser-added image

Any help will be appreciated.