public static Salesforce Login(Salesforce sfdc)
        {
            Salesforce sfdcout = new Salesforce();
            String     jsonResponse;

            try {
                using (var client = new HttpClient()) {
                    var request = new FormUrlEncodedContent(new Dictionary <string, string>
                    {
                        { "grant_type", "password" },
                        { "client_id", sfdc.ClientId },
                        { "client_secret", sfdc.ClientSecret },
                        { "username", sfdc.Username },
                        { "password", sfdc.Password + sfdc.Token }
                    }
                                                            );
                    request.Headers.Add("X-PrettyPrint", "1");
                    var response = client.PostAsync(SFDCLoginUrl, request).Result;
                    jsonResponse = response.Content.ReadAsStringAsync().Result;
                }
                var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonResponse);
                sfdcout             = sfdc;
                sfdcout.AuthToken   = values["access_token"];
                sfdcout.InstanceUrl = values["instance_url"];
                return(sfdcout);
            } catch (Exception) {
                throw;
            }
        }
예제 #2
0
        public void PutSalesforceTest()
        {
            // TODO: add unit test for the method 'PutSalesforce'
            Salesforce body = null; // TODO: replace null with proper value

            instance.PutSalesforce(body);
        }
예제 #3
0
        /// <summary>
        /// A function that uses the phone number to search for a matching contact in Salesforce and if any is found the contacts name is played to the party
        /// </summary>
        /// <param name="connectLambdaRequest"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <object> FunctionHandler(ConnectLambdaRequest connectLambdaRequest, ILambdaContext context)
        {
            Console.WriteLine("-------- Function Handler ----------");
            Console.WriteLine(connectLambdaRequest);

            // Are we logged in yet?
            if (!Salesforce.LoggedIn)
            {
                // Retrieve the authentication settings from the environment that the Lambda function is executing in
                string strClientId      = Environment.GetEnvironmentVariable("ClientId");
                string strClientSecret  = Environment.GetEnvironmentVariable("ClientSecret");
                string strUsername      = Environment.GetEnvironmentVariable("Username");
                string strPassword      = Environment.GetEnvironmentVariable("Password");
                string strSecurityToken = Environment.GetEnvironmentVariable("SecurityToken");
                Console.WriteLine($"ClientId: {strClientId}, ClientSecret: {strClientSecret}, Username: {strUsername}");

                // Use the credentials to login to Salesforce
                await Salesforce.Login(strClientId, strClientSecret, strUsername, strPassword, strSecurityToken);
            }

            // Get the phone number passed with the Connect Lambda request
            string strPhoneNumber = connectLambdaRequest?.Details?.ContactData?.CustomerEndpoint?.Address;

            Console.WriteLine($"Searching Salesforce contacts for phone number: {strPhoneNumber}");

            // Search Salesforce contacts for the phone number
            List <Contact> contacts = await Salesforce.SearchContacts(strPhoneNumber);

            // If we got exactly one contact then return it
            Console.WriteLine($"Retrieved {contacts.Count} contacts");

            // Return results in a format that makes Connect happy
            if (contacts.Count == 1)
            {
                Console.WriteLine($"Returning contact {contacts[0]}");
                var result = new
                {
                    Contact = $"\"{contacts[0]}\""
                };
                return(result);
            }

            // Return no contacts even if we got multiple hits
            Console.WriteLine("Returning empty contact result");
            var emptyResult = new
            {
                Contact = "unknown"
            };

            return(emptyResult);
        }
예제 #4
0
 private async void buttonLogin_Click(object sender, EventArgs e)
 {
     Properties.Settings.Default.Save();
     try
     {
         await Salesforce.Login(
             textBoxClientID.Text,
             textBoxClientSecret.Text,
             textBoxUserName.Text,
             textBoxPassword.Text,
             textBoxSecurityToken.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Login Failed: {ex.Message}");
     }
 }
예제 #5
0
        private async void buttonSearch_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.Save();

            listBoxContacts.Items.Clear();

            string strPhoneNumber = textBoxPhoneNumber.Text;

            try
            {
                List <Contact> contacts = await Salesforce.SearchContacts(strPhoneNumber);

                if (contacts.Count == 0)
                {
                    MessageBox.Show("No contacts found");
                    return;
                }
                listBoxContacts.Items.AddRange(contacts.ToArray());
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Search Contacts Failed: {ex.Message}");
            }
        }
예제 #6
0
    // Use this for initialization
    IEnumerator Start()
    {
        Cursor.visible = false;

        //init object
        sf = gameObject.AddComponent <Salesforce>();

        // login
        Debug.Log("Password + security token = " + password + " " + securityToken);
        sf.login(username, password + securityToken);

        // wait for Auth Token
        while (sf.token == null)
        {
            yield return(new WaitForSeconds(0.2f));
        }


        string mainQuery = "";

        mainQuery += "SELECT Id, IsDeleted, AccountId, IsPrivate, Name, Description, StageName, Amount, Probability, ExpectedRevenue,";
        mainQuery += " TotalOpportunityQuantity, CloseDate, Type, NextStep, LeadSource, IsClosed, IsWon, ForecastCategory,";
        mainQuery += " ForecastCategoryName, CampaignId, HasOpportunityLineItem, Pricebook2Id, OwnerId, CreatedDate, CreatedById,";
        mainQuery += " LastModifiedDate, LastModifiedById, SystemModstamp, LastActivityDate, FiscalQuarter, FiscalYear, Fiscal,";
        mainQuery += " LastViewedDate, LastReferencedDate, Urgent__c,";
        //Account
        mainQuery += " Account.Id, Account.Name, Account.AccountNumber, Account.Description, Account.Type, Account.Industry, Account.CustomerPriority__c, Account.UpsellOpportunity__c, Account.Priority__c,";

        //OppProducts
        mainQuery += " (SELECT Id, OpportunityId, SortOrder, PricebookEntryId, Product2.Name, ProductCode, Name, Quantity, TotalPrice, UnitPrice, ListPrice, ServiceDate, Description, Priority__c FROM OpportunityLineItems ORDER BY Priority__c DESC),";

        // Campaigns
        mainQuery += " Campaign.Id, Campaign.Name, Campaign.AmountWonOpportunities, Campaign.AmountAllOpportunities, Campaign.NumberOfWonOpportunities, Campaign.NumberOfOpportunities, Campaign.NumberOfResponses, Campaign.NumberOfContacts, Campaign.NumberOfConvertedLeads, Campaign.NumberOfLeads, Campaign.Description, Campaign.IsActive, Campaign.NumberSent, Campaign.ExpectedResponse, Campaign.ActualCost, Campaign.BudgetedCost, Campaign.ExpectedRevenue, Campaign.EndDate, Campaign.StartDate, Campaign.Status, Campaign.Type, Campaign.ParentId, Campaign.OwnerId, Campaign.Priority__c, ";

        // Contracts
        mainQuery += " Contract.Id, Contract.Status, Contract.StartDate, Contract.EndDate, Contract.ContractTerm, Contract.ContractNumber, Contract.Description, Contract.SpecialTerms, Contract.Priority__c ";

        mainQuery += " FROM Opportunity";

        sf.query(mainQuery);

        // wait for query results
        while (sf.response == null)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        Debug.Log("Response from Salesforce: " + sf.response);

        // Extract the JSON encoded value for the Store the procedure ID (Case) in a field
        // We are using the free add-in from the Unity3D Asset STore called BoomLagoon.

        // Using BoomLagoon, create a JSON Object from the Salesforce response.
        JSONObject json = JSONObject.Parse(sf.response);


        JSONArray records = json.GetArray("records");

        Debug.Log("records = " + records);

        OpportunityUtil.BuildOpportunityRings(records, transform, Ring, Block, blockBox);
    }
예제 #7
0
 public void Init()
 {
     instance = new Salesforce();
 }
예제 #8
0
    // Use this for initialization
    IEnumerator Start()
    {
        //init object
        sf = gameObject.AddComponent <Salesforce>();

        // login
        sf.login(username, password + securityToken);

        // wait for Auth Token
        while (sf.token == null)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        // query: Retrieve the next closest scheduled surgery / procedure for the current patient
        sf.query("SELECT Id, Surgery_Type__c FROM Case WHERE ContactId = '" + patientID + "' ORDER BY Surgery_Date__c LIMIT 1");

        // wait for query results
        while (sf.response == null)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        Debug.Log("Retrieve Procedure (Case):" + sf.response);

        // Extract the JSON encoded value for the Store the procedure ID (Case) in a field
        // We are using the free add-in from the Unity3D Asset STore called BoomLagoon.


        // Using BoomLagoon, create a JSON Object from the Salesforce response.
        JSONObject json = JSONObject.Parse(sf.response);

        // Retrieve the records array (only one record is returned) and traverse that record's
        // attributes to get the case Id and Surgery Type
        JSONArray records = json.GetArray("records");

        Debug.Log("records = " + records);

        foreach (JSONValue row in records)
        {
            JSONObject rec = JSONObject.Parse(row.ToString());
            Debug.Log("Procedure (case) Id = " + rec.GetString("Id") +
                      "Surgery Type = " + rec.GetString("Surgery_Type__c"));

            // Assign the case and surgery type
            procedureID = rec.GetString("Id");
            surgeryType = rec.GetString("Surgery_Type__c");
        }

        // Get the number of X-Rays to load from the Playmaker FSM Global Variables.
        int numXrays = FsmVariables.GlobalVariables.FindFsmInt("numImagesToLoad").Value;

        // query: retrieve 5 images (attachments) from the proecdure (case) record
        sf.query("SELECT Id, Name, Body FROM Attachment WHERE ParentId = '" + procedureID + "' LIMIT " + numXrays);

        // wait for query results
        while (sf.response == null)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        Debug.Log("Xray Attachments = " + sf.response);

        // Using BoomLagoon, parse the JSON response .
        json = JSONObject.Parse(sf.response);

        // Retrieve the records array (up to five records are returned)
        // Traverse through each record to obtain the link to the attachment body
        records = json.GetArray("records");
        Debug.Log("records = " + records);

        int i = 1;         // X-Ray image ObjectName starts at xRay1

        foreach (JSONValue row in records)
        {
            JSONObject rec = JSONObject.Parse(row.ToString());
            Debug.Log("Body Link = " + rec.GetString("Body"));

            // get the attachment and store in the Texture Array
            sf.getAttachmentBody(rec.GetString("Body"), i);

            i++;
        }
    }