Header Ads Widget

SFDC QUESTIONS AND ANSWERS


3. Can we insert Contact or Opportunity related for an account, while inserting contact or opportunity ?



Yes, We can, for that we need to trigger on Contact/Opportunity ,here we are inserting contact/opportunity related to an account for that we need to specify account Id also.

            We PartnerNetworkRecordConnection object for sharing records between salesforce to salesforce.

It contains filed 'ParentRecordId',to that filed we need to assign that account id.I have written trigger on conatct , i am giving code for that,you can implement same thing for opportunity also.

              

 Trigger autoforwardContact on Contact(after Insert)

{ 

String  UserName = UserInfo.getName();

 String orgName = UserInfo.getOrganizationName(); 

List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>(   [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted']  );

System.debug('Size of connection map: '+connMap.size());

 List<PartnerNetworkRecordConnection> prncList = new List<PartnerNetworkRecordConnection>();

for(Integer i =0; i< Trigger.size; i++)

{

Contact con = Trigger.new[i];

String conId = con.Id;

System.debug('Value of ContactId: '+conId);

 for(PartnerNetworkConnection network : connMap)

 {

String cid = network.Id;

String status = network.ConnectionStatus;

String connName = network.ConnectionName;

 String ContactName = con.LastName;

String Accountid = con.Accountid;

System.debug('Connectin Details.......Cid:::'+cid+'Status:::'+Status+'ConnName:::'+connName+'ContactName:::'+COntactName);

 System.debug('Account ID************'+Accountid);

 if(ContactName!= NULL)

{ 

System.debug('INSIDE IF'); 

 PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection(); 

 newrecord.ConnectionId = cid; 

 newrecord.LocalRecordId = ConId; 

 newrecord.ParentRecordId= Accountid; // here we are specifying Account ID 

 newrecord.SendClosedTasks = true;  

newrecord.SendOpenTasks = true;

  newrecord.SendEmails = true;  

System.debug('Inserting New Record'+newrecord);

  insert newrecord;

}} } }       

Using Above Trigger we can Send newly inserted record in to Partner's organization.

Post a Comment

0 Comments