• strangebiscuit
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies

I've been trying to create a trigger to connect entries between two custom objects upon bulk upload...I was able to get some help with the code but there's a compile error that I can't figure out. Can anyone help? It'd be greatly appreciated.

 

What we're trying to do:  basically we have two custom objects, "Sales" and "Reps". We upload a list of sales (in .csv format) into the Sales object each week. We want to make it so that every time a Sale entry gets created it is assigned to the Rep who made that sale (Sales has a master-detail relationship with Reps). Each sale lists the Name and ID# of the rep who made it, but not the Salesforce ID of the corresponding Rep entry. So we want the apex trigger to match each Sale to the correct Rep by comparing the Name and/or ID fields in both objects.

 

The code we've got so far is:

trigger SaleTrigger on Sale__c (before insert){

   //This set will store all the RepId's.

   Set<String> repIDs = new Set<String>();

   //Loop through all the new sales to be created.
   for(Sale__c sale : Trigger.new){
      //Get the rep's ID of each sale and add it to the Set
      //Note: I am assuming the API/Unique name of the Rep ID     
      //field is Rep_Id__c;
      repIDs.add(sale.Rep_ID__c);
   }

   //Now we have all the Rep ID's in the set.
   // Issue an single SOQL to get the Salesforce ID's of all the reps.
   
   Map<String,ID> mapReps = new Map<String,ID>();
   for(Rep__c repRecord : [Select ID,Rep_ID__c From Rep__c WHERE Rep_ID__c IN (:repIDs)]){
      mapReps.put(repRecord.Rep_ID__c,repRecord.ID);
   }
   
  //The mapReps has a map of all Rep ID's with Rep Salesforce ID's
   for(Sale__c sale : Trigger.new){
      ID repSalesforceID = mapReps.get(sale.Rep_ID__c);
      //This is the MD field in Sale__c.
      sale.Rep__c = repSalesforceID;
   }
   
}

 

The error I'm getting on trying to save is:  "Invalid bind expression type of SET<String> for column of type String"

It occurs on line 19 which is: 

 

for(Rep__c repRecord : [Select ID,Rep_ID__c From Rep__c WHERE Rep_ID__c IN (:repIDs)]){

 

Can anyone help me figure this out? I'd be extremely grateful.

 

I've been trying to puzzle out this problem with various roundabout methods for some time on Professional Edition, but we just upgraded to Enterprise and it seems like apex triggers would be the most effective way to implement this. I wonder if anyone could provide any advice or guidance, as I'm pretty new to apex.

 

We're trying to use Salesforce to store and organize some payroll info that is provided to us in the form of Excel spreadsheets. They are basically lists of sales which include the name and ID of the rep who made the sale. We need to upload these on a weekly basis and then be able to view the sales made by each rep. 

 

So basically we have two custom objects, "Sales" and "Reps". We upload a list of sales (in .csv format) into the Sales object each week. We want to make it so that every time a Sale entry gets created it is assigned to the Rep who made that sale (Sales has a master-detail relationship with Reps). Each sale lists the Name and ID# of the rep who made it, but not the Salesforce ID of the corresponding Rep entry. So it seems we need the apex trigger to match each Sale to the correct Rep by comparing the Name and/or ID fields in both objects.

 

Does this sound plausible and make sense? Could anyone provide any insight on how I might get started? Any help would be greatly appreciated.

 

P.S. We also need to assign "points" to each Rep based on the status of each sale that gets added...but I suppose that will come after. I've been told this might be accomplished with workflow rules, but obviously we first need to find a way of associating each Sale with the correct Rep

I've been trying to create a trigger to connect entries between two custom objects upon bulk upload...I was able to get some help with the code but there's a compile error that I can't figure out. Can anyone help? It'd be greatly appreciated.

 

What we're trying to do:  basically we have two custom objects, "Sales" and "Reps". We upload a list of sales (in .csv format) into the Sales object each week. We want to make it so that every time a Sale entry gets created it is assigned to the Rep who made that sale (Sales has a master-detail relationship with Reps). Each sale lists the Name and ID# of the rep who made it, but not the Salesforce ID of the corresponding Rep entry. So we want the apex trigger to match each Sale to the correct Rep by comparing the Name and/or ID fields in both objects.

 

The code we've got so far is:

trigger SaleTrigger on Sale__c (before insert){

   //This set will store all the RepId's.

   Set<String> repIDs = new Set<String>();

   //Loop through all the new sales to be created.
   for(Sale__c sale : Trigger.new){
      //Get the rep's ID of each sale and add it to the Set
      //Note: I am assuming the API/Unique name of the Rep ID     
      //field is Rep_Id__c;
      repIDs.add(sale.Rep_ID__c);
   }

   //Now we have all the Rep ID's in the set.
   // Issue an single SOQL to get the Salesforce ID's of all the reps.
   
   Map<String,ID> mapReps = new Map<String,ID>();
   for(Rep__c repRecord : [Select ID,Rep_ID__c From Rep__c WHERE Rep_ID__c IN (:repIDs)]){
      mapReps.put(repRecord.Rep_ID__c,repRecord.ID);
   }
   
  //The mapReps has a map of all Rep ID's with Rep Salesforce ID's
   for(Sale__c sale : Trigger.new){
      ID repSalesforceID = mapReps.get(sale.Rep_ID__c);
      //This is the MD field in Sale__c.
      sale.Rep__c = repSalesforceID;
   }
   
}

 

The error I'm getting on trying to save is:  "Invalid bind expression type of SET<String> for column of type String"

It occurs on line 19 which is: 

 

for(Rep__c repRecord : [Select ID,Rep_ID__c From Rep__c WHERE Rep_ID__c IN (:repIDs)]){

 

Can anyone help me figure this out? I'd be extremely grateful.

 

I've been trying to puzzle out this problem with various roundabout methods for some time on Professional Edition, but we just upgraded to Enterprise and it seems like apex triggers would be the most effective way to implement this. I wonder if anyone could provide any advice or guidance, as I'm pretty new to apex.

 

We're trying to use Salesforce to store and organize some payroll info that is provided to us in the form of Excel spreadsheets. They are basically lists of sales which include the name and ID of the rep who made the sale. We need to upload these on a weekly basis and then be able to view the sales made by each rep. 

 

So basically we have two custom objects, "Sales" and "Reps". We upload a list of sales (in .csv format) into the Sales object each week. We want to make it so that every time a Sale entry gets created it is assigned to the Rep who made that sale (Sales has a master-detail relationship with Reps). Each sale lists the Name and ID# of the rep who made it, but not the Salesforce ID of the corresponding Rep entry. So it seems we need the apex trigger to match each Sale to the correct Rep by comparing the Name and/or ID fields in both objects.

 

Does this sound plausible and make sense? Could anyone provide any insight on how I might get started? Any help would be greatly appreciated.

 

P.S. We also need to assign "points" to each Rep based on the status of each sale that gets added...but I suppose that will come after. I've been told this might be accomplished with workflow rules, but obviously we first need to find a way of associating each Sale with the correct Rep