Synchronize Salesforce project data with Square Peg's external billing system|| challenge 8

Поделиться
HTML-код
  • Опубликовано: 12 дек 2024

Комментарии • 2

  • @Salesforcebuddy1711
    @Salesforcebuddy1711  Год назад +1

    BillingCalloutService :-
    ------------------------------------
    public class BillingCalloutService {
    @future(callout = true)
    public static void callBillingService(String projectRef, Decimal billingAmount){
    ServiceCredentials__c srvcCrd = ServiceCredentials__c.getValues('BillingServiceCredential');

    BillingServiceProxy.project projectInst = new BillingServiceProxy.project();
    projectInst.username = srvcCrd.Username__c;
    projectInst.password = srvcCrd.Password__c;
    projectInst.billAmount = billingAmount;

    BillingServiceProxy.InvoicesPortSoap11 invPortSoapInst = new BillingServiceProxy.InvoicesPortSoap11();
    String response = invPortSoapInst.billProject(projectInst);

    List lstOfProjects = new List();
    if(response != null && response.equalsIgnoreCase('OK')){
    List lstOfPrjts = [SELECT Status__c FROM Project__c WHERE ProjectRef__c = :projectRef];
    for(Project__c prjt : lstOfPrjts){
    prjt.Status__c = 'Billed';

    lstOfProjects.add(prjt);
    }

    UPDATE lstOfProjects;
    }
    }
    }
    ProjectTrigger :-
    ----------------------------
    trigger ProjectTrigger on Project__c (after update) {
    if(Trigger.isAfter && Trigger.isUpdate){
    for(Project__c prjt : Trigger.new){
    if(prjt.Status__c != null && prjt.Status__c.equals('Billable')){
    BillingCalloutService.callBillingService(prjt.ProjectRef__c, prjt.Billable_Amount__c);
    }
    }
    }
    }