• Brian Shea
  • NEWBIE
  • 50 Points
  • Member since 2016

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

Hi there,
We have created a custom Lightning component that is called by an Action in Lightning. The component performs some pretty basic operations: it just updates a few fields on the record.

For users with the System Administrator profile, the feature works as intended. However, when other users use the feature, it takes about 20 seconds to execute, so the page refreshes for the user before the operation is complete (so the user thinks nothing has happened). Once the user refreshes the page after 20 seconds, they can see that the record has been updated.

We have been testing to try to identify why the feature doesn't work for non-Sys Admins but haven't been able to find anything. We tried giving the Profile modify all access to object + access to all fields, but that does not fix the issue. We have looked at other discrepancies between the Sys Admin and the other profile, but we haven't found anything that resolves it.

One other point: we have created a Javascript button for Classic that calls the underlying Apex Class directly, and this works fine for all users. We need to figure out a solutioln that will also work in Lightning.

 

Does anyone have thoughts on what could be causing this? or any potential fixes or workarounds? 

 

Thank you!

Brian

Hi there,
I have a custom zip code field (text field) in my application and when I recently loaded a large volume of data, I the leading zero on a few hundred of the zip codes were dropped.

I have written a SOQL query that identifies all of the records that I want to fix:

SELECT Name, Physical_Address_Zip_Code__c FROM Location__c WHERE NOT Physical_Address_Zip_Code__c LIKE '_____' ORDER BY Physical_Address_Zip_Code__c
but I want to write an apex script that concatenates a leading zero to the start of all these records. Anyone know how to do this? Thanks!

I've been trying to serialize the results of a SOQL query into JSON. But I've run into a problem because one of the items in the SOQL result set is generated by a function rather than a field. And I'm having trouble mapping the non-field into the JSON.

Here's what I'm doing:

String q = 'SELECT Physical_Address_City__c, Contact_Person__c, DISTANCE(Geolocation__c, GEOLOCATION(:lat, :lng), \'mi\') FROM Location__c;
List<Location__c> locationList = Database.query(q);
List<Location> locationRecords = new List<Location>();
 for(Location__c loc : locationList) {
            locationRecords.add(new Location(loc));
}
String locationJSON = JSON.serialize(locationRecords);

RestContext.response.addHeader('Content-Type', 'application/json');
RestContext.response.responseBody = Blob.valueOf(locationJSON);

Where the Location class is as follows:
Public class Location {
	    
        public String City;
        public Strong ContactPerson;
        public Decimal Distance;

	    Public Location(Location__c loc) {
	        this.City = loc.Physical_Address_City__c;
            this.ContactPerson = loc.Contact_Person__c;
            this.Distance = loc.expr0;
	    }
}
 

But I'm getting the following error:
Error: Compile Error: Invalid field expr0 for SObject Location__c at line 22 column 33

I also tried aliasing the Distance results to DISTANCE in my SELECT statement and reference DISTANCE

this.Distance = loc.DISTANCE;
But that didn't work either. Same error message.


The mapping is expecting a field, but I'm passing it the results of a function. Any recommendations for how to work around this?

Thank you!

I'm building a web service from my salesforce app and I'm running into some challenges formatting the JSON response that the service will generate. Specifically, the JSON contains backslash characters "\" that I want to remove. I've tried a few approaches; none of which have worked. Here are Apex snippets of the approaches I've tried:

Approach 1: return String
List<Location__c> locationList = Database.query(q);
String locationJSON = JSON.serialize(locationList);                 
locationJSON = locationJSON.replaceAll('"Physical_Address_City__c"', '"City"');
//Do more find/replace to update the rest of the keys...
return locationJSON;

With Approach 1 I am able to do a find/replace to format the keys in the JSON. But the JSON contains backslash characters "\" and does not contain a response header.

Results:
(no response header)
"[{\"City\":\"New York\"}]
 

Approach 2: use RestConext method
List<Location__c> locationList = Database.query(q); 
RestContext.response.addHeader('Content-Type', 'application/json'); 
RestContext.response.responseBody = Blob.valueOf(JSON.serialize(locationList));
With Approach 2, I am able to generate a JSON with a header and no backslashes "\" but I don't know how to rename the key values (for instance, Physical_Address_City__c --> City) using this approach. 

Results:
(response header)
"[{"Physical_Address_City__c":"New York"}]



Approach 3: Combination of Approach 1 and 2
List<Location__c> locationList = Database.query(q);        
String locationJSON = JSON.serialize(locationList);                 
locationJSON = locationJSON.replaceAll('"Physical_Address_City__c"', '"City"'); 
​//Do more find/replace to update the rest of the keys...
RestContext.response.addHeader('Content-Type', 'application/json');
RestContext.response.responseBody = Blob.valueOf(JSON.serialize(locationJSON));

With Approach 3 I am able to generate a JSON with the response Header and transform the keys (Physical_Address_City__c --> City) but the JSON body still contains the backslash characters "\". And I'm serializing the JSON twice, which doesn't seem right.

Results:
(response header)
"[{\"City\":\"New York\"}]



Does anyone have thoughts on how to write this more elegantly and also remove the backslash characters? Thank you!

Brian

Hi there,
We have created a custom Lightning component that is called by an Action in Lightning. The component performs some pretty basic operations: it just updates a few fields on the record.

For users with the System Administrator profile, the feature works as intended. However, when other users use the feature, it takes about 20 seconds to execute, so the page refreshes for the user before the operation is complete (so the user thinks nothing has happened). Once the user refreshes the page after 20 seconds, they can see that the record has been updated.

We have been testing to try to identify why the feature doesn't work for non-Sys Admins but haven't been able to find anything. We tried giving the Profile modify all access to object + access to all fields, but that does not fix the issue. We have looked at other discrepancies between the Sys Admin and the other profile, but we haven't found anything that resolves it.

One other point: we have created a Javascript button for Classic that calls the underlying Apex Class directly, and this works fine for all users. We need to figure out a solutioln that will also work in Lightning.

 

Does anyone have thoughts on what could be causing this? or any potential fixes or workarounds? 

 

Thank you!

Brian

Hi there,
I have a custom zip code field (text field) in my application and when I recently loaded a large volume of data, I the leading zero on a few hundred of the zip codes were dropped.

I have written a SOQL query that identifies all of the records that I want to fix:

SELECT Name, Physical_Address_Zip_Code__c FROM Location__c WHERE NOT Physical_Address_Zip_Code__c LIKE '_____' ORDER BY Physical_Address_Zip_Code__c
but I want to write an apex script that concatenates a leading zero to the start of all these records. Anyone know how to do this? Thanks!

I've been trying to serialize the results of a SOQL query into JSON. But I've run into a problem because one of the items in the SOQL result set is generated by a function rather than a field. And I'm having trouble mapping the non-field into the JSON.

Here's what I'm doing:

String q = 'SELECT Physical_Address_City__c, Contact_Person__c, DISTANCE(Geolocation__c, GEOLOCATION(:lat, :lng), \'mi\') FROM Location__c;
List<Location__c> locationList = Database.query(q);
List<Location> locationRecords = new List<Location>();
 for(Location__c loc : locationList) {
            locationRecords.add(new Location(loc));
}
String locationJSON = JSON.serialize(locationRecords);

RestContext.response.addHeader('Content-Type', 'application/json');
RestContext.response.responseBody = Blob.valueOf(locationJSON);

Where the Location class is as follows:
Public class Location {
	    
        public String City;
        public Strong ContactPerson;
        public Decimal Distance;

	    Public Location(Location__c loc) {
	        this.City = loc.Physical_Address_City__c;
            this.ContactPerson = loc.Contact_Person__c;
            this.Distance = loc.expr0;
	    }
}
 

But I'm getting the following error:
Error: Compile Error: Invalid field expr0 for SObject Location__c at line 22 column 33

I also tried aliasing the Distance results to DISTANCE in my SELECT statement and reference DISTANCE

this.Distance = loc.DISTANCE;
But that didn't work either. Same error message.


The mapping is expecting a field, but I'm passing it the results of a function. Any recommendations for how to work around this?

Thank you!

Hi All, I would like to ask for any help as I am really new to this and still learning. I am trying to create a trigger that will roll up the Opportunity Amount on a Custom Object field. Their relationship is lookup only. I keep receiving Error: Compile Error: Invalid field: 'Commission__c' at line 6 column 32

I have a Custom object and set up a lookup from Opportunity to the custom object. What I would like is to get the sum of the Amount of all the opportunities attached to the custom object. 

I need to roll up:
From Object: Opportunity
Field: Amount

Where to roll up: 
Object: Commission__c
Field: Total_Amount__c
 
trigger CommissionRollUp on Commission__c (After Insert){
    Set<Id> setOpportunityIds=new Set<Id>();
        for(Commission__c c:Trigger.new)
            setOpportunityIds.add(c.Amount);
        List<Opportunity> lstOpportunityToUpdate=new List<Opportunity>();
        for(AggregateResult result:[Select Commission__c,count(id) From Commission__c WHERE
Commission__c IN :setOpportunityIds GROUP BY Commission__c LIMIT 2000]){
            Opportunity__r parent=new Opportunity__r();
        Opportunity.Id=result.get('Commission__c');
        Opportunity.Total_Amount__c=(Integer)result.get('expr0');
        lstOpportunityToUpdate.add(Opportunity);
        }
    update lstOpportunityToUpdate;
}

 
I'm building a web service from my salesforce app and I'm running into some challenges formatting the JSON response that the service will generate. Specifically, the JSON contains backslash characters "\" that I want to remove. I've tried a few approaches; none of which have worked. Here are Apex snippets of the approaches I've tried:

Approach 1: return String
List<Location__c> locationList = Database.query(q);
String locationJSON = JSON.serialize(locationList);                 
locationJSON = locationJSON.replaceAll('"Physical_Address_City__c"', '"City"');
//Do more find/replace to update the rest of the keys...
return locationJSON;

With Approach 1 I am able to do a find/replace to format the keys in the JSON. But the JSON contains backslash characters "\" and does not contain a response header.

Results:
(no response header)
"[{\"City\":\"New York\"}]
 

Approach 2: use RestConext method
List<Location__c> locationList = Database.query(q); 
RestContext.response.addHeader('Content-Type', 'application/json'); 
RestContext.response.responseBody = Blob.valueOf(JSON.serialize(locationList));
With Approach 2, I am able to generate a JSON with a header and no backslashes "\" but I don't know how to rename the key values (for instance, Physical_Address_City__c --> City) using this approach. 

Results:
(response header)
"[{"Physical_Address_City__c":"New York"}]



Approach 3: Combination of Approach 1 and 2
List<Location__c> locationList = Database.query(q);        
String locationJSON = JSON.serialize(locationList);                 
locationJSON = locationJSON.replaceAll('"Physical_Address_City__c"', '"City"'); 
​//Do more find/replace to update the rest of the keys...
RestContext.response.addHeader('Content-Type', 'application/json');
RestContext.response.responseBody = Blob.valueOf(JSON.serialize(locationJSON));

With Approach 3 I am able to generate a JSON with the response Header and transform the keys (Physical_Address_City__c --> City) but the JSON body still contains the backslash characters "\". And I'm serializing the JSON twice, which doesn't seem right.

Results:
(response header)
"[{\"City\":\"New York\"}]



Does anyone have thoughts on how to write this more elegantly and also remove the backslash characters? Thank you!

Brian