• ekorz
  • NEWBIE
  • 75 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 24
    Replies

Hi there,

 

I am new to apex and was wondering if someone would be able to help me out by providing some example code on how I would write an apex trigger which sets the value of a lookup field based on identical values in a picklist.

 

Any help would be much appreciated,

 

Mikie

(Apex Rookie)

I'm pretty new to VF, so I'm erring on the side of verbosity.  I'm also a soccer fan.  I hope that helps?

I'm trying to build a nice way for a user to 'browse' their important records.  Basically, I'm hoping to have a filtered picklist at the top of the page, and then a table of fields/values for whatever picklist value was selected.  Imagine my users are Coaches of different soccer teams, and they want to browse their player's stats.  I could build this with a lookup field driving everything, but that seems weird for my use case.

So imagine my database is full of all soccer_players_c from teams all over the world.   This VF page would be for a coach, and they really don't care about other team's players, so I'd reduce the driving picklist to just their team's players. 

Custom object Soccer_Player__c
Field values Goals__c, Age__c, Salary__c, maybe a nice photo?

So I'd want to do some SOQL in a controller building my picklist:  [select Name from Soccer_Player__c where Team__c =$user.team]
Then display that picklist at the top of the page.  Then, whenever you click on a new player 'Name', the rest of the page updates (ajax I guess?) showing Goals, Age, Salary, maybe that nice photo... etc. 

If this is totally covered in a cookbook somewhere I'm happy to read up.  I don't think I had the right keywords when I was searching.  Otherwise if you have an example controller / page that covers this I'd love to see it!
  • February 03, 2014
  • Like
  • 0
I'm hoping to create several records, and connect them through lookups, all at once.  I've used this chapter from the handbook in the past to create parent + children records at the same time, in classes & triggers.  http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_dml_foreign_keys.htm

As soon as I try to do the same thing, but with simple lookup relationships instead of parent+child relationships, the foreign key part seems to break.  So, quoting the handbook, this no longer seems to work:

Account accountReference = new Account(
            MyExtID__c='SAP111111');               
        newOpportunity.Account = accountReference;

I'm using custom objects so these lines looks more like:

Custom_Object__c placeholder = new Custom_Object__c (
            MyExtID__c='SAP111111');
newobject.Custom_Related_Object__c = placeholder;

I've tried
newobject.Custom_Related_Object__r = placeholder;
and it throws an error that my sobject can't be assigned to a list

I've tried
newobject.Custom_Related_Object__r.id = placeholder.id;
and it saves, but doesn't work

Anyone know how to handle this? 
  • January 14, 2014
  • Like
  • 0

Hello!

 

I'm pretty new to JSON methods so forgive me if this doesn't make 100% sense...


I built an Apex class that passes JSON data from Salesforce to Netsuite.  I call the class from a Button (javascript) on a Parent record.  All works fine.

 

Before, I was just building the JSON Body manually before (code below) since it seemed easy at the time.  Now, I've got to figure out a way to query the Parent's Child records, serialize those children into the JSON, and pass the whole thing at once.

 

So, my previous method was for my button to pass in the values for the Strings 'recordType', 'entity', 'job', 'item', 'quantity', 'amount, and just build the JSON Body by hand since the field names needed to be set:

 

HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();

//set my headers & endpoint, deleted for this board post

req.setBody('{"recordtype":"'+recordType+'", "entity":"'+entity+'", "job":"'+job+'","item":[{"item":"'+item+'", "quantity":"'+quantity+'", "amount":"'+amount+'"}]}');

res = http.send(req);

 

Notice the nested "item":[{item/quantity/amount}] area?  Well, I have multiple "item" sections -- one per child record -- that I need to get in this JSON.  The Parent has the recordtype, entity, and job.  So ideally I could, in the class, query for the child records and produce a new JSON body that ends up with multiple item sets like this:

 

req.setBody('{"recordtype":"'+recordType+'", "entity":"'+entity+'", "job":"'+job+'","item":[
{"item":"'+item[1]+'", "quantity":"'+quantity[1]+'", "amount":"'+amount[1]+'"},
{"item":"'+item[2]+'", "quantity":"'+quantity[2]+'", "amount":"'+amount[2]+'"},
{"item":"'+item[n..]+'", "quantity":"'+quantity[n..]+'", "amount":"'+amount[n..]+'"},
]}');

 

I figured the existing JSON methods would be helpful, but I can't figure out how to use 'em.  If anyone has already done this, I'd love to see the code you used to build this type of JSON.  If you wanted to help out using my situation you can assume my Child__c object's fields are just item__c, quantity__c, and amount__c, as in my query would be

 

//having passed the string "id" into the class from my Button on the parent object

list<Child__c> lineitems = [Select amount__c, quantity__c, item__c from Child__c WHERE Parent__c = :id];

 

My best guess at building the new JSON is pretty terrible so far so I won't paste that in just yet!

  • November 07, 2013
  • Like
  • 0

Hi Everybody,

 

I have a cross-object formula field, and my goal is to roll it up to the parent object.  Since roll-ups on those types of formula fields aren't allowed under standard SFDC practice, I thought I'd write a trigger that copies the field, after insert/update, to a separate blank field (currency type in my case) and use *that* field as the roll-up target.  I assume it has to be after-insert/update so the formual field can calculate.

 

This code worked fine for any given record, but I'm stuck at how to bulkify the trigger in case I need to mass insert/mass update.

 

Trigger CopyfromFormulaToBlankField on Custom__c (after insert, after update) {

    List<Custom__c> clist = [SELECT Non_Formula_Field_for_Rollup__c, Formula_Field__c FROM Custom__c WHERE Id IN: Trigger.newMap.keySet()];
    
    for (Custom__c c :clist){
    
        if(lh.Non_Formula_Field_for_Rollup__c != lh.Formula_Field__c){
        
            lh.Non_Formula_Field_for_Rollup__c = lh.Formula_Field__c;
            update lhlist;
        
        }
    }
}

 

 

Any ideas?

Thanks!

 

  • October 31, 2013
  • Like
  • 0

Howdy,

 

I'm passing data from one system to another, and Salesforce keeps Account.BillingStreet as one field, whereas my external system likes "address1" and "address2" separately (and treats a carrage return as invalid) .  I was hoping to solve the problem by buildng two formula fields, one for "address line 1" and another for "the rest of BillingStreet". 

 

The delimiting factor would seems to be a carraige return stored in BillingStreet, and although I can find that it's "char(10)" in excel and should be '\r' otherwise, I can't figure out how to program these formula fields:

 

ex. formula field 1 - find the first carraige return, if any, and return everything to the left

  LEFT( BillingStreet , FIND('\r', BillingStreet)-1)    -- but this doesn't work

 

formula field 2 - find the first carraige return, if any, and return everything to the right

 

 

 

Or if there's a better way...

 

Help!

  • October 22, 2013
  • Like
  • 0

I've been staring at the Salesforce bulkify best practice pages for like an hour, and it's just not happening for me. 

 

I have 2 custom objects, Supply and Shipment.  They're related through a lookup field, namely Supplies__c.Shipment__c.  But, my warehouse doesn't have access to the SFID's, so they're recording the "Tracking" numbers instead -- a unique identifier.  At the end of the day, I upload a list of those tracking numbers onto Supplies__c.Tracking__c and built this trigger to update the Supplies__c.Shipment__c  lookup field automatically. 

 

This trigger code queries all the Shipments, finds the one that has the tracking number in question, and updates the Supply record's lookup field with the Shipment__c.id.  Works great!  But, it blows up in bulk because of the query inside the for() loop.

 

Trigger GrabLocationFromShipment on Supplies__c (before insert, before update) {
  for (Supplies__c  s: trigger.new) {
    if(s.Tracking__c != null) {
       List<Shipment__c> ship = new List<Shipment__c>();
ship = [Select Id from Shipment__c WHERE Shipment__c.Tracking__c = :s.Tracking__c LIMIT 1]; if (ship.size() > 0){
s.Shipment__c = ship[0].Id; } } } }

 

How do I run this query outside the for() loop, and still return the matching IDs so I can update the lookup?

  • August 02, 2013
  • Like
  • 0

I realize there is a ton of material out there around bulk, batch, scheduled, @future apex, and that's actually my problem...  I'm not really sure what avenue to pursue.  For the sake of simplicity, this existing class updates the description field on Account using a @future HTTP callout (right from a great tutorial on cheenath.com):

 

public class AccountUpdater {

  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void updateAccount(String id, String name) {

    //construct an HTTP request
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://cheenath.com/tutorial/sfdc/sample1/data.txt');
    req.setMethod('GET');

    //send the request
    Http http = new Http();
    HttpResponse res = http.send(req);

    //check the response
    if (res.getStatusCode() == 200) {

      //update account
      Account acc = new Account(Id=id);
      acc.Description = res.getBody();
      update acc;
    } else {
      System.debug('Callout failed: ' + res);
    } 
  }
}

 

 

I have a trigger to fire that method after insert, and it works great.  My goal is to run the above @future method 'updateAccount', against all existing Accounts once per month (or a large subset determined by a query) Could you outline the archetecture of the system you'd use? 

 

I am fuzzy around how many classes I need to build (one to schedule, one to batch, one to execute, one to query?) and how they connect.  Can I reuse my existing @future method?  I get lost between batch apex, scheduled apex, how the limits hinder each avenue, etc. 

 

Thanks!

  • July 02, 2013
  • Like
  • 0

Hello Kind SFDC Masters!

I have two custom objects, Merchant__c  and Location__c, that I sync between our main production database and our SFDC database.  They're basically clean copies of sold Accounts, and their constituent child locations.  Think Subway -- 1 Merchant, 10000 child Locations.

I have Opportunity records that can accept an unlimited number of related addresses, a related object called "LocationHolder" with standard addy fields.

My goal is to build a trigger that, upon closing an opportunity, grabs info from Opportunity to build a Merchant, then grabs  LocationHolder records and builds child Locations.  Again, Locations are children of Merchant.  LocationHolder is related to Opportunity.

I can create the Merchant without issue, thanks mostly to another forum post, but I can't

a) grab the newly created Merchant ID, or
b) iterate through the Opportunity's related LocationHolder objects, be it zero or twenty, to create any Locations.

----So Far----

trigger createMerchantFromOpportunity on Opportunity (after insert, after update) {
    
    List <Merchant__c> MerchToInsert = new List <Merchant__c> ();  
       
    for (Opportunity o : Trigger.new) {
        

        if (o.Probability == 100) {     //my criteria for the trigger
        
        Merchant__c m = new Merchant__c ();
        
        // map opportunity fields to Merchant object
        
        m.Name = o.AccountName__c;         //named the same as the Account
m.Account__c = o.AccountID; //add reference back to Account       

m.etc__c = o.etc__c;     //etc. truncated here, you get the idea.
                    
        MerchToInsert.add(m);
                
        } //end if
             
    } //end for o
    
   try {
        insert MerchToInsert;
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    
}

----END So Far----

After the insert, I should have a Merchant ID, but I don't know how to retrieve it.  I also don't know how to build, say, 5 new Location__c records if there were 5 LocationHolder related records.

Any guidance is cause for celebration!

  • May 10, 2013
  • Like
  • 0

My previous noob question was about trigger code, so of course my next question is about writing a test for it.  Basically the Opportunities in my database can be related to Accounts, like normal, or to a custom objected called Location__c.  Locations are usually related to an Account through a lookup (Location.Account__c), so my trigger adds an account.id to an Opportunity if one was omited during the record creation, but is available through the Location relationship. 

 

OppUpdate Trigger

----------------------------

trigger OppUpdate on Opportunity(before insert, before update) {
  Map<Id,Location__c> locations = new Map<Id,Location__c>();
    for(Opportunity record:Trigger.new)
     locations.put(record.Location__c,null);
  locations.putAll([SELECT Id,Account__c FROM Location__c WHERE Id IN :locations.keySet()]);
    for(Opportunity record:Trigger.new)
   

    if(record.accountId == null && record.location__c != null)
      record.accountId = locations.get(record.Location__c).Account__c;
}

 

 

And now, the test that is failing. (I write this into an Apex Class, right?)

 

 

TestOppUpdate Apex Class

---------------------------------------

 

@isTest
   private class TestOppUpdate {
   
     static testMethod void myOppUpdateTest() {
         
        Account a = new Account( Name = 'TestAccount');
         insert a;
               
      Location__c l = new Location__c( Name = 'TestLocation', account__c = a.id);
           insert l;
            
        Opportunity o = new Opportunity( Name = 'TestOppty', AccountId = null, Location__c = l.id );
             
       { insert o; }
                    { System.assertEquals(o.AccountId, l.Account__c); }
      }
  }

  • April 05, 2013
  • Like
  • 0

I have custom object called "Locations" from which my team can create Opportunities.  "Locations" contains a "LocationDescription__c" field that's usually full of great notes, so I'd like to build a trigger to copy those notes into my Opportunity.Description field.  Simple enough right?

 

I expect that I have to build a Map<>, maybe do a SOQL query to store the related object data into the trigger, but I'm very new to this.

Here's my code, which stores a null value into Opportunity.Description when it's executed:

 

 

trigger OppUdate on Opportunity(before insert, before update) {
            
   for(Opportunity opp : Trigger.new){
           if (opp.Description == null) {
          opp.Description = opp.Location__r.LocationDescription__c;
         }
       }
}

 

 

Thanks in advance!

  • April 05, 2013
  • Like
  • 0
I'm pretty new to VF, so I'm erring on the side of verbosity.  I'm also a soccer fan.  I hope that helps?

I'm trying to build a nice way for a user to 'browse' their important records.  Basically, I'm hoping to have a filtered picklist at the top of the page, and then a table of fields/values for whatever picklist value was selected.  Imagine my users are Coaches of different soccer teams, and they want to browse their player's stats.  I could build this with a lookup field driving everything, but that seems weird for my use case.

So imagine my database is full of all soccer_players_c from teams all over the world.   This VF page would be for a coach, and they really don't care about other team's players, so I'd reduce the driving picklist to just their team's players. 

Custom object Soccer_Player__c
Field values Goals__c, Age__c, Salary__c, maybe a nice photo?

So I'd want to do some SOQL in a controller building my picklist:  [select Name from Soccer_Player__c where Team__c =$user.team]
Then display that picklist at the top of the page.  Then, whenever you click on a new player 'Name', the rest of the page updates (ajax I guess?) showing Goals, Age, Salary, maybe that nice photo... etc. 

If this is totally covered in a cookbook somewhere I'm happy to read up.  I don't think I had the right keywords when I was searching.  Otherwise if you have an example controller / page that covers this I'd love to see it!
  • February 03, 2014
  • Like
  • 0
I'm hoping to create several records, and connect them through lookups, all at once.  I've used this chapter from the handbook in the past to create parent + children records at the same time, in classes & triggers.  http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_dml_foreign_keys.htm

As soon as I try to do the same thing, but with simple lookup relationships instead of parent+child relationships, the foreign key part seems to break.  So, quoting the handbook, this no longer seems to work:

Account accountReference = new Account(
            MyExtID__c='SAP111111');               
        newOpportunity.Account = accountReference;

I'm using custom objects so these lines looks more like:

Custom_Object__c placeholder = new Custom_Object__c (
            MyExtID__c='SAP111111');
newobject.Custom_Related_Object__c = placeholder;

I've tried
newobject.Custom_Related_Object__r = placeholder;
and it throws an error that my sobject can't be assigned to a list

I've tried
newobject.Custom_Related_Object__r.id = placeholder.id;
and it saves, but doesn't work

Anyone know how to handle this? 
  • January 14, 2014
  • Like
  • 0

Hello!

 

I'm pretty new to JSON methods so forgive me if this doesn't make 100% sense...


I built an Apex class that passes JSON data from Salesforce to Netsuite.  I call the class from a Button (javascript) on a Parent record.  All works fine.

 

Before, I was just building the JSON Body manually before (code below) since it seemed easy at the time.  Now, I've got to figure out a way to query the Parent's Child records, serialize those children into the JSON, and pass the whole thing at once.

 

So, my previous method was for my button to pass in the values for the Strings 'recordType', 'entity', 'job', 'item', 'quantity', 'amount, and just build the JSON Body by hand since the field names needed to be set:

 

HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();

//set my headers & endpoint, deleted for this board post

req.setBody('{"recordtype":"'+recordType+'", "entity":"'+entity+'", "job":"'+job+'","item":[{"item":"'+item+'", "quantity":"'+quantity+'", "amount":"'+amount+'"}]}');

res = http.send(req);

 

Notice the nested "item":[{item/quantity/amount}] area?  Well, I have multiple "item" sections -- one per child record -- that I need to get in this JSON.  The Parent has the recordtype, entity, and job.  So ideally I could, in the class, query for the child records and produce a new JSON body that ends up with multiple item sets like this:

 

req.setBody('{"recordtype":"'+recordType+'", "entity":"'+entity+'", "job":"'+job+'","item":[
{"item":"'+item[1]+'", "quantity":"'+quantity[1]+'", "amount":"'+amount[1]+'"},
{"item":"'+item[2]+'", "quantity":"'+quantity[2]+'", "amount":"'+amount[2]+'"},
{"item":"'+item[n..]+'", "quantity":"'+quantity[n..]+'", "amount":"'+amount[n..]+'"},
]}');

 

I figured the existing JSON methods would be helpful, but I can't figure out how to use 'em.  If anyone has already done this, I'd love to see the code you used to build this type of JSON.  If you wanted to help out using my situation you can assume my Child__c object's fields are just item__c, quantity__c, and amount__c, as in my query would be

 

//having passed the string "id" into the class from my Button on the parent object

list<Child__c> lineitems = [Select amount__c, quantity__c, item__c from Child__c WHERE Parent__c = :id];

 

My best guess at building the new JSON is pretty terrible so far so I won't paste that in just yet!

  • November 07, 2013
  • Like
  • 0

Hi Everybody,

 

I have a cross-object formula field, and my goal is to roll it up to the parent object.  Since roll-ups on those types of formula fields aren't allowed under standard SFDC practice, I thought I'd write a trigger that copies the field, after insert/update, to a separate blank field (currency type in my case) and use *that* field as the roll-up target.  I assume it has to be after-insert/update so the formual field can calculate.

 

This code worked fine for any given record, but I'm stuck at how to bulkify the trigger in case I need to mass insert/mass update.

 

Trigger CopyfromFormulaToBlankField on Custom__c (after insert, after update) {

    List<Custom__c> clist = [SELECT Non_Formula_Field_for_Rollup__c, Formula_Field__c FROM Custom__c WHERE Id IN: Trigger.newMap.keySet()];
    
    for (Custom__c c :clist){
    
        if(lh.Non_Formula_Field_for_Rollup__c != lh.Formula_Field__c){
        
            lh.Non_Formula_Field_for_Rollup__c = lh.Formula_Field__c;
            update lhlist;
        
        }
    }
}

 

 

Any ideas?

Thanks!

 

  • October 31, 2013
  • Like
  • 0

Howdy,

 

I'm passing data from one system to another, and Salesforce keeps Account.BillingStreet as one field, whereas my external system likes "address1" and "address2" separately (and treats a carrage return as invalid) .  I was hoping to solve the problem by buildng two formula fields, one for "address line 1" and another for "the rest of BillingStreet". 

 

The delimiting factor would seems to be a carraige return stored in BillingStreet, and although I can find that it's "char(10)" in excel and should be '\r' otherwise, I can't figure out how to program these formula fields:

 

ex. formula field 1 - find the first carraige return, if any, and return everything to the left

  LEFT( BillingStreet , FIND('\r', BillingStreet)-1)    -- but this doesn't work

 

formula field 2 - find the first carraige return, if any, and return everything to the right

 

 

 

Or if there's a better way...

 

Help!

  • October 22, 2013
  • Like
  • 0

I've been staring at the Salesforce bulkify best practice pages for like an hour, and it's just not happening for me. 

 

I have 2 custom objects, Supply and Shipment.  They're related through a lookup field, namely Supplies__c.Shipment__c.  But, my warehouse doesn't have access to the SFID's, so they're recording the "Tracking" numbers instead -- a unique identifier.  At the end of the day, I upload a list of those tracking numbers onto Supplies__c.Tracking__c and built this trigger to update the Supplies__c.Shipment__c  lookup field automatically. 

 

This trigger code queries all the Shipments, finds the one that has the tracking number in question, and updates the Supply record's lookup field with the Shipment__c.id.  Works great!  But, it blows up in bulk because of the query inside the for() loop.

 

Trigger GrabLocationFromShipment on Supplies__c (before insert, before update) {
  for (Supplies__c  s: trigger.new) {
    if(s.Tracking__c != null) {
       List<Shipment__c> ship = new List<Shipment__c>();
ship = [Select Id from Shipment__c WHERE Shipment__c.Tracking__c = :s.Tracking__c LIMIT 1]; if (ship.size() > 0){
s.Shipment__c = ship[0].Id; } } } }

 

How do I run this query outside the for() loop, and still return the matching IDs so I can update the lookup?

  • August 02, 2013
  • Like
  • 0

Hi there,

 

I am new to apex and was wondering if someone would be able to help me out by providing some example code on how I would write an apex trigger which sets the value of a lookup field based on identical values in a picklist.

 

Any help would be much appreciated,

 

Mikie

(Apex Rookie)

I realize there is a ton of material out there around bulk, batch, scheduled, @future apex, and that's actually my problem...  I'm not really sure what avenue to pursue.  For the sake of simplicity, this existing class updates the description field on Account using a @future HTTP callout (right from a great tutorial on cheenath.com):

 

public class AccountUpdater {

  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void updateAccount(String id, String name) {

    //construct an HTTP request
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://cheenath.com/tutorial/sfdc/sample1/data.txt');
    req.setMethod('GET');

    //send the request
    Http http = new Http();
    HttpResponse res = http.send(req);

    //check the response
    if (res.getStatusCode() == 200) {

      //update account
      Account acc = new Account(Id=id);
      acc.Description = res.getBody();
      update acc;
    } else {
      System.debug('Callout failed: ' + res);
    } 
  }
}

 

 

I have a trigger to fire that method after insert, and it works great.  My goal is to run the above @future method 'updateAccount', against all existing Accounts once per month (or a large subset determined by a query) Could you outline the archetecture of the system you'd use? 

 

I am fuzzy around how many classes I need to build (one to schedule, one to batch, one to execute, one to query?) and how they connect.  Can I reuse my existing @future method?  I get lost between batch apex, scheduled apex, how the limits hinder each avenue, etc. 

 

Thanks!

  • July 02, 2013
  • Like
  • 0

Hello,

 

Background:

Currently I have Custom controller that will select the Product services and insert OLI into relevant Opportunity. And OLI is creating revenue schedule if there is any.(via trigger after insert)

 

Also:

I have validation rule (under OLI) in place that check: AND(Hasrevenueschedule, Ischanged(unitprice))

 

How can i insert the child record(OLI schedule) after parent(OLI) has been saved. Can i use same controller class to insert child record? so i can avoid validation to execute.

 

Thanks,

Hello Kind SFDC Masters!

I have two custom objects, Merchant__c  and Location__c, that I sync between our main production database and our SFDC database.  They're basically clean copies of sold Accounts, and their constituent child locations.  Think Subway -- 1 Merchant, 10000 child Locations.

I have Opportunity records that can accept an unlimited number of related addresses, a related object called "LocationHolder" with standard addy fields.

My goal is to build a trigger that, upon closing an opportunity, grabs info from Opportunity to build a Merchant, then grabs  LocationHolder records and builds child Locations.  Again, Locations are children of Merchant.  LocationHolder is related to Opportunity.

I can create the Merchant without issue, thanks mostly to another forum post, but I can't

a) grab the newly created Merchant ID, or
b) iterate through the Opportunity's related LocationHolder objects, be it zero or twenty, to create any Locations.

----So Far----

trigger createMerchantFromOpportunity on Opportunity (after insert, after update) {
    
    List <Merchant__c> MerchToInsert = new List <Merchant__c> ();  
       
    for (Opportunity o : Trigger.new) {
        

        if (o.Probability == 100) {     //my criteria for the trigger
        
        Merchant__c m = new Merchant__c ();
        
        // map opportunity fields to Merchant object
        
        m.Name = o.AccountName__c;         //named the same as the Account
m.Account__c = o.AccountID; //add reference back to Account       

m.etc__c = o.etc__c;     //etc. truncated here, you get the idea.
                    
        MerchToInsert.add(m);
                
        } //end if
             
    } //end for o
    
   try {
        insert MerchToInsert;
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    
}

----END So Far----

After the insert, I should have a Merchant ID, but I don't know how to retrieve it.  I also don't know how to build, say, 5 new Location__c records if there were 5 LocationHolder related records.

Any guidance is cause for celebration!

  • May 10, 2013
  • Like
  • 0

Can anybody help me on integrating salesforce to netsuite? Do we have a working apex class to do this?

 

a link that i can look into will help