• GauravGarg
  • PRO
  • 3278 Points
  • Member since 2015
  • Sr Technical Specialist
  • AXA Singapore


  • Chatter
    Feed
  • 101
    Best Answers
  • 0
    Likes Received
  • 5
    Likes Given
  • 10
    Questions
  • 1056
    Replies
Hello,
I was wondering.  What is the best way to get the record from a list based on the currecnt record.
For example I have this list where I am grabbing all the records where the ProjectT Name is 'Closed Templates'
cprojects = [SELECT Id, ProjectT__r.Name, Cand_Project__c,Cand__c 
                FROM Project__c WHERE  ProjectT__r.Name =: 'Closed Templates'];
In a nother method how can I grab the the record/field from the list based on the current record.  What I am trying to go is query all of the records that meet the criteria so that I only have to query it once in the class but need to be able to get a record from list based on the current record being updated.
Thanks,
P
I'm looking for some guidance after days of searching SF, forums, tralblazer, etc. I haven't worked in SF in a very long time.
In my mind what I need to do is simple, but everything I seem to find leads me down a path of complex development. Maybe I'm searching on the wrong terms. 

Here is what I'm trying to do. 
Use case - User needs to click a button(action, etc.) in a record to open to an externally hosted site to perform a task that ties to the SF record they're working in. On click, it would automatically authenticate to the site, pass initial values, and then open the web page in an iframe (preferable), or in a new browser window/tab with the initial values populated. 

Basic logic - (at least in JSON)
1. Authenticate - grant type is client credentials, returns a bearer token
2. Initialise a session - bearer token in header, returns a web sessionid
3. Display that session - bearer token in the header, sessionid appended to the end of a static external URL

The primary issue for me is the structure of this. Writing the code itself isn't really an issue. It's where to put it all and bring it all together.

I had thought this could all be in done in a VF page, but that doesn't seem to be the case. Some people recommend using Canvas, but that seems to be way over the top. 

Any help, guidance is greatly appreciated.

 
Hello,

insert cloneQuoteList; 

I am inserting the list of quote.
How can i get the Opportunity Id and Inserted qute id after the insert.

I want to use the Ids to insert the cloned quote line items

thank you

I have configured my salesforce org with JOT form. My lead assignment rule is also active. But due to some reason it is not working. Can any one suggest me why it is not working and hot to run it.

Thank you  

Hi All, 
When Updating Contact Email Through Import Wizard, i tried using  two approaches 
1. contact name, account name
2. contact email id,contact id
Both work fine,but when there are duplicate contacts under account then only one of them gets updated . Hence i assume option 2 is the right way to go.Can someone confirm?

Not able to use case comment object.Initially we write few lines of code on case comment object and it was working. But, now when we are trying to change the code its is showing invalid variable commentbody error message. Then i  reverted all the changes and just tried to save the method as earlier. But now also im not able to save that class. Same code is not giving errors in UAT but getting error in Dev sandbox. 

   public static void UpdateCaseComment(string Id, string comment ){
        casecomment cc=new casecomment();
        cc.Id=Id;
        cc.commentbody=comment;
        try{
            update cc;
        }catch(Exception e){
            System.debug('er->'+e);
        }
    } 

This is my code 
Please let me know what is causing this issue.

So due to business requirements, I'm using a wrapper to sum daily target data into a single "record" displayed in a lightning:datatable in an aura component.   Those summarized records are editable and when saved were divided by seven for the week.  

Now the start of the "week" is changeable.  In other words some weeks can be seven days long, others can be five depending on the start date.  I'm able to get things working fine, creation of new records, extra except for the division part when updating previous records.  

Essentially using the "Power of One," I'm summing up the number of days in the "weekly record" and displaying it in the consolidated view for users.  I would like to pass that number back to SFDC so the updated values are divided by that summed "Power of One" value.  

Hoping some one can help me figure out how to force the component to return the sum even though it hasn't changed, kind of like the ID value.   If that value is rreturned, I don't have to do a SOQL query to find the number of daily records for the various "weekly" records.

Thanks.
Hi all, 
I have a 'Text Area (Long)'  Field called  All_Products_List__c  wich will be populate by a trigger. To avoid error, i want to limit the number of caracter sto the max vaklue of Text Area (Long). 
The code  save well but when i run  the test class, The error is: "Ending position out of bounds: 131072".  
 
trigger DeliveryNotification on Item_Distributed__c (after update, after insert, after delete, after undelete){

    List <Item_Distributed__c> deliveryItems = (Trigger.isInsert|| Trigger.isUnDelete) ? Trigger.new : Trigger.old;
    
    List <Id> delveryId = new List<Id> ();
    String fullProduct;
    
    for (Item_Distributed__c allDeliveryItems : deliveryItems) {
           delveryId.add(allDeliveryItems.Delivery__c);
   }
   
   List< Delivery__c> deliveryList = [ SELECT id, All_Products_List__c, (SELECT Product_With_UOM__c  from  Items_Distributed__r ) From Delivery__c 
                                    Where id in:delveryId];
                                    
    for (Delivery__c del: deliveryList){
        if (del.Items_Distributed__r.size()>0){
            //camp.Product_With_UOM__c = string.valueOf(del.Items_Distributed [0].Product_With_UOM__c);
            del.All_Products_List__c = '';
            for(Item_Distributed__c member : del.Items_Distributed__r )
               fullProduct = del.All_Products_List__c + member.Product_With_UOM__c + ' ,';
                del.All_Products_List__c = fullProduct.substring(131072);
        }
            else
            del.All_Products_List__c = null;
        }   
                    update deliveryList;

 
Hello,

I have a custom object (Warehouse Visit) that is the child record of Contact. I'd like to click a button on the Warehouse Visit tab where multiple records can be created on one Visualforce page. Basically, I'd like staff to be able to log multiple visits on one page rather than add them one by phone.

On the VF page, I'd like a link that says "add" to allow staff to add multiple rows for each record (3-4 fields). At the end of each row, I want a Remove or X link to remove that row if it was created in error. Then, on save, I'd like it to redirect back to the Warehouse Visit tab. 

I haven't started building the VF page yet, but I'd like to enter about 4 fields, including a lookup to the Contact, a couple of date/time fields, and maybe a checkbox or picklist. 

I have started with this Apex class code, based on a previous button I had help developing, but I'm getting an error. Can anyone help fix this code?

public class WarehouseVisitController {
    public List<Warehouse_Visit__c> wvRecord{get; set;}
    public Integer wvIndex {get; set;}

    public WarehouseVisitController  (){
        wvRecord = new List<Warehouse_Visit__c>();
        wvRecord.add(new Warehouse_Visit__c);
    } #this is where the error is happening
    public void addWarehouseVisit () {
        wvRecord.add(new Warehouse_Visit__c);
    }
    public void removeWarehouseVisit() {
        wvIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('wvIndex'));
        wvRecord.remove(wvIndex);
    }
    public PageReference save() {
        upsert wvRecord;
        PageReference page = new PageReference('/');
        return page;
    }
    public PageReference cancel() {
        PageReference page = new PageReference('/' );
        return page;
    }
}

 
Hi, 

Is it possible to join two unrelated objects (Account with Custom Object) using SOQL? 

Basically I need to update the Account object with a field from the unrelated custom object. Where Account.custom_field == Customobject.custom_Field.

The update can be done in bulk, hence governor limits (SOQL -100) should be respected.

Thanks!


 
I am a long time Salesforce admin/developer but I am still getting started with actually writing Apex code so this is probably a simple error on my part.

I am trying to use batch apex to call the google maps api to avoid limits on @future calls. We have a custom Property__c object and we need to be able load hundreds of records at a time and have them get geocoded.

I can tell from the debug statements that I am successfully passing a set of Ids to the batch apex class. However the database.querlocator does not appear to be getting called. Here is the code:
 
public class batchPropertyGeocode implements Database.Batchable <sObject>, 
Database.AllowsCallouts, Database.Stateful 
{
    Set<Id> propsToGeocode = new Set<Id>();
    //Constructor will take a set of Property Ids
    public batchPropertyGeocode(Set<Id> propsToGeocode) {
        this.propsToGeocode = propsToGeocode;
        System.debug('Creating list of Properties to Geocode: '+this.propsToGeocode);
    }
    
    public Database.QueryLocator start(Database.BatchableContext BC) 
    {
        //Query Properties passed from Trigger
        System.debug('Querying to get Property addresses');
        return Database.getQueryLocator([SELECT Property_City__c,PropertyState__c,
                                         Property_Street_Address__c,PropertyZipCode__c 
                                         FROM Property__c 
                                         WHERE Id IN :propsToGeocode]);
    }
    
    public void execute(Database.BatchableContext BC, List <Property__c> Propertyupdate) 
    {

        List < Property__c > modifiedProps = new list <Property__c> ();
        for (Property__c prop: Propertyupdate) 
        {
            //create a string for the address to pass to Google Geocoding API
            String geoAddress = '';
            if(prop.Property_Street_Address__c!= null)
                geoAddress+= prop.Property_Street_Address__c+ ', ';
            if(prop.Property_City__c != null)
                geoAddress+= prop.Property_City__c+ ', ';
            if(prop.PropertyState__c!= null)
                geoAddress+= prop.PropertyState__c+ ', ';
            if(prop.PropertyZipCode__c!= null)
                geoAddress+= prop.PropertyZipCode__c;
            geoAddress = EncodingUtil.urlEncode(geoAddress, 'UTF-8');
            System.debug('Url Encoded address: '+ geoAddress);
            
            try{
                googleMapsJson gro = callGoogleApex(geoAddress);
                System.Debug(gro.results.size());
                if(gro.results.size() > 0)
                {
                    double lat = gro.results[0].geometry.location.lat;
                    double lon = gro.results[0].geometry.location.lng;
                    
                    if (lat != null) 
                    {
                        system.debug('lat is not null');
                        prop.Geolocation__Latitude__s = lat;
                        prop.Geolocation__Latitude__s = lon;
                        modifiedProps.add(prop);
                        system.debug('Property Location: ' + Prop.Geolocation__Latitude__s );
                    }
                }
                else
                {
                    System.Debug('nothing in list. what am i going to do?');
                }
            } 
            catch (Exception e) {}
            update modifiedProps;
        }
    }
    
    
    
    public static googleMapsJson callGoogleApex(string geoAddress)
    {
        // Key for Google Maps Geocoding API
  		String geocodingKey = 'Actual Google API Key Here';
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        googleMapsJson gro = new googleMapsJson();
        if (geoAddress != null)
        {
            req.setEndpoint('http://maps.googleapis.com/maps/api/geocode/json?address=' + geoAddress +'&key='+ geocodingKey+ '&sensor=false');
            req.setMethod('GET');
            req.setTimeout(6000);
            
            HttpResponse res = h.send(req);
            JSONParser parser = JSON.createParser(res.getBody());
            while(parser.nextToken() != null)
            {
                if(parser.getCurrentToken()==JSONToken.START_OBJECT){
                    gro = (googleMapsJson) parser.readValueAs(googleMapsJson.class);
                }    
            }    
        }
        return gro;
        
    }
    public void finish(Database.BatchableContext BC) { }
}
I would really appreciate some help to get me over the hump.
 
Hi,
Below is my code for the trigger for  duplicate prevention on the account . It works well, but if I have 50k records this impacts scalability and not feasible.
So please any one can help to code in better way.
thanks in advance.
trigger AccountDuplicate on Account (before insert) {
 List<Account> dup = new List<Account>();
 dup = [Select id, Name from Account];
 for(Account a:Trigger.New){
 for(Account a1:dup){
 if(a.Name==a1.Name){
 a.Name.addError('Name already Exist ');
 }
 }
 }   
 }
Hi,
I have a problem with Opportunity related list Quotes.
I can't see the button "New Quote", I  try to modify quote settings in the opportunity layout (like that https://success.salesforce.com/answers?id=90630000000D5QRAA0) but there's no button header, just the column one is visible. How can I do to solve my issue?