• Management 20
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Hi All
I'm completely new to Apex triggers but have managed to put together the trigger below to automatically send account records to a 2nd salesforce org when the record is created usng S2S .The trigger works perfectly on our sandbox but I am now unable to deploy it to production because the relevant tests have not been run. I've tried looking at documentation on how to do this but I've had no success so far. If anyone could help me out on this I'd be extremely grateful!

trigger SendAccountsToConnection on Account (after insert) {
        PartnerNetworkConnection conn = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection  where ConnectionStatus = 'Accepted' and ConnectionName = 'xxxabc'];
        List<PartnerNetworkRecordConnection> recordConnectionToInsert  = new List<PartnerNetworkRecordConnection>  ();
        for (Account acc : Trigger.new){
            PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();

            newrecord.ConnectionId = conn.Id;
            newrecord.LocalRecordId = acc.id;  
            newrecord.SendClosedTasks = false;
            newrecord.SendOpenTasks = false;
            newrecord.SendEmails = false;
            recordConnectionToInsert.add(newrecord);
        }
        if (recordConnectionToInsert.size() > 0){
            System.debug('>>> Sharing ' + recordConnectionToInsert.size() + ' records');
            insert recordConnectionToInsert;
        }
}
Hi All,
I am looking to integrate 2 Salesforce Orgs using rest API - I am completely new to coding and apex - I have managed to integrate org 1 and org 2 for the account object but I now want to do the same for opportunity. Below is the code I have used for the account object which works - when creating an account in 1 org it automatically creates in org 2. How do i do the same for Opportunity?

APEX CLASS

public class SendAccount {
private final String clientId = '********';
private final String clientSecret = '****';
private final String username = '***';
private final String password = '*****';
public class deserializeResponse
{
public String id;
public String access_token;
}
public String ReturnAccessToken (SendAccount acount)
{
String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(reqbody);
req.setMethod('POST');
req.setEndpoint('https://*****/services/oauth2/token');
HttpResponse res = h.send(req);
deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
return resp1.access_token;
}
@future(callout=true)
public static void createAccount(String accName, String accPhone, String accWebsite, String accType, String accIndustry, String accSource, String accDescription, String accNotes, String accAddress, String accId)
{
SendAccount acount = new SendAccount();
String accessToken = acount.ReturnAccessToken (acount);
if(accessToken != null)
{
String endPoint = 'https://********/services/data/v32.0/sobjects/Account/';
String jsonstr = '{"Name" : "' + accName + '","Phone" : "' + accPhone + '","Website" : "' + accWebsite + '","Type" : "' + accType + '","Industry" : "' + accIndustry + '","Source__c" : "' + accSource + '","Description__c" : "' + accDescription + '","Notes__c" : "' + accNotes + '","Address__c" : "' + accAddress + '"}';
Http h2 = new Http();
HttpRequest req1 = new HttpRequest();
req1.setHeader('Authorization','Bearer ' + accessToken);
req1.setHeader('Content-Type','application/json');
req1.setHeader('accept','application/json');
req1.setBody(jsonstr);
req1.setMethod('POST');
req1.setEndpoint(endPoint);
HttpResponse res1 = h2.send(req1);
deserializeResponse resp2 = (deserializeResponse)JSON.deserialize(res1.getbody(),deserializeResponse.class);
Account a = [SELECT Phone, Website, Type, Industry, Source__c, Description__c, Notes__c, Address__c, Id FROM Account WHERE Id = :accId];
a.externalid__c = resp2.id;
update a;
}
}
}


APEX TRIGGER

trigger SendAccount on Account (after insert) {
for(Account a:Trigger.new){
SendAccount.createAccount(a.name, a.Phone, a.Website, a.Type, a.Industry, a.Source__c, a.Description__c, a.Notes__c, a.Address__c, a.Id);
}
}
 
We are trying to create a connection between two salesforce orgs through API. What we are looking for exactly is to integrate two orgs so that when we update a field or object on one org it automatically updates on the second org and vice versa I have limited to no coding experience so dont really have a clue where to go to get the data to integrate. Any assistance would be extremely appreciated - note we have tried Salesforce to Salesforce but its limitations do not work for us - having to externally share each record manually and the fact when you delete on one org it does not delete on the other.
Hi All
I'm completely new to Apex triggers but have managed to put together the trigger below to automatically send account records to a 2nd salesforce org when the record is created usng S2S .The trigger works perfectly on our sandbox but I am now unable to deploy it to production because the relevant tests have not been run. I've tried looking at documentation on how to do this but I've had no success so far. If anyone could help me out on this I'd be extremely grateful!

trigger SendAccountsToConnection on Account (after insert) {
        PartnerNetworkConnection conn = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection  where ConnectionStatus = 'Accepted' and ConnectionName = 'xxxabc'];
        List<PartnerNetworkRecordConnection> recordConnectionToInsert  = new List<PartnerNetworkRecordConnection>  ();
        for (Account acc : Trigger.new){
            PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();

            newrecord.ConnectionId = conn.Id;
            newrecord.LocalRecordId = acc.id;  
            newrecord.SendClosedTasks = false;
            newrecord.SendOpenTasks = false;
            newrecord.SendEmails = false;
            recordConnectionToInsert.add(newrecord);
        }
        if (recordConnectionToInsert.size() > 0){
            System.debug('>>> Sharing ' + recordConnectionToInsert.size() + ' records');
            insert recordConnectionToInsert;
        }
}
Hi All,
I am looking to integrate 2 Salesforce Orgs using rest API - I am completely new to coding and apex - I have managed to integrate org 1 and org 2 for the account object but I now want to do the same for opportunity. Below is the code I have used for the account object which works - when creating an account in 1 org it automatically creates in org 2. How do i do the same for Opportunity?

APEX CLASS

public class SendAccount {
private final String clientId = '********';
private final String clientSecret = '****';
private final String username = '***';
private final String password = '*****';
public class deserializeResponse
{
public String id;
public String access_token;
}
public String ReturnAccessToken (SendAccount acount)
{
String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(reqbody);
req.setMethod('POST');
req.setEndpoint('https://*****/services/oauth2/token');
HttpResponse res = h.send(req);
deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
return resp1.access_token;
}
@future(callout=true)
public static void createAccount(String accName, String accPhone, String accWebsite, String accType, String accIndustry, String accSource, String accDescription, String accNotes, String accAddress, String accId)
{
SendAccount acount = new SendAccount();
String accessToken = acount.ReturnAccessToken (acount);
if(accessToken != null)
{
String endPoint = 'https://********/services/data/v32.0/sobjects/Account/';
String jsonstr = '{"Name" : "' + accName + '","Phone" : "' + accPhone + '","Website" : "' + accWebsite + '","Type" : "' + accType + '","Industry" : "' + accIndustry + '","Source__c" : "' + accSource + '","Description__c" : "' + accDescription + '","Notes__c" : "' + accNotes + '","Address__c" : "' + accAddress + '"}';
Http h2 = new Http();
HttpRequest req1 = new HttpRequest();
req1.setHeader('Authorization','Bearer ' + accessToken);
req1.setHeader('Content-Type','application/json');
req1.setHeader('accept','application/json');
req1.setBody(jsonstr);
req1.setMethod('POST');
req1.setEndpoint(endPoint);
HttpResponse res1 = h2.send(req1);
deserializeResponse resp2 = (deserializeResponse)JSON.deserialize(res1.getbody(),deserializeResponse.class);
Account a = [SELECT Phone, Website, Type, Industry, Source__c, Description__c, Notes__c, Address__c, Id FROM Account WHERE Id = :accId];
a.externalid__c = resp2.id;
update a;
}
}
}


APEX TRIGGER

trigger SendAccount on Account (after insert) {
for(Account a:Trigger.new){
SendAccount.createAccount(a.name, a.Phone, a.Website, a.Type, a.Industry, a.Source__c, a.Description__c, a.Notes__c, a.Address__c, a.Id);
}
}
 
We are trying to create a connection between two salesforce orgs through API. What we are looking for exactly is to integrate two orgs so that when we update a field or object on one org it automatically updates on the second org and vice versa I have limited to no coding experience so dont really have a clue where to go to get the data to integrate. Any assistance would be extremely appreciated - note we have tried Salesforce to Salesforce but its limitations do not work for us - having to externally share each record manually and the fact when you delete on one org it does not delete on the other.