• Keith Stephens 18
  • NEWBIE
  • 50 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 30
    Questions
  • 29
    Replies
Hello All,
I hope someone can help me or point me in the right direction to solve this error I am getting.
This error is occuring on this line:
AggregateResult[] AARsAB  = [SELECT Count(id) maxRates, Main_Center__c,CPT_Code__c
			FROM Account_Procedure_Rate__c where Main_Center__c IN: centerMap.keySet()  group by CPT_Code__c, Main_Center__c];

I think it is due to it's bringing back to many rows.
Would this line of code resolve such issue?
List<SObject> AARs= [SELECT Count(id) maxRates, Main_Center__c,CPT_Code__c
		FROM Account_Procedure_Rate__c  group by CPT_Code__c, Main_Center__c];

Sticking it into a list of sobject?  If so what is the difference between the two?
This only occures in our production environment since we do not keep our dev and qa upto date with this many records ect..
Thanks,
Keith.
Hello All,
I hope someone can help me or point me in the correct direction to solve this error I am getting.
This error is occuring with this line of code I have:
AggregateResult[] AARsA  = [SELECT Count(id) maxRates, Main_Center__c,CPT_Code__c
			FROM Account_Procedure_Rate__c  group by CPT_Code__c, Main_Center__c];

I think it is due to it's seems to be bringing back thousands of recs, over 5000.
If I were to do this:
List<SObject> AARs= [SELECT Count(id) maxRates, Main_Center__c,CPT_Code__c
		FROM Account_Procedure_Rate__c  group by CPT_Code__c, Main_Center__c];


Would it fix my issue?
I cannot reporduce this in DEV or QA because we do not have that many records in those environments, we just do not keep our environments up to date.
Thanks,
KS
Hello All,
Can someone tell me if my trigger is bulkified?
I have removed all of the SOQL statments out of the loop, but I don't know if that is all I have to do to bulkify my code.
trigger MostRecentCenter on Procedure__c (after insert, after update) {
   try{           
          if (TriggerSettings.areTriggersDisabled()) return;  
           Set<Id> procIds = new Set<Id>();
           Set<Id> caseIds = new Set<Id>();
		   List<Case> lstCase = new List<Case>();
               
               for(Procedure__c proc : Trigger.New)
               {                 
                   if(proc.CreatedDate != null) 
                   { 
                       procIds.add(proc.LastModifiedById);  
                       caseIds.add(proc.Case__c);                      
                   }                        
               }                        
               
              Map<string, Procedure__c> procMap = new map<string, Procedure__c> ( [SELECT CenterID__c, Center__c from Procedure__c 
               where LastModifiedById IN: procIds Order by CreatedDate Desc] );     

              Map<string, Case> caseMap = new map<string, Case> ( [SELECT Id, Most_Recent_Center__c FROM Case WHERE Id IN: caseIds] );  
                         
                 for(Procedure__c pd: trigger.new) 
                 {       
                     //system.debug(pd.id);

                    if(procMap.containsKey(pd.id)) 
                    {           
                      
                        //Id centerID = (Id)procMap.get(pd.id).Center__c;
                        //Case cs = (Case)[SELECT Id, Most_Recent_Center__c FROM Case WHERE Id = :pd.Case__c];
                        //cs.Most_Recent_Center__c = centerID;
						
                        //system.debug('pd.id = ' + pd.id);
                        //system.debug('caseMap = ' + caseMap);
                        //system.debug('pd.case = ' + pd.Case__c);
                        //system.debug('procmap.get = ' + procMap.get(pd.id).Center__c);

                        caseMap.get(pd.Case__c).Most_Recent_Center__c =(Id)procMap.get(pd.id).Center__c;                     
                        lstCase.add(caseMap.get(pd.Case__c));                      
                                                               
                    }       
                }
                   // system.debug('lstCase Size = ' + lstCase.size());
				if(lstCase.size()>0)
                    //system.debug('in size if');
					update lstCase;                
          
        
    }catch(Exception e){
       //Package suspended, uninstalled or expired, exit gracefully.
       System.debug('Error MostRecentCenter');
       system.debug(e.getMessage());
       
    }
    
}


Thanks,
KS
Hello,
I have the follwoing code being executed in a for loop and I want to remove it from the loop and bulkify it how would I do this?
A list, or a map? I preferer to use a map if possible.
 
Account_Procedure_Rate__c rate = [SELECT Amount_To_Pay__c, Procedure_Cost__c FROM Account_Procedure_Rate__c 
														 	 WHERE  CPT_Code__c = :proc.CPT_Code__c AND Main_Center__c = :centerId];
							proc.Amount_To_Pay__c = rate.Amount_To_Pay__c;
							proc.Procedure_Cost__c = rate.Procedure_Cost__c;



Thanks,
K
Hello All,
I have the follwoing code and I want to return the count of records.
trigger Pupdate on Procedure__c (before update, before insert) {

Map<Id,AggregateResult> cprCnt = new Map<id,AggregateResult>([SELECT Count(id) maxRates
 		FROM Center_Procedure_Rate__c group by CPT_Code__c, Center__c]);
		
		if (Trigger.isInsert || (Trigger.isUpdate && proc.Amount_To_Pay__c == NULL && proc.Procedure_Cost__c == NULL) || 
					(Trigger.isUpdate && (proc.Procedure_Status__c != 'OK to Pay' && proc.Procedure_Status__c != 'Paid' &&
					   (proc.Amount_To_Pay__c != NULL && proc.Procedure_Cost__c != NULL)))) {
					// get count of Center Procedure Rates that match current procedure
					//centerRateCount = 
					//	[SELECT COUNT(Id) maxRates FROM Center_Procedure_Rate__c 
					//	 WHERE CPT_Code__c = :proc.CPT_Code__c AND Center__c = :proc.Center__c];
						 
					//maxCtrRates = centerRateCount[0].get('maxRates') == null ? 0 : (Integer)centerRateCount[0].get('maxRates');
					
					maxCtrRates = cprCnt.get(proc.Center__c, proc.CPT_Code__c);
					system.debug(maxCtrRates);
		}
}
In the code you can see I am doing it through Soql, but I need to have this bulkified.
we are not hiting our soql limtis.
Thansk,
K
 
Hello All,
I am new to Salesforce development, so I hope someone can help me.
I need to get this trigger bulkified, but I do not know how, this trigger was written by someone else who no longer works for the company.
trigger ProcedureRateUpdates on Procedure__c (before update, before insert) {
	// if triggers have been globally disabled via TriggerCustomSettings setting, then exit
	if (TriggerSettings.areTriggersDisabled()) return;
	
	List<AggregateResult> centerRateCount = null;
	List<AggregateResult> acctRateCount = null;
	Integer maxCtrRates = 0;
	Integer maxAcctRates = 0;
	Id centerId = null;
	Boolean isManualProcPricing = false;
	
	
	// Set<Id> procIds = trigger.newMap.keySet();
	// List<Procedure_c> procs = [SELECT Id,  FROM Procedure__c 
	//						   WHERE Id IN :procIds];
					   
	for (Procedure__c proc: trigger.new) {
		if (proc.Override_Procedure_Rate__c == false) {
			// get the Main Center ID for the current procedure
			try {
				centerId = [SELECT Main_Center__c FROM Center__c WHERE Id = :proc.Center__c][0].Main_Center__c;
			} catch (Exception e) {
				proc.addError('Unable to determine Main Center. Ensure that this procedure has a Center selected.');
				continue;
			}
			// determine if Manual Procedure Pricing checkbox is checked
			isManualProcPricing = [SELECT Manual_Procedure_Pricing__c FROM Main_Center__c WHERE Id = :centerId][0].Manual_Procedure_Pricing__c;
			if (isManualProcPricing == false) {
				// only process the costs if entering a new procedure or updating an existing one that has a blank amount and cost
				// or updating an existing one only if the Procedure Status is not 'OK to Pay' or 'Paid')
				if (Trigger.isInsert || (Trigger.isUpdate && proc.Amount_To_Pay__c == NULL && proc.Procedure_Cost__c == NULL) || 
					(Trigger.isUpdate && (proc.Procedure_Status__c != 'OK to Pay' && proc.Procedure_Status__c != 'Paid' &&
					   (proc.Amount_To_Pay__c != NULL && proc.Procedure_Cost__c != NULL)))) {
					// get count of Center Procedure Rates that match current procedure
					centerRateCount = 
						[SELECT COUNT(Id) maxRates FROM Center_Procedure_Rate__c 
						 WHERE CPT_Code__c = :proc.CPT_Code__c AND Center__c = :proc.Center__c];
						 
					maxCtrRates = centerRateCount[0].get('maxRates') == null ? 0 : (Integer)centerRateCount[0].get('maxRates');
						
					if (maxCtrRates == 0) {
						System.debug('proc.Center__c = ' + proc.Center__c);
						// no rates found in Center Procedure Rate object, so look at Account Procedure Rate object for rate
						acctRateCount = [SELECT COUNT(Id) maxRates FROM Account_Procedure_Rate__c 
							 			 WHERE CPT_Code__c = :proc.CPT_Code__c AND Main_Center__c = :centerId];
						maxAcctRates = acctRateCount[0].get('maxRates') == null ? 0 : (Integer)acctRateCount[0].get('maxRates');
						
						if (maxAcctRates == 0) { 
							proc.addError('No rates found for this procedure.');
						} else if (maxAcctRates == 1) {
							Account_Procedure_Rate__c rate = [SELECT Amount_To_Pay__c, Procedure_Cost__c FROM Account_Procedure_Rate__c 
														 	 WHERE  CPT_Code__c = :proc.CPT_Code__c AND Main_Center__c = :centerId];
							proc.Amount_To_Pay__c = rate.Amount_To_Pay__c;
							proc.Procedure_Cost__c = rate.Procedure_Cost__c;
						} else {
							proc.addError('More than one procedure rate for the main center was found.');
						}
					} else if (maxCtrRates == 1) {
						Center_Procedure_Rate__c rate = [SELECT Amount_To_Pay__c, Procedure_Cost__c FROM Center_Procedure_Rate__c 
														 WHERE  CPT_Code__c = :proc.CPT_Code__c AND Center__c = :proc.Center__c];
						proc.Amount_To_Pay__c = rate.Amount_To_Pay__c;
						proc.Procedure_Cost__c = rate.Procedure_Cost__c;
					} else {
						proc.addError('More than one procedure rate for the center was found.');
					}
				}
			}
		}
	} 
}



Thanks,
Keith.
How do I set this up?
Will this debugger work without a salesforce debugger license?
Do you need to set up a scratch org?

Thanks,
Keith.
Hello All,
I am having issues with I think escaping values into my soql statment. Here is what I have
String userEmail = UserInfo.getUserEmail(); 
system.debug(userEmail);


String url = 'https://test.salesforce.com/services/data/v40.0/query?q=SELECT+Attny_Phone_From_Contact__c,Attorney_Email_from_Contact__c,Attorney_Email__c,Attorney_Fax__c,Attorney_First_Name__c,Attorney_Full_Name__c,\''userEmail'\', Attorney_Last_Name__c,Id,Plaintiff_First_Name__c,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c+FROM+Case+limit+3';
system.debug(url);

Yes, I want to return the UserEmail this way, but I am getting an "Unexpected token 'url' error.
Thanks for the help or guidance.
Keith.
I am calling Salesforce query api call, and I am wanting to pass in a case id, but it is not working.
I have tried to add single quotes around the ID but that did ot work either.
If I remove the where clause it works just fine.
Any help would be appritiated.
Thanks,
Keith.
 
String url = 'https://test.salesforce.com/services/data/v40.0/query?q=SELECT+Plaintiff_First_Name__c,Plaintiff_Last_Name__c,Attorney_Fax__c,Attorney_First_Name__c,Attorney_Last_Name__c+FROM+Case+WHERE+Id=500g000000G1DB4';
system.debug(url);
Http h = new Http();
HttpRequest req = new HttpRequest();
system.debug('got request');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setEndpoint(url);
system.debug('setendpoint');
req.setMethod('GET');
HttpResponse res = h.send(req);


 
Hello all,
I am making a rest api call from the developer console that just calls SF AIP /query?q passing in a simple SOQL statment.
salesforce.com/services/data/v40.0/query?q=SELECT+Attny_Phone_From_Contact__c,Attorney_Email_from_Contact__c,Attorney_Email__c,Attorney_Fax__c,Attorney_First_Name__c,Attorney_Full_Name__c,Attorney_Last_Name__c,Id,Plaintiff_First_Name__c,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c+FROM+Case+limit+3';

This works fine, but now I want to add the logged in users email address, everything I have tried is not working.
example String userEmail = UserInfo.getUserEmail();
And adding userEmail in my soql string ect..

How can I get the email to be passed in the query.
Thanks,
Keith.
I am needing to include a string of text in my soql query. Is this possible?
In sql server the following query works and returns the text, but how do I do this using SOQL?

SELECT [LastModifeidDate]
      ,[Plaintiff_Full_Name__c]
      ,[Pliantif_Last_Name__c],
   'hello world'
  FROM [ERP].[dbo].[Cases]
Thanks,
KS
Hello All,
How do I write a simple Salesforce class that will execute this soql "SELECT LastModifiedDate,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c FROM Case limit 3"
And return a Json string so I can pass that to my C# rest service.
And for testing sake call the class from the Developer Console.

Thanks for any help, I am learning SF as I go.
Keith.
Hello All,
I am calling Salesforce API to retun me the version /services/data/
But the returned JSON I get has backslashes infront of the double quotes.
How do I remove the backshash \?  Also in my c# rest service I am using NewtonSoft_Json.Linq.
Here is my c# code to call Salesforce API.
I have a Return just before parsing so I can get the JSON being returned.
But when it does hit the parser it errors out.
 
HttpClient apiCallClient = new HttpClient();
               
                String restCallURL = ServiceURL + "/services/data/";

                HttpRequestMessage apirequest = new HttpRequestMessage(HttpMethod.Get, restCallURL);
                apirequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                apirequest.Headers.Add("authorization", "Bearer " + authToken);
                HttpResponseMessage apiCallResponse = await apiCallClient.SendAsync(apirequest);


                string requestresponse = await apiCallResponse.Content.ReadAsStringAsync();
                
                // Regex.Unescape(requestresponse);
                //requestresponse = requestresponse.Replace('\"', '"');
                //string x = requestresponse.Replace("\n", "").Replace("\r", "");

                // return x.ToString();
                 return requestresponse.ToString();
//This is where my code breaks on the parsing of the string because of \
 JToken sObjJObj = JObject.Parse(requestresponse);
                return "obj " + sObjJObj.ToString();

JSON String.
"[{\"label\":\"Winter '11\",\"url\":\"/services/data/v20.0\",\"version\":\"20.0\"},{\"label\":\"Spring '11\",\"url\":\"/services/data/v21.0\",\"version\":\"21.0\"},{\"label\":\"Summer '11\",\"url\":\"/services/data/v22.0\",\"version\":\"22.0\"},{\"label\":\"Winter '12\",\"url\":\"/services/data/v23.0\",\"version\":\"23.0\"},{\"label\":\"Spring '12\",\"url\":\"/services/data/v24.0\",\"version\":\"24.0\"},{\"label\":\"Summer '12\",\"url\":\"/services/data/v25.0\",\"version\":\"25.0\"},{\"label\":\"Winter '13\",\"url\":\"/services/data/v26.0\",\"version\":\"26.0\"},{\"label\":\"Spring '13\",\"url\":\"/services/data/v27.0\",\"version\":\"27.0\"},{\"label\":\"Summer '13\",\"url\":\"/services/data/v28.0\",\"version\":\"28.0\"},{\"label\":\"Winter '14\",\"url\":\"/services/data/v29.0\",\"version\":\"29.0\"},{\"label\":\"Spring '14\",\"url\":\"/services/data/v30.0\",\"version\":\"30.0\"},{\"label\":\"Summer '14\",\"url\":\"/services/data/v31.0\",\"version\":\"31.0\"},{\"label\":\"Winter '15\",\"url\":\"/services/data/v32.0\",\"version\":\"32.0\"},{\"label\":\"Spring '15\",\"url\":\"/services/data/v33.0\",\"version\":\"33.0\"},{\"label\":\"Summer '15\",\"url\":\"/services/data/v34.0\",\"version\":\"34.0\"},{\"label\":\"Winter '16\",\"url\":\"/services/data/v35.0\",\"version\":\"35.0\"},{\"label\":\"Spring '16\",\"url\":\"/services/data/v36.0\",\"version\":\"36.0\"},{\"label\":\"Summer '16\",\"url\":\"/services/data/v37.0\",\"version\":\"37.0\"},{\"label\":\"Winter '17\",\"url\":\"/services/data/v38.0\",\"version\":\"38.0\"},{\"label\":\"Spring '17\",\"url\":\"/services/data/v39.0\",\"version\":\"39.0\"},{\"label\":\"Summer '17\",\"url\":\"/services/data/v40.0\",\"version\":\"40.0\"},{\"label\":\"Winter '18\",\"url\":\"/services/data/v41.0\",\"version\":\"41.0\"}]"
Hello All,
I am making a call from my c# rest service to try and get Salesforce latest version number, but SF is not retuning a parsable Json stirng.
HttpClient apiCallClient = new HttpClient();
            //String restCallURL = ServiceURL + "/services/data/v40.0/sobjects";                
            String restCallURL = ServiceURL + "/services/data/";
            
            HttpRequestMessage apirequest = new HttpRequestMessage(HttpMethod.Get, restCallURL);
            apirequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            apirequest.Headers.Add("authorization", "Bearer " + authToken);
            HttpResponseMessage apiCallResponse = await apiCallClient.SendAsync(apirequest);

            String requestresponse = await apiCallResponse.Content.ReadAsStringAsync();

           // String jsonResult = requestresponse.TrimStart(new char[] { '[' }).TrimEnd(new char[] { ']' });

            List<String> sObjLst = new List<String>();
            return requestresponse.ToString();
            
            if (apiCallResponse.IsSuccessStatusCode)
            {

                JObject sObjJObj = JObject.Parse(requestresponse);
                return sObjJObj.ToString();

            }
In the above code requestresponse equals, below but newtonsoft_Json is not able to parse it, and if I try and parse it with online parsers they also return errors.

[{\"label\":\"Winter '11\",\"url\":\"/services/data/v20.0\",\"version\":\"20.0\"},{\"label\":\"Spring '11\",\"url\":\"/services/data/v21.0\",\"version\":\"21.0\"},{\"label\":\"Summer '11\",\"url\":\"/services/data/v22.0\",\"version\":\"22.0\"},{\"label\":\"Winter '12\",\"url\":\"/services/data/v23.0\",\"version\":\"23.0\"},{\"label\":\"Spring '12\",\"url\":\"/services/data/v24.0\",\"version\":\"24.0\"},{\"label\":\"Summer '12\",\"url\":\"/services/data/v25.0\",\"version\":\"25.0\"},{\"label\":\"Winter '13\",\"url\":\"/services/data/v26.0\",\"version\":\"26.0\"},{\"label\":\"Spring '13\",\"url\":\"/services/data/v27.0\",\"version\":\"27.0\"},{\"label\":\"Summer '13\",\"url\":\"/services/data/v28.0\",\"version\":\"28.0\"},{\"label\":\"Winter '14\",\"url\":\"/services/data/v29.0\",\"version\":\"29.0\"},{\"label\":\"Spring '14\",\"url\":\"/services/data/v30.0\",\"version\":\"30.0\"},{\"label\":\"Summer '14\",\"url\":\"/services/data/v31.0\",\"version\":\"31.0\"},{\"label\":\"Winter '15\",\"url\":\"/services/data/v32.0\",\"version\":\"32.0\"},{\"label\":\"Spring '15\",\"url\":\"/services/data/v33.0\",\"version\":\"33.0\"},{\"label\":\"Summer '15\",\"url\":\"/services/data/v34.0\",\"version\":\"34.0\"},{\"label\":\"Winter '16\",\"url\":\"/services/data/v35.0\",\"version\":\"35.0\"},{\"label\":\"Spring '16\",\"url\":\"/services/data/v36.0\",\"version\":\"36.0\"},{\"label\":\"Summer '16\",\"url\":\"/services/data/v37.0\",\"version\":\"37.0\"},{\"label\":\"Winter '17\",\"url\":\"/services/data/v38.0\",\"version\":\"38.0\"},{\"label\":\"Spring '17\",\"url\":\"/services/data/v39.0\",\"version\":\"39.0\"},{\"label\":\"Summer '17\",\"url\":\"/services/data/v40.0\",\"version\":\"40.0\"},{\"label\":\"Winter '18\",\"url\":\"/services/data/v41.0\",\"version\":\"41.0\"}]

Thanks for any help or advice.
Keith.
Hello All,
I have the follwoing Rest call in Salesforce development console and it seems to be working, but how to I read the request in my C# method the URI is pointing too.
String Soql = 'SELECT LastModifiedDate,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c FROM Case limit 3';
List<sObject> L = Database.query(Soql);
Bolden,Plaintiff_Last_Name__c=Bolden,Id=500g000000G3NmpAAF})';

String jsonResponse = Json.serialize(L);

String url = 'http://localhost:1025/ErpApiService/api/PriceForCustomerB/';

Http h = new Http();
HttpRequest req = new HttpRequest();
system.debug('got request');
req.setHeader('Content-Type', 'application/json');

req.setEndpoint(url);
system.debug('setendpoint');
//req.setMethod('GET');
req.setMethod('POST');
req.setBody(jsonResponse);
HttpResponse res = h.send(req);
Thanks for any help or advice,
Keith.
 
Needing help to get Case information to my C# rest service.
Below is my code, but I am getting "Bad Request" error.
I am not sure what I need to do to get my query results to my service for reading.
Thanks,
KS
String Soql = 'SELECT LastModifiedDate,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c FROM Case limit 3';
List<sObject> L = Database.query(Soql);
String url = 'http://server/ErpApiService/api/PriceForCustomerB/' + L;

System.Debug(url);

Http h = new Http();
HttpRequest req = new HttpRequest();
system.debug('got request');
req.setHeader('Content-Type', 'application/json');

req.setEndpoint(url);
system.debug('setendpoint');
req.setMethod('GET');
HttpResponse res = h.send(req);

 system.debug('res' + res);
system.debug('Price: ' + res.getBody());

 
Hello All
I am new to Salesforce and Restful services.
But I currently have a c# rest service running and I am able to call it from SF, but currently I am just passing in a hard coded string value.
Here is my code that I can run from the Development Console
 
String url = 'http://server/ErpApiService/api/PriceForCustomerA/10/15';

Http h = new Http();
HttpRequest req = new HttpRequest();
system.debug('got request');
req.setEndpoint(url);
system.debug('setendpoint');
req.setMethod('GET');
HttpResponse res = h.send(req);
 system.debug('res' + res);
system.debug('Price: ' + res.getBody());

And this works and calls my rest service passing in a string value, but now I want to pass back some actual data from salesforce example
'SELECT LastModifiedDate,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c FROM Case limit 3';
I know I will have to change my parameter in my rest service to accept whatever SF will be passing to me.

But here I am not sure what or how to do this? Do I need to create a dictionary object, and pass that?
What do I need to do in SF to pass query results and then read them in my rest service.
Thanks for any help or advice,
Keith.
 
Hello All,
I am new to SF and Rest services, but I have created a C# restful service which I can call from SF developers console, but as of now I am passing in to the service and retruning a hard coded string. (Proof of concept that I can call my service).
Now I want to pass into my service actual data from a SOQL query. Something simple like "Select firstname, lastname from cases limit 3;"

I am not sure how to do this? Do I need to pass it in as string or some other JSON object?
One in my  Rest Service how do I pars it out, to insert into a SQL Server DB or Azure DB?

Just taking small steps for now, end result will be passing data from SF Class or button to the Rest service and DB in Azure.

Thanks,
Keith.
Hello,
We currenly use Conga to merge information into templates, then save and email these document to attorney's. We want to find a way to do this without Conga or a 3rd party plug in. So from Apex itself.  Has anyone done this? Is this possible? 
I am new to Salesforce and Apex ect.. I have only written a few triggers, but I am a Sr. Veteran with .NET C#.

Any advice or help would be great.
Thanks,
Keith.
Hello All,
One I am new to SF and Apex and their triggers, but I wrote this trigger and at one time it worked in Dev. Now it is not updating the list, with all my system.debug statements it gets all the way down to the update lstCase; statment but then errors out.
Can someone help me out on what might be happening now.
Thanks,
Keith.
 
trigger MostRecentCenter on Procedure__c (after insert, after update) {
   try{           
            
           Set<Id> procIds = new Set<Id>();
           Set<Id> caseIds = new Set<Id>();
		   List<Case> lstCase = new List<Case>();
               
               for(Procedure__c proc : Trigger.New)
               {                 
                   if(proc.CreatedDate != null) 
                   { 
                       procIds.add(proc.LastModifiedById);  
                       caseIds.add(proc.Case__c);                      
                   }                        
               }                        
               
              Map<string, Procedure__c> procMap = new map<string, Procedure__c> ( [SELECT CenterID__c, Center__c from Procedure__c 
               where LastModifiedById IN: procIds Order by CreatedDate Desc] );     

              Map<string, Case> caseMap = new map<string, Case> ( [SELECT Id, Most_Recent_Center__c FROM Case WHERE Id IN: caseIds] );  
                         
                 for(Procedure__c pd: trigger.new) 
                 {       
                     //system.debug(pd.id);

                    if(procMap.containsKey(pd.id)) 
                    {           
                      
                        //Id centerID = (Id)procMap.get(pd.id).Center__c;
                        //Case cs = (Case)[SELECT Id, Most_Recent_Center__c FROM Case WHERE Id = :pd.Case__c];
                        //cs.Most_Recent_Center__c = centerID;
						
                        system.debug('pd.id = ' + pd.id);
                        system.debug('caseMap = ' + caseMap);
                        system.debug('pd.case = ' + pd.Case__c);
                        system.debug('procmap.get = ' + procMap.get(pd.id).Center__c);

                        caseMap.get(pd.Case__c).Most_Recent_Center__c = procMap.get(pd.id).Center__c;                     
                        lstCase.add(caseMap.get(pd.Case__c));                      
                                                               
                    }       
                }
                    system.debug('lstCase Size = ' + lstCase.size());
				if(lstCase.size()>0)
                    system.debug('in size if');
					update lstCase;                
          
        
    }catch(Exception e){
       //Package suspended, uninstalled or expired, exit gracefully.
       System.debug('Error MostRecentCenter');
    }
    
}

 
Hello All,
I need to be able to update an Azure database from Salesforce.  Mainly for Cases and Lawyers, when cases or lawyers get updated I need to update the Azure DB as well.
I have seen the examples that talk about Azure to Salesforce, but I have not seen anything talking about Salesforce to Azure.
I have looked at both the Salesforce WCF and RestAPI https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/
But again these go from Azure to Salesforce.

Is it possible to go the other way?  What would be the best approch to this as I have seen many differnt approches to connecting.
We don't want any syncing of data, just to make a .NET call when Salesforce records get updates ect.. to update our Azure DB.
Thanks,
K.
Hello All,
I hope someone can help me or point me in the right direction to solve this error I am getting.
This error is occuring on this line:
AggregateResult[] AARsAB  = [SELECT Count(id) maxRates, Main_Center__c,CPT_Code__c
			FROM Account_Procedure_Rate__c where Main_Center__c IN: centerMap.keySet()  group by CPT_Code__c, Main_Center__c];

I think it is due to it's bringing back to many rows.
Would this line of code resolve such issue?
List<SObject> AARs= [SELECT Count(id) maxRates, Main_Center__c,CPT_Code__c
		FROM Account_Procedure_Rate__c  group by CPT_Code__c, Main_Center__c];

Sticking it into a list of sobject?  If so what is the difference between the two?
This only occures in our production environment since we do not keep our dev and qa upto date with this many records ect..
Thanks,
Keith.
Hello All,
I have the follwoing code and I want to return the count of records.
trigger Pupdate on Procedure__c (before update, before insert) {

Map<Id,AggregateResult> cprCnt = new Map<id,AggregateResult>([SELECT Count(id) maxRates
 		FROM Center_Procedure_Rate__c group by CPT_Code__c, Center__c]);
		
		if (Trigger.isInsert || (Trigger.isUpdate && proc.Amount_To_Pay__c == NULL && proc.Procedure_Cost__c == NULL) || 
					(Trigger.isUpdate && (proc.Procedure_Status__c != 'OK to Pay' && proc.Procedure_Status__c != 'Paid' &&
					   (proc.Amount_To_Pay__c != NULL && proc.Procedure_Cost__c != NULL)))) {
					// get count of Center Procedure Rates that match current procedure
					//centerRateCount = 
					//	[SELECT COUNT(Id) maxRates FROM Center_Procedure_Rate__c 
					//	 WHERE CPT_Code__c = :proc.CPT_Code__c AND Center__c = :proc.Center__c];
						 
					//maxCtrRates = centerRateCount[0].get('maxRates') == null ? 0 : (Integer)centerRateCount[0].get('maxRates');
					
					maxCtrRates = cprCnt.get(proc.Center__c, proc.CPT_Code__c);
					system.debug(maxCtrRates);
		}
}
In the code you can see I am doing it through Soql, but I need to have this bulkified.
we are not hiting our soql limtis.
Thansk,
K
 
Hello All,
I am new to Salesforce development, so I hope someone can help me.
I need to get this trigger bulkified, but I do not know how, this trigger was written by someone else who no longer works for the company.
trigger ProcedureRateUpdates on Procedure__c (before update, before insert) {
	// if triggers have been globally disabled via TriggerCustomSettings setting, then exit
	if (TriggerSettings.areTriggersDisabled()) return;
	
	List<AggregateResult> centerRateCount = null;
	List<AggregateResult> acctRateCount = null;
	Integer maxCtrRates = 0;
	Integer maxAcctRates = 0;
	Id centerId = null;
	Boolean isManualProcPricing = false;
	
	
	// Set<Id> procIds = trigger.newMap.keySet();
	// List<Procedure_c> procs = [SELECT Id,  FROM Procedure__c 
	//						   WHERE Id IN :procIds];
					   
	for (Procedure__c proc: trigger.new) {
		if (proc.Override_Procedure_Rate__c == false) {
			// get the Main Center ID for the current procedure
			try {
				centerId = [SELECT Main_Center__c FROM Center__c WHERE Id = :proc.Center__c][0].Main_Center__c;
			} catch (Exception e) {
				proc.addError('Unable to determine Main Center. Ensure that this procedure has a Center selected.');
				continue;
			}
			// determine if Manual Procedure Pricing checkbox is checked
			isManualProcPricing = [SELECT Manual_Procedure_Pricing__c FROM Main_Center__c WHERE Id = :centerId][0].Manual_Procedure_Pricing__c;
			if (isManualProcPricing == false) {
				// only process the costs if entering a new procedure or updating an existing one that has a blank amount and cost
				// or updating an existing one only if the Procedure Status is not 'OK to Pay' or 'Paid')
				if (Trigger.isInsert || (Trigger.isUpdate && proc.Amount_To_Pay__c == NULL && proc.Procedure_Cost__c == NULL) || 
					(Trigger.isUpdate && (proc.Procedure_Status__c != 'OK to Pay' && proc.Procedure_Status__c != 'Paid' &&
					   (proc.Amount_To_Pay__c != NULL && proc.Procedure_Cost__c != NULL)))) {
					// get count of Center Procedure Rates that match current procedure
					centerRateCount = 
						[SELECT COUNT(Id) maxRates FROM Center_Procedure_Rate__c 
						 WHERE CPT_Code__c = :proc.CPT_Code__c AND Center__c = :proc.Center__c];
						 
					maxCtrRates = centerRateCount[0].get('maxRates') == null ? 0 : (Integer)centerRateCount[0].get('maxRates');
						
					if (maxCtrRates == 0) {
						System.debug('proc.Center__c = ' + proc.Center__c);
						// no rates found in Center Procedure Rate object, so look at Account Procedure Rate object for rate
						acctRateCount = [SELECT COUNT(Id) maxRates FROM Account_Procedure_Rate__c 
							 			 WHERE CPT_Code__c = :proc.CPT_Code__c AND Main_Center__c = :centerId];
						maxAcctRates = acctRateCount[0].get('maxRates') == null ? 0 : (Integer)acctRateCount[0].get('maxRates');
						
						if (maxAcctRates == 0) { 
							proc.addError('No rates found for this procedure.');
						} else if (maxAcctRates == 1) {
							Account_Procedure_Rate__c rate = [SELECT Amount_To_Pay__c, Procedure_Cost__c FROM Account_Procedure_Rate__c 
														 	 WHERE  CPT_Code__c = :proc.CPT_Code__c AND Main_Center__c = :centerId];
							proc.Amount_To_Pay__c = rate.Amount_To_Pay__c;
							proc.Procedure_Cost__c = rate.Procedure_Cost__c;
						} else {
							proc.addError('More than one procedure rate for the main center was found.');
						}
					} else if (maxCtrRates == 1) {
						Center_Procedure_Rate__c rate = [SELECT Amount_To_Pay__c, Procedure_Cost__c FROM Center_Procedure_Rate__c 
														 WHERE  CPT_Code__c = :proc.CPT_Code__c AND Center__c = :proc.Center__c];
						proc.Amount_To_Pay__c = rate.Amount_To_Pay__c;
						proc.Procedure_Cost__c = rate.Procedure_Cost__c;
					} else {
						proc.addError('More than one procedure rate for the center was found.');
					}
				}
			}
		}
	} 
}



Thanks,
Keith.
How do I set this up?
Will this debugger work without a salesforce debugger license?
Do you need to set up a scratch org?

Thanks,
Keith.
Hello All,
I am having issues with I think escaping values into my soql statment. Here is what I have
String userEmail = UserInfo.getUserEmail(); 
system.debug(userEmail);


String url = 'https://test.salesforce.com/services/data/v40.0/query?q=SELECT+Attny_Phone_From_Contact__c,Attorney_Email_from_Contact__c,Attorney_Email__c,Attorney_Fax__c,Attorney_First_Name__c,Attorney_Full_Name__c,\''userEmail'\', Attorney_Last_Name__c,Id,Plaintiff_First_Name__c,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c+FROM+Case+limit+3';
system.debug(url);

Yes, I want to return the UserEmail this way, but I am getting an "Unexpected token 'url' error.
Thanks for the help or guidance.
Keith.
I am calling Salesforce query api call, and I am wanting to pass in a case id, but it is not working.
I have tried to add single quotes around the ID but that did ot work either.
If I remove the where clause it works just fine.
Any help would be appritiated.
Thanks,
Keith.
 
String url = 'https://test.salesforce.com/services/data/v40.0/query?q=SELECT+Plaintiff_First_Name__c,Plaintiff_Last_Name__c,Attorney_Fax__c,Attorney_First_Name__c,Attorney_Last_Name__c+FROM+Case+WHERE+Id=500g000000G1DB4';
system.debug(url);
Http h = new Http();
HttpRequest req = new HttpRequest();
system.debug('got request');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setEndpoint(url);
system.debug('setendpoint');
req.setMethod('GET');
HttpResponse res = h.send(req);


 
Hello all,
I am making a rest api call from the developer console that just calls SF AIP /query?q passing in a simple SOQL statment.
salesforce.com/services/data/v40.0/query?q=SELECT+Attny_Phone_From_Contact__c,Attorney_Email_from_Contact__c,Attorney_Email__c,Attorney_Fax__c,Attorney_First_Name__c,Attorney_Full_Name__c,Attorney_Last_Name__c,Id,Plaintiff_First_Name__c,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c+FROM+Case+limit+3';

This works fine, but now I want to add the logged in users email address, everything I have tried is not working.
example String userEmail = UserInfo.getUserEmail();
And adding userEmail in my soql string ect..

How can I get the email to be passed in the query.
Thanks,
Keith.
Hello All,
How do I write a simple Salesforce class that will execute this soql "SELECT LastModifiedDate,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c FROM Case limit 3"
And return a Json string so I can pass that to my C# rest service.
And for testing sake call the class from the Developer Console.

Thanks for any help, I am learning SF as I go.
Keith.
Hello All,
I am making a call from my c# rest service to try and get Salesforce latest version number, but SF is not retuning a parsable Json stirng.
HttpClient apiCallClient = new HttpClient();
            //String restCallURL = ServiceURL + "/services/data/v40.0/sobjects";                
            String restCallURL = ServiceURL + "/services/data/";
            
            HttpRequestMessage apirequest = new HttpRequestMessage(HttpMethod.Get, restCallURL);
            apirequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            apirequest.Headers.Add("authorization", "Bearer " + authToken);
            HttpResponseMessage apiCallResponse = await apiCallClient.SendAsync(apirequest);

            String requestresponse = await apiCallResponse.Content.ReadAsStringAsync();

           // String jsonResult = requestresponse.TrimStart(new char[] { '[' }).TrimEnd(new char[] { ']' });

            List<String> sObjLst = new List<String>();
            return requestresponse.ToString();
            
            if (apiCallResponse.IsSuccessStatusCode)
            {

                JObject sObjJObj = JObject.Parse(requestresponse);
                return sObjJObj.ToString();

            }
In the above code requestresponse equals, below but newtonsoft_Json is not able to parse it, and if I try and parse it with online parsers they also return errors.

[{\"label\":\"Winter '11\",\"url\":\"/services/data/v20.0\",\"version\":\"20.0\"},{\"label\":\"Spring '11\",\"url\":\"/services/data/v21.0\",\"version\":\"21.0\"},{\"label\":\"Summer '11\",\"url\":\"/services/data/v22.0\",\"version\":\"22.0\"},{\"label\":\"Winter '12\",\"url\":\"/services/data/v23.0\",\"version\":\"23.0\"},{\"label\":\"Spring '12\",\"url\":\"/services/data/v24.0\",\"version\":\"24.0\"},{\"label\":\"Summer '12\",\"url\":\"/services/data/v25.0\",\"version\":\"25.0\"},{\"label\":\"Winter '13\",\"url\":\"/services/data/v26.0\",\"version\":\"26.0\"},{\"label\":\"Spring '13\",\"url\":\"/services/data/v27.0\",\"version\":\"27.0\"},{\"label\":\"Summer '13\",\"url\":\"/services/data/v28.0\",\"version\":\"28.0\"},{\"label\":\"Winter '14\",\"url\":\"/services/data/v29.0\",\"version\":\"29.0\"},{\"label\":\"Spring '14\",\"url\":\"/services/data/v30.0\",\"version\":\"30.0\"},{\"label\":\"Summer '14\",\"url\":\"/services/data/v31.0\",\"version\":\"31.0\"},{\"label\":\"Winter '15\",\"url\":\"/services/data/v32.0\",\"version\":\"32.0\"},{\"label\":\"Spring '15\",\"url\":\"/services/data/v33.0\",\"version\":\"33.0\"},{\"label\":\"Summer '15\",\"url\":\"/services/data/v34.0\",\"version\":\"34.0\"},{\"label\":\"Winter '16\",\"url\":\"/services/data/v35.0\",\"version\":\"35.0\"},{\"label\":\"Spring '16\",\"url\":\"/services/data/v36.0\",\"version\":\"36.0\"},{\"label\":\"Summer '16\",\"url\":\"/services/data/v37.0\",\"version\":\"37.0\"},{\"label\":\"Winter '17\",\"url\":\"/services/data/v38.0\",\"version\":\"38.0\"},{\"label\":\"Spring '17\",\"url\":\"/services/data/v39.0\",\"version\":\"39.0\"},{\"label\":\"Summer '17\",\"url\":\"/services/data/v40.0\",\"version\":\"40.0\"},{\"label\":\"Winter '18\",\"url\":\"/services/data/v41.0\",\"version\":\"41.0\"}]

Thanks for any help or advice.
Keith.
Hello All,
I have the follwoing Rest call in Salesforce development console and it seems to be working, but how to I read the request in my C# method the URI is pointing too.
String Soql = 'SELECT LastModifiedDate,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c FROM Case limit 3';
List<sObject> L = Database.query(Soql);
Bolden,Plaintiff_Last_Name__c=Bolden,Id=500g000000G3NmpAAF})';

String jsonResponse = Json.serialize(L);

String url = 'http://localhost:1025/ErpApiService/api/PriceForCustomerB/';

Http h = new Http();
HttpRequest req = new HttpRequest();
system.debug('got request');
req.setHeader('Content-Type', 'application/json');

req.setEndpoint(url);
system.debug('setendpoint');
//req.setMethod('GET');
req.setMethod('POST');
req.setBody(jsonResponse);
HttpResponse res = h.send(req);
Thanks for any help or advice,
Keith.
 
Needing help to get Case information to my C# rest service.
Below is my code, but I am getting "Bad Request" error.
I am not sure what I need to do to get my query results to my service for reading.
Thanks,
KS
String Soql = 'SELECT LastModifiedDate,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c FROM Case limit 3';
List<sObject> L = Database.query(Soql);
String url = 'http://server/ErpApiService/api/PriceForCustomerB/' + L;

System.Debug(url);

Http h = new Http();
HttpRequest req = new HttpRequest();
system.debug('got request');
req.setHeader('Content-Type', 'application/json');

req.setEndpoint(url);
system.debug('setendpoint');
req.setMethod('GET');
HttpResponse res = h.send(req);

 system.debug('res' + res);
system.debug('Price: ' + res.getBody());

 
Hello All
I am new to Salesforce and Restful services.
But I currently have a c# rest service running and I am able to call it from SF, but currently I am just passing in a hard coded string value.
Here is my code that I can run from the Development Console
 
String url = 'http://server/ErpApiService/api/PriceForCustomerA/10/15';

Http h = new Http();
HttpRequest req = new HttpRequest();
system.debug('got request');
req.setEndpoint(url);
system.debug('setendpoint');
req.setMethod('GET');
HttpResponse res = h.send(req);
 system.debug('res' + res);
system.debug('Price: ' + res.getBody());

And this works and calls my rest service passing in a string value, but now I want to pass back some actual data from salesforce example
'SELECT LastModifiedDate,Plaintiff_Full_Name__c,Plaintiff_Last_Name__c FROM Case limit 3';
I know I will have to change my parameter in my rest service to accept whatever SF will be passing to me.

But here I am not sure what or how to do this? Do I need to create a dictionary object, and pass that?
What do I need to do in SF to pass query results and then read them in my rest service.
Thanks for any help or advice,
Keith.
 
Hello All,
One I am new to SF and Apex and their triggers, but I wrote this trigger and at one time it worked in Dev. Now it is not updating the list, with all my system.debug statements it gets all the way down to the update lstCase; statment but then errors out.
Can someone help me out on what might be happening now.
Thanks,
Keith.
 
trigger MostRecentCenter on Procedure__c (after insert, after update) {
   try{           
            
           Set<Id> procIds = new Set<Id>();
           Set<Id> caseIds = new Set<Id>();
		   List<Case> lstCase = new List<Case>();
               
               for(Procedure__c proc : Trigger.New)
               {                 
                   if(proc.CreatedDate != null) 
                   { 
                       procIds.add(proc.LastModifiedById);  
                       caseIds.add(proc.Case__c);                      
                   }                        
               }                        
               
              Map<string, Procedure__c> procMap = new map<string, Procedure__c> ( [SELECT CenterID__c, Center__c from Procedure__c 
               where LastModifiedById IN: procIds Order by CreatedDate Desc] );     

              Map<string, Case> caseMap = new map<string, Case> ( [SELECT Id, Most_Recent_Center__c FROM Case WHERE Id IN: caseIds] );  
                         
                 for(Procedure__c pd: trigger.new) 
                 {       
                     //system.debug(pd.id);

                    if(procMap.containsKey(pd.id)) 
                    {           
                      
                        //Id centerID = (Id)procMap.get(pd.id).Center__c;
                        //Case cs = (Case)[SELECT Id, Most_Recent_Center__c FROM Case WHERE Id = :pd.Case__c];
                        //cs.Most_Recent_Center__c = centerID;
						
                        system.debug('pd.id = ' + pd.id);
                        system.debug('caseMap = ' + caseMap);
                        system.debug('pd.case = ' + pd.Case__c);
                        system.debug('procmap.get = ' + procMap.get(pd.id).Center__c);

                        caseMap.get(pd.Case__c).Most_Recent_Center__c = procMap.get(pd.id).Center__c;                     
                        lstCase.add(caseMap.get(pd.Case__c));                      
                                                               
                    }       
                }
                    system.debug('lstCase Size = ' + lstCase.size());
				if(lstCase.size()>0)
                    system.debug('in size if');
					update lstCase;                
          
        
    }catch(Exception e){
       //Package suspended, uninstalled or expired, exit gracefully.
       System.debug('Error MostRecentCenter');
    }
    
}

 
Hello all,
I am new with Apex and Salesforce so bare with me.
Up until now all the triggers I have written work just fine in Dev/QA and production.
But now I have this one trigger that needs a test class, but I am not sure where to being.
If someone can help me develop a test class that for the trigger below, then I should be able to understand how to test my triggers in the future. How to get the data needed to test the triggers ect...
Thanks,
Keith.
trigger MostRecentCenter on Procedure__c (after insert, after update) {
   try{           
            
           Set<Id> procIds = new Set<Id>();
           Set<Id> caseIds = new Set<Id>();
       List<Case> lstCase = new List<Case>();
               
               for(Procedure__c proc : Trigger.New)
               {                 
                   if(proc.CreatedDate != null) 
                   { 
                       procIds.add(proc.LastModifiedById);  
                       caseIds.add(proc.Case__c);                      
                   }                        
               }                        
               
              Map<string, Procedure__c> procMap = new map<string, Procedure__c> ( [SELECT CenterID__c, Center__c from Procedure__c 
               where LastModifiedById IN: procIds Order by CreatedDate Desc] );     

              Map<string, Case> caseMap = new map<string, Case> ( [SELECT Id, Most_Recent_Center__c FROM Case WHERE Id IN: caseIds] );  
                         
                 for(Procedure__c pd: trigger.new) 
                 {       
                     //system.debug(pd.id);

                    if(procMap.containsKey(pd.id)) 
                    {                 
                      
                        //Id centerID = (Id)procMap.get(pd.id).Center__c;
                        //Case cs = (Case)[SELECT Id, Most_Recent_Center__c FROM Case WHERE Id = :pd.Case__c];
                        //cs.Most_Recent_Center__c = centerID;
            caseMap.get(pd.Case__c).Most_Recent_Center__c = procMap.get(pd.id).Center__c;
                        lstCase.add(caseMap.get(pd.Case__c));                      
                                                               
                    }       
                }
                //system.debug(lstCase.size());
        if(lstCase.size()>0)
          update lstCase;
                
          //  }    //End of trigger.isBefore
        
    }catch(Exception e){
       //Package suspended, uninstalled or expired, exit gracefully.
       System.debug('MostRecentCenter');
    }
    
}

 
Is it possible to have the user get an email, everytime they log into Salesforce?  If so How?
Thanks,
Keith.
Hello All,
I need to be able to update an Azure database from Salesforce.  Mainly for Cases and Lawyers, when cases or lawyers get updated I need to update the Azure DB as well.
I have seen the examples that talk about Azure to Salesforce, but I have not seen anything talking about Salesforce to Azure.
I have looked at both the Salesforce WCF and RestAPI https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/
But again these go from Azure to Salesforce.

Is it possible to go the other way?  What would be the best approch to this as I have seen many differnt approches to connecting.
We don't want any syncing of data, just to make a .NET call when Salesforce records get updates ect.. to update our Azure DB.
Thanks,
K.
Hello All,
I need to help with my trigger.
What I am trying to accomplish is when a user adds a Procedure from our Case page we want a field on the Case page to populate with the Procedures Center Name.
Here is my trigger.  I am guessing it will need to be a trigger on Procudure__C and not on Case.
The line that is not working is: pd.Case__r.Most_Recent_Center__c = 'a0Qa000000RDrPuEAL';
This ID is the Center__C Id to get the name from the lookup field on the case page.
It seems I have all the values I need, but I cannot display anyof them in my debug statments.
trigger MostRecentCenter2 on Procedure__c (before insert, before update) {
    try{   
         if(trigger.isBefore){
            
            Set<Id> caseIds = new Set<Id>();
               
                for(Procedure__c cs : Trigger.New)
                {
                    if(cs.LastModifiedById != null) 
                    { 
                        caseIds.add(cs.LastModifiedById); 
                         //system.debug('>>>>>  '+(cs.LastModifiedById));

                    }                   
                }
                           
               //Map<string, Procedure__c> caseMap = new map<string, Procedure__c> ( [SELECT id, Name,  LastModifiedById  from Procedure__c 
               // where LastModifiedById IN: caseIds] );
             
              Map<string, Procedure__c> caseMap = new map<string, Procedure__c> ( [SELECT id, CenterID__c, Center__c,  Name, LastModifiedById from Procedure__c 
               where LastModifiedById IN: caseIds Order by Procedure_Date__c Desc] );

                //Map<string, Procedure__c> caseMap = new map<string, Procedure__c> ( [SELECT id, Name, LastModifiedById, Center__r.Name   from Procedure__c
                //where LastModifiedById IN: caseIds] ); 
                for(Procedure__c p: [SELECT LastModifiedById  from Procedure__c 
                                where LastModifiedById IN: caseIds]){                 
                    caseMap.put(p.LastModifiedById, p); 
                } 

               
              system.debug(' *************** caseMap :  ' + caseMap);
                for(Procedure__c pd: trigger.new) 
                {                   
                   
                    system.debug(' ***********  getobj= '+caseMap.getSObjectType());
                    system.debug('>>>>> in for loopA '+caseMap.size());
                    system.debug('>>>>> keysets'+caseMap.keyset());
                    system.debug('>>>>> in for loopB '+caseMap.values());
                    system.debug(' *********** pd.Center__c ' + pd.Center__c);
                    system.debug(' *********** pd.Center__r ' + pd.Center__r.Name);

                    system.debug('>>>>> LastModBy= '+caseMap.get(pd.LastModifiedById));
                    system.debug('>>>>> ID '+caseMap.get(pd.LastModifiedById).id);                    
                                               
            
                    if(caseMap.containsKey(pd.LastModifiedById)) 
                    {
                       
                            system.debug('>>>> BOOfdsfsd');                        
                            system.debug('>>>>> whatid= '+caseMap.get(pd.LastModifiedById).Center__c);
                           // system.debug('>>>>> center= '+caseMap.get(pd.LastModifiedById).Center__r.id);
                           // 'a0Qa000000RDrPuEAL'
                            pd.Case__r.Most_Recent_Center__c = 'a0Qa000000RDrPuEAL';
                           // pd.Case__r.Most_Recent_Center__c = caseMap.get(pd.LastModifiedById).id;
                                               
                    }       
                }  


            }    //End of trigger.isBefore
    
        
    }catch(Exception e){
       //Package suspended, uninstalled or expired, exit gracefully.
       System.debug('MostRecentCenter');
    }
    
}
Debug Output:
14:07:32:020 USER_DEBUG [31]|DEBUG| *************** caseMap :  {00522000000rdLyAAI=Procedure__c:{LastModifiedById=00522000000rdLyAAI, Id=a0M22000000bPu9EAE}, a0M22000000bPu9EAE=Procedure__c:{Id=a0M22000000bPu9EAE, CenterID__c=1376, Center__c=a0Qa000000RDrPuEAL, Name=Proc-97617, LastModifiedById=00522000000rdLyAAI}}
14:07:32:021 USER_DEBUG [35]|DEBUG| ***********  getobj= Procedure__c
14:07:32:021 USER_DEBUG [36]|DEBUG|>>>>> in for loopA 2
14:07:32:021 USER_DEBUG [37]|DEBUG|>>>>> keysets{00522000000rdLyAAI, a0M22000000bPu9EAE}
14:07:32:021 USER_DEBUG [38]|DEBUG|>>>>> in for loopB (Procedure__c:{Id=a0M22000000bPu9EAE, CenterID__c=1376, Center__c=a0Qa000000RDrPuEAL, Name=Proc-97617, LastModifiedById=00522000000rdLyAAI}, Procedure__c:{LastModifiedById=00522000000rdLyAAI, Id=a0M22000000bPu9EAE})
14:07:32:021 USER_DEBUG [39]|DEBUG| *********** pd.Center__c a0Qa000000RDrPuEAL
14:07:32:021 USER_DEBUG [40]|DEBUG| *********** pd.Center__r null
14:07:32:021 USER_DEBUG [42]|DEBUG|>>>>> LastModBy= Procedure__c:{LastModifiedById=00522000000rdLyAAI, Id=a0M22000000bPu9EAE}
14:07:32:021 USER_DEBUG [43]|DEBUG|>>>>> ID a0M22000000bPu9EAE
14:07:32:021 USER_DEBUG [49]|DEBUG|>>>> BOOfdsfsd
14:07:32:022 USER_DEBUG [65]|DEBUG|MostRecentCenter

Thanks,
Keith.