2

I am creating lead using Force.com Toolkit for PHP.

I have also created trigger when any lead is created. using this trigger I wants to open one popup or model in salesforce screen. is it possible ?

2
  • Triggers can't perform any UI actions Ashwin. Those are for deal with any logic whenever a database transaction occurs. – highfive Jun 9 '14 at 7:47
  • Then is there any possibility to open popup using create apex page and map with trigger? – Salesforce Jun 9 '14 at 7:49
3

After the lead is inserted via the API you can retrieve the resulting record Id. This is after all the triggers have completed and control has returned to your PHP code.

Then in your PHP code you can redirect the user to a new URL that includes the resulting lead ID.

The URL will be something like:

https://na5.salesforce.com/00Q300000000001

You will want to pull the server url from the toolkit based on the connection. I think this is the $location or endpoint in the SforceBaseClient. The 00Q part will be the new Lead ID. If the user doesn't already have an active session in the browser you can either set a cookie for them out bounce the request through a login URL.


Disclaimer: I've never written a line of PHP before. This might work, or it might not compile (Is PHP compiled or interpreted?). This was partially butchered from the Workbench source for jumpToSfdc.php.

// Get the Lead Id from the inserted record. Assumes only one. Not error checking...
$response = $mySforceConnection->insert($leadRecords);
$leadId = $response[0]->id;

// Split the location URL to get the Salesforce domain.
preg_match("@((https?://)((.*)-api)?(.*))/services@", 
    $mySforceConnection->getLocation();, $sfdcApiHost);

// [1] => https://na4-api.salesforce.com
// [2] => https://
// [3] => na4-api
// [4] => na4
// [5] => .salesforce.com

if ($sfdcApiHost[3] != null) {
    //special cases
    switch ($sfdcApiHost[4]) {
        case "na0": $sfdcApiHost[4] = "ssl"; break;
        case "ap0": $sfdcApiHost[4] = "ap"; break;
        case "eu0": $sfdcApiHost[4] = "emea"; break;
    }
    $sfdcUiHost = $sfdcApiHost[2] . $sfdcApiHost[4] . $sfdcApiHost[5];
} else {
    $sfdcUiHost = $sfdcApiHost[1];
}

$jumpUrl = "$sfdcUiHost/secur/frontdoor.jsp?sid=". $mySforceConnection->getSessionId() 
            . "&retURL=%2F" . $leadId;

// Redirect the browser to the frontdoor to login to Salesforce and navigate to the lead.
header("Location: " . $jumpUrl);
8
  • Hi Denial, Thanks For update. I hope this will work but can you please give example of Force.com Toolkit for PHP. So it can be very useful for me. – Salesforce Jun 9 '14 at 9:36
  • I tried setEndpoint($location) function but it is not open that location in salesforce. Please suggest. – Salesforce Jun 9 '14 at 9:38
  • Actually I am using Force.com Toolkit for PHP to insert lead (REST API). when any rest api call and lead is created after that I wants to open popup or model in salesforce who ever is login in salesforce. So here salesforce screen is open in another window and lead api call is in another window. I wants to open popup when any lead successfully created then wants to open popup in salesforce screen. Please suggest. – Salesforce Jun 9 '14 at 10:28
  • I've put something together that will hopefully point you in the right direction. It will redirect the browser to the lead that was inserted. You may need to adapt it open a separate browser window. – Daniel Ballinger Jun 9 '14 at 22:50
  • Hi Danial, Thanks for update, I have tried this but there is some confusion over here. My scenario is different. I have account callportal like twillio and when call start I am calling salesforce api and create lead into salesforce. but at a same time in my screen only open salesforce account. I wants to open popup in salesforce screen when any lead is created. Please suggest ? – Salesforce Jun 10 '14 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.