• ranjanikmca1.3940038284852163E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
ranjanikmca1.3940038284852163E12
Hi,

Can any one give solution for this.

$query1 = "Select body,ContentType,Name FROM Attachment Where Id = '00PQ0000001gQzc' OR Name='B.pdf' ORDER BY Name ASC " ;
$queryResult = $partnerConnection->query($query1);
print_r($queryResult);
echo "<br/><Br/>";
print_r($queryResult->records);
echo "<br/><Br/>";
$records = $queryResult->records;

foreach ($queryResult->records as $record) {
    echo $record->fields->Name."<br/>\n";
}

In this above code  print_r($queryResult); displays only array[0] th record. But it shows [size] => 2.
I cant get the second record.
foreach ($queryResult->records as $record) {
    echo $record->fields->Name."<br/>\n";

}

displays only the 1st record name . It does not show the second record  Name.


The Result for the above code is

QueryResult Object ( [queryLocator] => 01gQ000000EhwCfIAJ-1 [done] => [records] => Array ( [0] => SObject Object ( [type] => Attachment [fields] => stdClass Object ( [Body] => NTQxRDQxNkRCNzY1Mj48MTMwMTAxMTRBMkM5NTk0MUE3MDU0MUQ0MTZEQjc2NTI+XSAvUHJldiA4MTA5MS9YUmVmU3RtIDgwODQ1Pj4NCnN0YXJ0eHJlZg0KODE0NjcNCiUlRU9G [ContentType] => application/pdf [Name] => A.pdf ) ) ) [size] => 2 )

Array ( [0] => SObject Object ( [type] => Attachment [fields] => stdClass Object ( [Body] => NTQxRDQxNkRCNzY1Mj48MTMwMTAxMTRBMkM5NTk0MUE3MDU0MUQ0MTZEQjc2NTI+XSAvUHJldiA4MTA5MS9YUmVmU3RtIDgwODQ1Pj4NCnN0YXJ0eHJlZg0KODE0NjcNCiUlRU9G [ContentType] => application/pdf [Name] => A.pdf ) ) )

A.pdf

If I remove the body from the query means it displays both records. //$query1 = "Select ContentType,Name FROM Attachment Where Id = '00PQ0000001gQzc' OR Name='B.pdf' ORDER BY Name ASC " ;
If I include body in the query means it displays only first record. //$query1 = "Select Body,ContentType,Name FROM Attachment Where Id = '00PQ0000001gQzc' OR Name='B.pdf' ORDER BY Name ASC " ;

Is anything wrong with Code ?
ranjanikmca1.3940038284852163E12
Hi,

Can any one give solution for this.

$query1 = "Select body,ContentType,Name FROM Attachment Where Id = '00PQ0000001gQzc' OR Name='B.pdf' ORDER BY Name ASC " ;
$queryResult = $partnerConnection->query($query1);
print_r($queryResult);
echo "<br/><Br/>";
print_r($queryResult->records);
echo "<br/><Br/>";
$records = $queryResult->records;

foreach ($queryResult->records as $record) {
    echo $record->fields->Name."<br/>\n";
}

In this above code  print_r($queryResult); displays only array[0] th record. But it shows [size] => 2.
I cant get the second record.
foreach ($queryResult->records as $record) {
    echo $record->fields->Name."<br/>\n";

}

displays only the 1st record name . It does not show the second record  Name.


The Result for the above code is

QueryResult Object ( [queryLocator] => 01gQ000000EhwCfIAJ-1 [done] => [records] => Array ( [0] => SObject Object ( [type] => Attachment [fields] => stdClass Object ( [Body] => NTQxRDQxNkRCNzY1Mj48MTMwMTAxMTRBMkM5NTk0MUE3MDU0MUQ0MTZEQjc2NTI+XSAvUHJldiA4MTA5MS9YUmVmU3RtIDgwODQ1Pj4NCnN0YXJ0eHJlZg0KODE0NjcNCiUlRU9G [ContentType] => application/pdf [Name] => A.pdf ) ) ) [size] => 2 )

Array ( [0] => SObject Object ( [type] => Attachment [fields] => stdClass Object ( [Body] => NTQxRDQxNkRCNzY1Mj48MTMwMTAxMTRBMkM5NTk0MUE3MDU0MUQ0MTZEQjc2NTI+XSAvUHJldiA4MTA5MS9YUmVmU3RtIDgwODQ1Pj4NCnN0YXJ0eHJlZg0KODE0NjcNCiUlRU9G [ContentType] => application/pdf [Name] => A.pdf ) ) )

A.pdf

If I remove the body from the query means it displays both records. //$query1 = "Select ContentType,Name FROM Attachment Where Id = '00PQ0000001gQzc' OR Name='B.pdf' ORDER BY Name ASC " ;
If I include body in the query means it displays only first record. //$query1 = "Select Body,ContentType,Name FROM Attachment Where Id = '00PQ0000001gQzc' OR Name='B.pdf' ORDER BY Name ASC " ;

Is anything wrong with Code ?

Can anyone clue me in on how to bring an attachment down from SF so my users can download to their machine?

 

I understand how to query or retrieve from the attachment object and also understand the need to decode the base64 encoded body, but my attempts have gone nowhere thus far.  Here is my code:

//SF Header stuff require_once ($_SERVER["DOCUMENT_ROOT"].'/system/header_sforce.php'); //Grab an Attachement Id from the reqeust object $attid = $_REQUEST['attid']; //Query SF for the desired attachment $query = 'SELECT Id, ParentId, Name, BodyLength, Body FROM Attachment WHERE Id = \''.$attid.'\' '; $queryObject = $mySforceConnection->query($query); //Probably have some header() methods here echo base64_decode($queryObject->records[0]->Body);

 

I know it's not elegant, right now I'm just trying to get a rudimentary download working.  If someone could just cut and paste an example of some working code from their app that would be so awesome.

 

Thanks in advance.