• ooheman das
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies
Hi 
I have one custom object margin_calculator_... and this object have lookup of Opportunity.when we update Opportunity at a particular stage here [ stagename-'Margin cal...' () ]in this stage if there is at least one record in my custom object margin_calculator_... it should allow to update oppty at this stage or if there is no custom object records for that oppty it should not allow to update oppty at that stage.
i tried too much but not able to do in both condion.my code is working 
but something is missing please help me out.
Thanks in advance.
your help will be appericiated.
jsingh
my code is as follows-
trigger OpportunityTrigger on Opportunity (before update) {
    List<Margin_Calculator_Version__c> marginLst =new List<Margin_Calculator_Version__c>();    
    marginLst = [SELECT Id, Name, Opportunity__r.Id FROM Margin_Calculator_Version__c WHERE Opportunity__r.Id IN :Trigger.new]; 
    
        
        
        for(Opportunity opp:Trigger.new){
            for(Margin_Calculator_Version__c marginversion:marginLst){
                Set<Id> oppId = new Set<Id>();
                
                oppId.add(marginversion.Opportunity__r.Id);
                
               
               
                if((oppId.Contains(opp.Id)) && (opp.StageName=='Margin Calculation'))
                {
                    
                    update opp;
                }else{
                    
                    opp.addError('Please create one record in margin version');
                }
                
                
           
        }
        
    }
    
}
    
    

 
  • March 08, 2020
  • Like
  • 0
Hi there :)

i'm currently working on an native Android app for my company and ran into some problems with Salesforce lately.

I hope i can find some help here.

What i want to achieve:
The company has a lot of Accounts in Salesforce with 3 important fields for the app: Name, Business (Workshop or Parts Dealer) and location(latitude, longitude)
I would like to show those Accounts(Workshops/Parts Dealers) as markers on a google map in my Android app based on a radius around the user's current location. So it would be more than sufficient to get the data as JSON or XML(i read about sObjects, which would be nice too)

The app will be freely available on Google Play Store and every user should be able to see all the Workshops/Parts dealers around the world.

The problem i'm facing is that i can't find a way to fetch the data inside my app without authenticating every user with a Salesforce-Login. 
Which API is the best to use in this case?

It would be so awsome if anybody could help me with this problem.

What i tried so far: 
- SalesforceMobileSDK: If i extend SalesForceApplication i always end up with the Salesforce-Login Screen.
It seems that every client has to be authenticated for API-calls to work. I tried using the method "peekUnauthenticatedRestClient", but this method only works on full path URL's(e.g. "https://api.spotify.com/v1/search?q=James%20Brown&type=artist"), which isn't really practically for my Use-case.

- I feel like i read nearly all docs about salesforce api, but can't quite get my head around how to solve this problem, although it seems like to be a pretty common use-case.  

- would a salesforce-apex method which would select all records inside a set radius around the user's location be accessable without authentication?

Thanks for your help in advance!

Roman

 
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
    req.setMethod('GET');
    http.send(req); //works fine
    bar();
    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?