SalesForce - Find list of all Campaigns - salesforce

How do I find the list of all of Campaigns via the REST API?
I did try something like the following , but I dont see its working
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
$response=$mySforceConnection->retrieve("IsActive, ParentId, Name, Type","Campaign");
Thanks

Related

Hi all, I'm getting an Error Campaigns Filed is Mandatory in new Leads from 2021. when i am trying to create a new lead

QueryResult result1 = connection.query("select id, Name from Campaign where id='" + campaignId +
"'");
LeadDetails lead = new LeadDetails();
lead.setFirstName(leadDeatils.getFirstName());
lead.setLastName(leadDeatils.getLastName());
lead.setSalutation("Mrs.");
lead.setIndus("sasadd");
Campaign campaign = (Campaign)result1.getRecords()[0];
lead.setCampaign(campaign);
SaveResult[] sr = connection.create(new SObject[] { lead });
I am new bee here. please help me out. thank you.
What is it, integration that sends Leads to SF using SOAP API?
You will have to contact Administrators / Developers in charge of that Salesforce org. There's no standard lookup from Lead to Campaign so there's nothing to be made mandatory from 2021. Here's list of standard fields.. And here's the entity relationship diagram showing that Leads (and Contacts) are linked to Campaign via many-to-many helper table called CampaignMember. (bottom left).
Whatever error you're getting - it's probably new custom field/validation rule/some other thing the SF admins in your organisation did without notifying integration team.
P.S. If you have campaign id and there's custom Campaign__c field on lead or something -you don't have to query it? You probably could just call lead.setCampaign(campaignId ); or something like that?
Added Campaign Member to get fixed
CampaignMember campaignMember = new CampaignMember();
campaignMember.setCampaignId(campaignId);
campaignMember.setLeadId(leadId);
SaveResult[] result = connection.create(new SObject[] { campaignMember });
if (result.length == 1 && result[0].isSuccess()) {
System.out.println("LeadAssignment.setCampaignMember() : " + result);
// lead.setAttachments(attachResult.getClass());;
} else {
System.out.println("LeadAssignment.setCampaignMember() : Campaign member added on lead " + leadId);
}

Creating a Multi-Contact Event with Apex in Salesforce

I am attempting to use Apex to create a multi-contact event.
I have already enabled Allow Users to Relate Multiple Contacts to Tasks and Events in the activity settings in the scratch org.
I am following the guide and the example at the bottom of these docs but I am constantly getting an error when pushing to the scratch org:
// ...
event.setEventWhoIds(attendeeContactIds);
// ...
Method does not exist or incorrect signature: void setEventWhoIds(List<String>) from the type Event.
I also tried to write directly to the field with:
event.EventWhoIds = attendeeContactIds;
With that, I get the error, that the field is not writable.
attendeeContactIds is a List of Strings representing Contact IDs.
What could I be missing? 🤔🙇🏻‍♂️
It's bit stupid, it's readonly in apex. It's exposed so integrations can quickly create event and essentially a related list together in one all-or-nothing transaction. See also https://salesforce.stackexchange.com/questions/238094/eventwhoids-is-not-writeable-in-apex-class-but-working-on-jsforce
Try something like that?
Savepoint sp = Database.setSavepoint();
event e = new Event(
StartDateTime = System.now(),
EndDateTime = System.now().addHours(1)
);
insert e;
List<EventRelation> invitations = new List<EventRelation>();
for(Contact c : [SELECT Id FROM Contact LIMIT 5]){
invitations.add(new EventRelation(
EventId = e.Id,
RelationId = c.Id,
IsInvitee = true
));
}
insert invitations;
Database.rollback(sp); // unless you really want to send it out

RestFB: Getting list of users who liked a post

I need to get the name of each like on each post on a group page. Since I first have to get some data from the original post, I'm trying to make a connection then iterate through the likes and get a list of the users who liked each post. Here's what I have:
Connection<Likes> feedLikes = postFeed.fetchConnection(id+"/likes", Likes.class, Parameter.with("fields","from,actions,type"));
// Get the iterator
Iterator<List<Likes>> likeIt = feedLikes.iterator();
while(likeIt.hasNext()) {
List<Likes> likeFeed = likeIt.next();
for (Likes currLike: likeFeed) {
String ObjectId = id;
String LikeUserId = currLike.getId();
String LikeUserName = currLike.getName();
like_data.add(new String[] {ObjectId, LikeUserId, LikeUserName});
}
}
This doesn't work and I'm a little stuck on why. I know the username is stored in Likes.LikeItem but I can't even get to that step so far. Does anyone have any idea what I'm missing?
According to the Facebook reference this is not possible (https://developers.facebook.com/docs/graph-api/reference/v3.2/object/likes):
A User or Page can only query their own likes. Other Users'or Pages' likes are unavailable due to privacy concerns.
Only aggregated counts using total_count with the summary parameter are available for Post likes.

Angular 6 - How to Join DB object with Subscribe

I am working by my own on a app with Angular 6 / Flask. I am currently facing an issue and i am not able to find anything whivh is suitting it on the web. Here is my issue :
I have 3 Model : Project, Consultant and Client. To simplify, a Project have the id of a Consultant and a Client, and also two dates. What i want to do is to :
Get the list of all my projects
Iterate on this list to handle each project
Get the Consultant from its id
Get the Client from its id
Set an object with the Consultant, the Client and the two dates
Add this project to a list
Display the list
In fact, my purpose here is to be able to display information of the Consultant and the Client of each project so i need to get the object and not just their id. So i tried to do something from what i found :
ngOnInit() {
this.projectsListSubs = this.projectsApi
.getProjects()
.flatMap(params => {
params.forEach(elem => {
this.project.start_date = elem.start_date;
this.project.end_date = elem.end_date;
return [this.consultantsApi.getConsultant(elem.consultant_id),this.clientsApi.getClient(elem.client_id)]
}
this.dataSource = new MatTableDataSource(this.dataList);
})
.subscribe(params => {
this.project.consultant = params[0].firstName + " " + params[0].lastName;
this.project.client = params[1].name;
this.dataList.push(this.project);
});
}
Of course, it doesn't work. I think this code is garbage and I am not able to find a proper way to manage this case. Could you please help me on this ?
Thanks in advance.

Modifying Value in PHP/MySQL Database Query

I know the solution to this question is super simple, but I'm missing something.
I have a database filled with people's names. Most will be displayed # URL's like this:
MySite/People/Abraham_Lincoln
However, people who are only important in Washington State will be displayed # URL's like this:
MySite/People/Washington/Gary_Locke
Abraham Lincoln is simple because the value in the database table, field URL (Abraham_Lincoln), matches the URL (Abraham_Lincoln). However, the database value Gary_Locke does NOT match the URL Washington/Gary_Locke.
So I'm trying to modify my query so that if a person is associated with Washington (WHERE Site = 'WA'), the webpage URL ($MyURL) won't equal the database table field URL but Washington/ + URL.
But how do I append 'Washington/' and URL? The following query returns 0 results when I test it in SQL, and it doesn't work at all in my PHP page.
$result = mysql_result(mysql_query("SELECT COUNT(URL)
FROM people
WHERE URL = '$MyURL' AND Site = 'PX'
OR '$MyURL' = 'Washington/'URL AND Site = 'WA'"),0);
So, again, if I'm focusing on Gary Locke (Gary_Locke in field URL), then I want to be able to display information about him at MySite/People/Washington/Gary_Locke, NOT MySite/People/Gary_Locke.
Can anyone tell me what I'm doing wrong? Thanks.
Concat will join the Washington to URL see below
$result = mysql_result(mysql_query("SELECT COUNT(URL)
FROM people
WHERE URL = '$MyURL' AND Site = 'PX'
OR '$MyURL' = CONCAT('Washington/', URL) AND Site = 'WA'"),0);
Can I also suggest doing it this way, so that if you have an sql error, it will display the error, so you can tell what is wrong
$res = mysql_query("SELECT COUNT(URL)
FROM people
WHERE URL = '$MyURL' AND Site = 'PX'
OR '$MyURL' = CONCAT('Washington/', URL) AND Site = 'WA'");
if (!$res) {
die('Invalid query: ' . mysql_error());
}
$result = mysql_result($res, 0);
I also hope you are escaping your parameters, this will do the trick. (search for sql injection if you are not sure why that is a good idea)
$MyURL = mysql_real_escape_string($MyURL);
And finally, the mysql_ set of functions will be removed from the latest version of php very soon. You should look at mysqli or pdo if this is a long term project.

Resources