• sflearning
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 12
    Replies
trigger tocallout on Opportunity (after insert, after update) {
    Set<id> accountids = new Set<id>();
    
  for (Opportunity op : Trigger.new) {
  accountIds.add(op.AccountId);    
  }
  
  Map<Id, Account> accountMap = new Map<Id, Account>([SELECT ia_crm__IntacctID__c FROM Account WHERE Id IN :accountIds]);
    String sName;

    for (Opportunity op : Trigger.new){
    if(op.Account.ia_crm__IntacctID__c != null){
    sName = accountMap.get(op.AccountId).ia_crm__IntacctID__c;
}
    if (op.stagename == 'Contract Signed' && sName  != null && (op.CC__c != null || op.Routing_Number__c != null)) {
           if (OpportunityTriggerHandlerclass.ShowRun == true) {
            OpportunityTriggerHandlerclasshandler = new  OpportunityTriggerHandlerclass(); 
        handler.sendCardToTP(op);
      }
    }
  }
}

pls help for the test class...not able to cover..

sName = accountMap.get(op.AccountId).ia_crm__IntacctID__c;

{ if (OpportunityTriggerHandlerclass.ShowRun == true) { OpportunityTriggerHandlerclasshandler = new OpportunityTriggerHandlerclass(); handler.sendCardToTP(op); }

 
public class LeadCovertclass {
  
    @AuraEnabled
   Public lead lObj;
 
    @AuraEnabled
    Public Id leadId;
    
    @AuraEnabled
   Public Id oppId, accountId, contactId ;
   
    @AuraEnabled
    public Boolean showOpportunity { get; set; }
    
   @AuraEnabled
   public boolean isVisible {get;set;}

    @AuraEnabled
   public String Accountfounds {get; set;}
  
    @AuraEnabled
     public String oppName {get; set;}
    
    @AuraEnabled    
     public String accountName {get; set;}
    
    @AuraEnabled
     public String contactName {get; set;}
   
    
    private Account [] findCompany (string companyName) {
        
        //perform the SOSL query
        List<List<SObject>> searchList = [
            FIND :companyName 
            IN NAME FIELDS 
            RETURNING 
            Account(
                Id, 
                Name
            )
        ];
        
        List <Account> accountsFound = new List<Account>();
        
        for (List <sobject> sObjs : searchList) {
            
            for (sObject s : sObjs) {
              
              //add the account that was found to the list of found accounts
                accountsFound.add((Account) s);
            }   
        }
        
        // return the list of found accounts
        return accountsFound;
    }
   
    @AuraEnabled
    public static LeadCovertclass autoConvertRun(Id leadid)
    {
       
        LeadCovertclass obj = new LeadCovertclass();
        obj.isVisible = false;
       Lead l = [Select Id, Name, isConverted, Company From Lead where id= :leadid limit 1];
        
        if(l.isConverted == false){
        obj.isVisible = true;
      
        string company = l.Company;
        Account [] accountsFound = obj.findCompany(company + '*');
                
        
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(leadId);
        
        if (accountsFound != null && accountsFound.size() > 0) {          
           for (Account a : accountsFound) {
           lc.setAccountId(a.Id);
               
               AggregateResult[] oppcount = [SELECT COUNT(Id), AccountId FROM Opportunity where AccountId=:a.Id GROUP BY AccountId]; 
               if(oppcount.size() > 0){
               lc.setDoNotCreateOpportunity(true);
               obj.showOpportunity = false;
           }
           }
         }
        
        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
                
        
        if (lcr.isSuccess()) {
            
             obj.oppId = lcr.getOpportunityId();
            if(obj.oppId != null){  
                obj.showOpportunity = true;     
                Opportunity opp = [SELECT Name from Opportunity where id =: obj.oppId];
                obj.oppName = opp.Name;
            }         
                    
        obj.accountId = lcr.getAccountId(); 
        obj.contactId = lcr.getContactId();        
        Account acc = [SELECT Name from Account where id =: obj.accountId];
        obj.accountName = acc.Name;
        Contact cn = [SELECT Name from Contact where id =: obj.contactId];
        obj.contactName = cn.Name;
             
        }
        return obj;       
    }
    else
    return null;
    } 
}

 
Hi...
I want to copy the encryted fields from Account to Opportunity...whenever new opportunity is created and Account  encrypted fields are not null..
Account fields should b copied to opportunity..

Thanks in advance...its urgent..
plz help me with sample code...

 
Trigger
......................................................
trigger paymentinfo on Opportunity (after update) {
  for (Opportunity op : Trigger.new) {
    if ((op.CC__c != null) || (op.Routing_Number__c != null)) {
      if (paymentinfoTriggerHandler.ShowRun == true) {
       paymentinfoTriggerHandler handler = new paymentinfoTriggerHandler(); 
        handler.sendCardToTPro(op);
      }
    }
  }
}
---------------------------------------------------------------
handler

public class paymentinfoTriggerHandler {
    public paymentinfoTriggerHandler () {}
    Public Static boolean ShowRun = true;
    public void sendCardToTPro(Opportunity op) {
        if (op.TPro_Success__c != 'true') {
            //if( ! System.isBatch()  &&  ! System.isFuture() )
                paymentinfoTriggerHandler .send(op.Id);    
        }
    }
    @future(callout=true)
    STATIC public void send(String opid) {
        ShowRun = false;
        Opportunity op = [SELECT Id,Card_Holder_s_Name__c,CC__c,CC_Expiration_Date__c,Account.IntacctID__c,
                                 Org_Name__c,Card_Holder_s_Street__c,Card_Holder_s_Street_2__c,Card_Holder_s_City__c,Card_Holder_s_State__c,Card_Holder_s_Zip__c,
                                 Account.Organization_Email_Address__c, Account.Primary_Contact_Email__c,Event_Code__c,Routing_Number__c,Accounting_Number__c,TPro_Success__c,TPro_AuthID__c,TPro_CC_StoredAccountID__c
                          FROM Opportunity
                          WHERE Id = :opid];
        
        op.TPro_Success__c = null;
        op.TPro_CC_StoredAccountID__c = null;
        
        HttpRequest authRequest = new HttpRequest();
        authRequest.setHeader('Content-Type', 'text/xml');
        authRequest.setEndpoint('URL');
        authRequest.setMethod('POST');
        string xml = '';
        xml += '<request>';
        xml += '  <authentication>';
        xml += '    <user>';
        xml += '      <gateway></gateway>';
        xml += '      <emailaddress></emailaddress>';
        xml += '      <password></password>';
        xml += '      <application>Salesforce</application>';
        xml += '      <version>1.0.0</version>';
        xml += '    </user>';
        xml += '  </authentication>';
        xml += '  <content continueonfailure="true">';
        xml += '    <update>';
        xml += '      <customer refname="customer">';
        xml += '        <name>' + op.Account.IntacctID__c + '</name>';
        xml += '        <displayname>' + op.Org_Name__c + '</displayname>';
        xml += '      </customer>';
        xml += '    </update>';
        xml += '    <if condition="{!customer.responsestatus!} != \'success\'">';
        xml += '      <create>';
        xml += '        <customer refname="customer">';
        xml += '          <name>' + op.Account.IntacctID__c + '</name>';
        xml += '          <displayname>' + op.Org_Name__c + '</displayname>';
        xml += '        </customer>';
        xml += '      </create>';
        xml += '    </if>';
        xml += '    <if condition="{!customer.responsestatus!} = \'success\'">';
        xml += '      <update>';
        xml += '        <contact refname="contact">';
        xml += '          <name>B_{!customer.name!}</name>';
        xml += '          <customer>{!customer.id!}</customer>';
        xml += '          <contacttype>billing</contacttype>';
        if (op.Org_Name__c != null)
          xml += '          <companyname>' + op.Org_Name__c + '</companyname>';
        if (op.Card_Holder_s_Name__c != null) {
          xml += '          <firstname>' + op.Card_Holder_s_Name__c + '</firstname>';
          xml += '          <lastname>' + op.Card_Holder_s_Name__c + '</lastname>';
        }
        if (op.Card_Holder_s_Street__c != null)
          xml += '          <address1>' + op.Card_Holder_s_Street__c + '</address1>';
        if (op.Card_Holder_s_Street_2__c != null)
          xml += '          <address2>' + op.Card_Holder_s_Street_2__c + '</address2>';
        if (op.Card_Holder_s_City__c != null)
          xml += '          <city>' + op.Card_Holder_s_City__c + '</city>';
        if (op.Card_Holder_s_State__c != null)
          xml += '          <state>' + op.Card_Holder_s_State__c + '</state>';
        if (op.Card_Holder_s_Zip__c != null)
          xml += '          <zipcode>' + op.Card_Holder_s_Zip__c + '</zipcode>';
        xml += '          <country>United States</country>';
        if (op.Account.Organization_Email_Address__c != null)
          xml += '          <email1>' + op.Account.Organization_Email_Address__c + '</email1>';
        xml += '        </contact>';
        xml += '      </update>';
        xml += '    </if>';
        xml += '    <if condition="{!contact.responsestatus!} != \'success\'">';
        xml += '      <create>';
        xml += '        <contact refname="contact">';
        xml += '          <name>B_{!customer.name!}</name>';
        xml += '          <customer>{!customer.id!}</customer>';
        xml += '          <contacttype>billing</contacttype>';
        if (op.Org_Name__c != null)
          xml += '          <companyname>' + op.Org_Name__c + '</companyname>';
        if (op.Card_Holder_s_Name__c != null) {
          xml += '          <firstname>' + op.Card_Holder_s_Name__c + '</firstname>';
          xml += '          <lastname>' + op.Card_Holder_s_Name__c + '</lastname>';
        }
        if (op.Card_Holder_s_Street__c != null)
          xml += '          <address1>' + op.Card_Holder_s_Street__c + '</address1>';
        if (op.Card_Holder_s_Street_2__c != null)
          xml += '          <address2>' + op.Card_Holder_s_Street_2__c + '</address2>';
        if (op.Card_Holder_s_City__c != null)
          xml += '          <city>' + op.Card_Holder_s_City__c + '</city>';
        if (op.Card_Holder_s_State__c != null)
          xml += '          <state>' + op.Card_Holder_s_State__c + '</state>';
        if (op.Card_Holder_s_Zip__c != null)
          xml += '          <zipcode>' + op.Card_Holder_s_Zip__c + '</zipcode>';
        xml += '          <country>United States</country>';
        if (op.Account.Organization_Email_Address__c != null)
          xml += '          <email1>' + op.Account.Organization_Email_Address__c + '</email1>';
        xml += '        </contact>';
        xml += '      </create>';
        xml += '    </if>';
        if ((op.CC__c != null) && (op.CC__c.trim().length() > 0) && (op.CC_Expiration_Date__c != null) && (op.CC_Expiration_Date__c.trim().length() > 0)) {
        xml += '    <if condition="{!contact.responsestatus!} = \'success\'">';
        xml += '      <update>';
        xml += '        <storedaccount refname="cc">';
        xml += '          <name>' + op.Event_Code__c + '_CC</name>';
        xml += '          <displayname>' + op.Event_Code__c + '_CC</displayname>';
        xml += '          <customer>{!customer.id!}</customer>';
        xml += '          <contact>{!contact.id!}</contact>';
        xml += '          <creditcard>';
        xml += '            <keyed>';
        if (op.CC__c != null)
          xml += '              <cardholdernumber>' + op.CC__c + '</cardholdernumber>';
        if (op.Card_Holder_s_Name__c != null)
          xml += '              <cardholdername>' + op.Card_Holder_s_Name__c + '</cardholdername>';
        if (op.CC_Expiration_Date__c != null) {
          xml += '              <expiresmonth>' + op.CC_Expiration_Date__c.substring(0, 2) + '</expiresmonth>';
          xml += '              <expiresyear>' + '20' + op.CC_Expiration_Date__c.substring(op.CC_Expiration_Date__c.length() - 2, op.CC_Expiration_Date__c.length()) + '</expiresyear>';
        }
        xml += '            </keyed>';
        xml += '          </creditcard>';
        xml += '        </storedaccount>';
        xml += '      </update>';
        xml += '    </if>';
        xml += '    <if condition="{!cc.responsestatus!} != \'success\'">';
        xml += '      <create>';
        xml += '        <storedaccount refname="cc">';
        xml += '          <name>' + op.Event_Code__c + '_CC</name>';
        xml += '          <displayname>' + op.Event_Code__c + '_CC</displayname>';
        xml += '          <customer>{!customer.id!}</customer>';
        xml += '          <contact>{!contact.id!}</contact>';
        xml += '          <creditcard>';
        xml += '            <keyed>';
        if (op.CC__c != null)
          xml += '              <cardholdernumber>' + op.CC__c + '</cardholdernumber>';
        if (op.Card_Holder_s_Name__c != null)
          xml += '              <cardholdername>' + op.Card_Holder_s_Name__c + '</cardholdername>';
        if (op.CC_Expiration_Date__c != null) {
          xml += '              <expiresmonth>' + op.CC_Expiration_Date__c.substring(0, 2) + '</expiresmonth>';
          xml += '              <expiresyear>' + '20' + op.CC_Expiration_Date__c.substring(op.CC_Expiration_Date__c.length() - 2, op.CC_Expiration_Date__c.length()) + '</expiresyear>';
        }
        xml += '            </keyed>';
        xml += '          </creditcard>';
        xml += '        </storedaccount>';
        xml += '      </create>';
        xml += '    </if>';
        }
        if ((op.Accounting_Number__c != null) && (op.Accounting_Number__c.trim().length() > 0) && (op.Routing_Number__c != null) && (op.Routing_Number__c.trim().length() > 0)) {
        xml += '    <if condition="{!contact.responsestatus!} = \'success\'">';
        xml += '      <update>';
        xml += '        <storedaccount refname="ach">';
        xml += '          <name>' + op.Event_Code__c + '_ACH</name>';
        xml += '          <displayname>' + op.Event_Code__c + '_ACH</displayname>';
        xml += '          <customer>{!customer.id!}</customer>';
        xml += '          <contact>{!contact.id!}</contact>';
        xml += '          <ach>';
        if (op.Card_Holder_s_Name__c != null)
          xml += '            <AccountHolder>' + op.Card_Holder_s_Name__c + '</AccountHolder>';
        if (op.Accounting_Number__c != null)
          xml += '            <AccountNumber>' + op.Accounting_Number__c + '</AccountNumber>';
        xml += '            <PaymentType>Single</PaymentType>';
        if (op.Routing_Number__c != null)
          xml += '            <RoutingNumber>' + op.Routing_Number__c + '</RoutingNumber>';
        xml += '            <SecCode>CCD</SecCode>';
        xml += '          </ach>';
        xml += '        </storedaccount>';
        xml += '      </update>';
        xml += '    </if>';
        xml += '    <if condition="{!ach.responsestatus!} != \'success\'">';
        xml += '      <create>';
        xml += '        <storedaccount refname="ach">';
        xml += '          <name>' + op.Event_Code__c + '_ACH</name>';
        xml += '          <displayname>' + op.Event_Code__c + '_ACH</displayname>';
        xml += '          <customer>{!customer.id!}</customer>';
        xml += '          <contact>{!contact.id!}</contact>';
        xml += '          <ach>';
        if (op.Card_Holder_s_Name__c != null)
          xml += '            <AccountHolder>' + op.Card_Holder_s_Name__c + '</AccountHolder>';
        if (op.Accounting_Number__c != null)
          xml += '            <AccountNumber>' + op.Accounting_Number__c + '</AccountNumber>';
        xml += '            <PaymentType>Single</PaymentType>';
        if (op.Routing_Number__c != null)
          xml += '            <RoutingNumber>' + op.Routing_Number__c + '</RoutingNumber>';
        xml += '            <SecCode>CCD</SecCode>';
        xml += '          </ach>';
        xml += '        </storedaccount>';
        xml += '      </create>';
        xml += '    </if>';
        }
        xml += '  </content>';
        xml += '</request>';
        authRequest.setBody(xml);
        //authRequest.setCompressed(true); 
        
        Http http = new Http();
        HttpResponse res = http.send(authRequest);
        DOM.Document authResponse = res.getBodyDocument();  
        for(DOM.XmlNode node :authResponse.getRootElement().getChildElements()){
          if(node.getName() == 'authentication'){
            if (node.getAttributeValue('responsestatus', '') != 'success') {
              processError(op, node);              
            }
          }
          else if(node.getName() == 'content'){
            if (processUpdateCreate(op, 'customer','customer',node) == true) {
              if (processUpdateCreate(op, 'contact','contact',node) == true) {              
                processUpdateCreate(op, 'storedaccount','cc',node);
                processUpdateCreate(op, 'storedaccount','ach',node);
              }
            }
          }
        }
        update op;
    }
    STATIC public void processError(Opportunity op, DOM.XmlNode errorNode) {
      for(DOM.XmlNode node :errorNode.getChildElements()){
        if (node.getName() == 'errors') {
          for(DOM.XmlNode enode :node.getChildElements()){
            if (enode.getName() == 'error') {
              string enumber = '';
              string edescription = '';
              for(DOM.XmlNode enode2 :enode.getChildElements()){
                if (enode2.getName() == 'number')
                  enumber = enode2.getText();
                else if (enode2.getName() == 'description')
                  edescription = enode2.getText();
              }
              if (op.TPro_Success__c == null)
                op.TPro_Success__c = edescription + ' (' + enumber + ')';
              else
                op.TPro_Success__c = op.TPro_Success__c + ',' + edescription + ' (' + enumber + ')';
            }
          }
        }
      }
    }
    STATIC public Boolean processUpdateCreate(Opportunity op, string nodename, string refname, DOM.XmlNode ucNode) {
      Boolean isUpdated = false;
      Boolean isCreated = false;
      DOM.XmlNode tempCreated = null;
      DOM.XmlNode tempUpdated = null;
      for(DOM.XmlNode subnode :ucnode.getChildElements()){
        if (subnode.getName() == 'update') {
          for(DOM.XmlNode updatenode :subnode.getChildElements()){
            if (nodename == updatenode.getName()) {
              tempUpdated = updatenode;
              if ((updatenode.getAttributeValue('responsestatus', '') == 'success') && (updatenode.getAttributeValue('refname', '') == refname)) {
                isUpdated = true;
                if (refname == 'cc') {
                  for(DOM.XmlNode idnode :updatenode.getChildElements()){
                    if (idnode.getName() == 'id') {
                      op.TPro_CC_StoredAccountID__c = idnode.getText();
                    }
                  }                 
                }
              }
            }
          }
        }
        else if (subnode.getName() == 'create') {
          for(DOM.XmlNode createnode :subnode.getChildElements()){
            if (nodename == createnode.getName()) {
              tempCreated = createnode;
              if ((createnode.getAttributeValue('responsestatus', '') == 'success') && (createnode.getAttributeValue('refname', '') == refname)) {
                isCreated = true;
                if (refname == 'cc') {
                  for(DOM.XmlNode idnode :createnode.getChildElements()){
                    if (idnode.getName() == 'id') {
                      op.TPro_CC_StoredAccountID__c = idnode.getText();
                    }
                  }                 
                }
              }
            }
          }
        }
      } 
      if ((isUpdated == false) && (isCreated == false)) {
        if (tempCreated != null)
          processError(op, tempCreated);
        else if (tempUpdated != null)
          processError(op, tempUpdated);
        return (false);
      }         
      string tempstatus = '';
      if (isUpdated == true)
        tempstatus = 'Updated';
      else if (isCreated == true)
        tempstatus = 'Created';
      if (op.TPro_Success__c == null)
        op.TPro_Success__c = 'Successfully ' + tempstatus + ': ' + refname;
      else
        op.TPro_Success__c = op.TPro_Success__c + ',Successfully ' + tempstatus + ': ' + refname;
      update op; 
      return (true);
    }
}

hi...m new to sf.. can i get the code to test the rest api callout ...its urgent to delicer...thanks a lot !!!
Hi All,

I have created one custom button with Content Source as URL. So whenever i click on that button the client URL will hit. Now i created one trigger(it will execute whenever a contact is updated).

My issue is, i want to fetch that custom button funcationality in trigger. How can i do that.
 
Hi,

I have created Custom Detail Page Button with a HTTP URL. When user clicks on that button on a record, the URL link gets executed( Contacts third party server) and a field value is updated with the result on the record.

I have a requirement to not use this custom button and make the process automatic i.e. to execute URL Execution when a record is created ( Instead of user clickling on the button everytime).

Do anyone have idea how to call this HTTP URL in the apex class when a record is created?

Thanks in advance

The Action Plans v3 workes great but in our scenario we need the following option:

- When a new Opportunity is created, the Stage always starts at "Prospecting"

- How do I "Trigger an Action Plan" based on that Sales Stage?

- Which would automatically load the Action Plan and it's preassigned tasks?

- Then when the stage changes to "Qualification", it triggers the next Action Plan automatically?

 

Currently we would have to "manually" assign the Action Plan based on the Stage, which runs the risk of not being assigned..