• amyamyamy
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 7
    Replies

Is it possible to convert the SQL query below to SOQL???

 

select * from (select * from table where email = 'abc@gmail.com' order by CreatedDate ) limit 1

 

Thank you!!

Hi,

 

I am new to apex and creating a trigger to delete newly inserted contacts with duplicate emails. Actually since emails have to be unique in our salesforce instance, we are trying to do a cleanup right after new contacts are inserted.

 

Here's my trigger and I cannot get it saved due to this error: 
Error: Compile Error: unexpected token: global at line 28 column 0

 

Could any please help?? Thank you!!

 

****trigger****

trigger manageEmailAfterInsert on Contact (after insert, after update) {

/* This trigger is created by Heller to delete the duplicate contacts being inserted */
Set<String> setEmail = new Set<String>();
Map<String, Id> contactMap1 = new Map<String, Id>();
List<String> ToBeDeleted = new List<String>();
for (Contact Contact : trigger.new)
{
setEmail.add(Contact.Email);
contactMap1.put(Contact.Email,Contact.Id);
}

for(Contact dupContact : [select email from Contact where email in: setEmail])
{
if(contactMap1.containsKey(dupContact.Email))
{
ToBeDeleted.add(contactMap1.get(dupContact.Email));
}
}

If(ToBeDeleted.size() > 0)
//delete ToBeDeleted;
DeleteDupContact.deleteRecords();
}


global class DeleteDupContact {
@future
public deleteRecords(String[] ToBeDeleted) {

try {
DeleteResult[] deleteResults = connection.delete(ToBeDeleted);
for (int i = 0; i < deleteResults.length; i++) {
DeleteResult deleteResult = deleteResults[i];
if (deleteResult.isSuccess()) {
System.out
.println('Deleted Record ID: ' + deleteResult.getId());
} else {
// Handle the errors.
// We just print the first error out for sample purposes.
Error[] errors = deleteResult.getErrors();
if (errors.length > 0) {
System.out.println('Error: could not delete ' + 'Record ID '
+ deleteResult.getId() + '.');
System.out.println(' The error reported was: ('
+ errors[0].getStatusCode() + ') '
+ errors[0].getMessage() + '\n');
}
}
}
} catch (ConnectionException ce) {
ce.printStackTrace();
}
}

Hi, I need help with my very first apex btach...

For the CustomIterable class, I am following this example:

global class CustomIterable implements Iterator<Contact>{ 
List<Contact> accs {get; set;} 
Integer i {get; set;} 
public CustomIterable(){ 
accs = [SELECT Id, Name FROM Contact WHERE Name = 'test']; 
i = 0; 
} 
global boolean hasNext(){ 
if(i >= accs.size()) 
return false; 
else
return true; 
} 
global Contact next(){ 
if(i == 8){ i++; return null;} 
i=i+1; 
return accs[i-1]; 
} 
}

 

I am trying to replace line 5 

accs = [SELECT Id, Name FROM Contact WHERE Name = 'test'];

with my codes:

List<Location_By_Zip_Code__c> zips = [select JDRF_Location__r.Name From Location_By_Zip_Code__c where Update_Zip__c= true];
for(Location_By_Zip_Code__c lbz : zips ){
List<Contact> consbyzip = [SELECT id, RecordTypeId, MailingPostalCode, AccountID, JDRF_Location__c, Do_Not_Auto_Update_Location__c, Major_Donor__c, Planned_Giving_Membership__c FROM Contact WHERE JDRF_Location__r.Name = :lbz.JDRF_Location__r.Name];
}

But I've been trying for hours, still couldn't figure out how to populate my query to a list...

 

Could anyone please help?

 

I appreciate it!! Thank you!!

The multiselect picklist boxes's width is fixed for standard salesforce.com pages like "Create" or "Edit". And because of this, there's a scroll bar at the bottom so I always have to scroll from left to right in order to see the whole page. I checked in Winer 13 environment, the multiselect picklist boxes' width is not fixed.

Does anyone know how to fix this?

Thank you!!

Can anyone help me with this soql query please?

 

I have three objects:

Contact (Lookup to Location__c object by Location__c field which holds location IDs)

Location__c (has two child lookup relationships with the other 2 objects) - the two most important fields in this objects are location ID and location name

Location_by_Zip__c (Lookup to Location__c object by Location__c field which holds location IDs) - this object is actually for mapping between zip codes and location IDs

 

My query is like this:

 

SELECT id, RecordTypeId, MailingPostalCode, AccountID, Location__c
FROM Contact
WHERE Location__r.Name = (select Location__r.Name From Location_By_Zip__c where Update_Zip__c= true)

 

I got error: unexpected token '('

 

 

When I changed the query to:

 

SELECT id, RecordTypeId, MailingPostalCode, AccountID, Location__c
FROM Contact 
WHERE Location__r.Name IN (select Location__r.Name From Location_By_Zip__c where Update_Zip__c= true)

 

I got error: The inner select field 'Location__r.Name' cannot have more than one level of relationships

 

 

I really appreciate any help!

 

Thanks!

Is this possible?

When a task is created from a contact, Phone number is pre-populated with the contact's phone. When a task is created from an account, Phone number is pre-populated with the account's phone.

 

Any help is greately appreciated!! Thank you!

Hi,

 

I am new to apex and creating a trigger to delete newly inserted contacts with duplicate emails. Actually since emails have to be unique in our salesforce instance, we are trying to do a cleanup right after new contacts are inserted.

 

Here's my trigger and I cannot get it saved due to this error: 
Error: Compile Error: unexpected token: global at line 28 column 0

 

Could any please help?? Thank you!!

 

****trigger****

trigger manageEmailAfterInsert on Contact (after insert, after update) {

/* This trigger is created by Heller to delete the duplicate contacts being inserted */
Set<String> setEmail = new Set<String>();
Map<String, Id> contactMap1 = new Map<String, Id>();
List<String> ToBeDeleted = new List<String>();
for (Contact Contact : trigger.new)
{
setEmail.add(Contact.Email);
contactMap1.put(Contact.Email,Contact.Id);
}

for(Contact dupContact : [select email from Contact where email in: setEmail])
{
if(contactMap1.containsKey(dupContact.Email))
{
ToBeDeleted.add(contactMap1.get(dupContact.Email));
}
}

If(ToBeDeleted.size() > 0)
//delete ToBeDeleted;
DeleteDupContact.deleteRecords();
}


global class DeleteDupContact {
@future
public deleteRecords(String[] ToBeDeleted) {

try {
DeleteResult[] deleteResults = connection.delete(ToBeDeleted);
for (int i = 0; i < deleteResults.length; i++) {
DeleteResult deleteResult = deleteResults[i];
if (deleteResult.isSuccess()) {
System.out
.println('Deleted Record ID: ' + deleteResult.getId());
} else {
// Handle the errors.
// We just print the first error out for sample purposes.
Error[] errors = deleteResult.getErrors();
if (errors.length > 0) {
System.out.println('Error: could not delete ' + 'Record ID '
+ deleteResult.getId() + '.');
System.out.println(' The error reported was: ('
+ errors[0].getStatusCode() + ') '
+ errors[0].getMessage() + '\n');
}
}
}
} catch (ConnectionException ce) {
ce.printStackTrace();
}
}

Hi, I need help with my very first apex btach...

For the CustomIterable class, I am following this example:

global class CustomIterable implements Iterator<Contact>{ 
List<Contact> accs {get; set;} 
Integer i {get; set;} 
public CustomIterable(){ 
accs = [SELECT Id, Name FROM Contact WHERE Name = 'test']; 
i = 0; 
} 
global boolean hasNext(){ 
if(i >= accs.size()) 
return false; 
else
return true; 
} 
global Contact next(){ 
if(i == 8){ i++; return null;} 
i=i+1; 
return accs[i-1]; 
} 
}

 

I am trying to replace line 5 

accs = [SELECT Id, Name FROM Contact WHERE Name = 'test'];

with my codes:

List<Location_By_Zip_Code__c> zips = [select JDRF_Location__r.Name From Location_By_Zip_Code__c where Update_Zip__c= true];
for(Location_By_Zip_Code__c lbz : zips ){
List<Contact> consbyzip = [SELECT id, RecordTypeId, MailingPostalCode, AccountID, JDRF_Location__c, Do_Not_Auto_Update_Location__c, Major_Donor__c, Planned_Giving_Membership__c FROM Contact WHERE JDRF_Location__r.Name = :lbz.JDRF_Location__r.Name];
}

But I've been trying for hours, still couldn't figure out how to populate my query to a list...

 

Could anyone please help?

 

I appreciate it!! Thank you!!

The multiselect picklist boxes's width is fixed for standard salesforce.com pages like "Create" or "Edit". And because of this, there's a scroll bar at the bottom so I always have to scroll from left to right in order to see the whole page. I checked in Winer 13 environment, the multiselect picklist boxes' width is not fixed.

Does anyone know how to fix this?

Thank you!!

Is this possible?

When a task is created from a contact, Phone number is pre-populated with the contact's phone. When a task is created from an account, Phone number is pre-populated with the account's phone.

 

Any help is greately appreciated!! Thank you!

Hi,

 

I am facing 'Parse error' when trying to generate Apex Class from a WSDL generated by Informatica Web Service.

 

Error: Failed to parse wsdl: Parse error: Found invalid XML. processing instruction can not have PITarget with reserveld xml name (position: START_DOCUMENT seen

 

Has anybody faced this issue?  

Please let me know if anybody can help me on the same.

 

Thanks & Regards,

Deepak