• Patrick Hanahan
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
I'm trying to clean up my SalesForce a bit, and realized I have many Opportunities that are duplicates of each other. For me, duplicate Opps means multiple opportunities with the same "Job Number" which is a custom field. I tried to make it a unique field, but it won't allow me to do that until all duplicates are deleted.

So I'm trying to write some code that finds all duplicates at once and lists them so I can go through and delete the redundant ones.

I would like to just write a function that loops through all the Opps and checks like this. (pseudo code)
 
for ( Opportunity O: All Opportunities)
    {
        for ( Opportunity I: All Opportunities)
        {
            if O.jobNumber == I.jobNumber
                display I;
        }
    }
I just don't know if theres anywhere to plug that in. A report maybe? Is there anywhere I can access the entire database of opportunities and find specific ones in this manner?
 
This is the error I'm getting on this code. The error is for the last for loop. I thought I knew what the error was saying, but the wording is kind if confusing, and everything I've tried hasn't fixed it. Any ideas?
 
global class ParseEmailSubjectForJobNumber implements Messaging.InboundEmailHandler {
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, 
                                                         Messaging.Inboundenvelope envelope) {
                                                         

Account account;
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

try {
// Creating Regex to base pattern on and pulling email subject into a string
String jobNum;
integer cancelled = 0;
Opportunity opportunity;
String regex = '\\b\\d{7}\\b';
String subjectSentence = email.subject;

// Splitting the email subject into a list of words and removing all "(" and ")" and "J"
// to make the regex simpler
List<String> subjectSplit = subjectSentence.split('\\s+');  
for (String input : subjectSplit){
    input = input.replaceAll('(', '');
    input = input.replaceAll(')', '');
    input = input.replaceAll('J', '');
}        

Pattern p = Pattern.compile(regex);

// checks for the word cancelled in the subject, and sets the variable "cancelled" to 1 if it finds it (the variable is for later use)
for (String input : subjectSplit){
    if (input == 'cancelled' || input == 'Cancelled')
        cancelled = 1;
}

// loops through all words in the subject to find the job number, then sets the opportunity with the corresponding
// job number to cancelled if the subject also contains the word cancelled
for (String input : subjectSplit){
    Matcher m = p.matcher(input);
       if (m.find()){
           jobNum = input;
           if ([select count() from Opportunity where Job__c = :input] != 0 && cancelled == 1){
                opportunity = [select Id from Opportunity where Job__c = :jobNum];
                opportunity.StageName = 'Cancelled';
           }
       }else{
           break;
       }
}
}catch(Exception E){

}  
}
}

 
In most of the emails I recieve, the subject contains a 6 digit "job number", which designates which assignment the email is about. Many of these emails come from the same email address, so the job number is the only way I can associate an incoming email with a specific opportunity. 

Is there any way to parse each incoming email subject to look for a 6 digit code?
Hi I am having trouble with adding a contact into salesforce. the Below error is what I have been getting. Also, Trigger does not show up under contacts under customize.

Review all error messages below to correct your data.
Apex trigger sync.contactTrigger caused an unexpected exception, contact your administrator: sync.contactTrigger: execution of AfterInsert caused by: line 8, column 9: trigger body is invalid and failed recompilation: Dependent class is invalid and needs recompilation: sync.asyncapex: line 24, column 28: sObject type 'Lead' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
Hi,

Does anyone know how to fix this issue when adding a contact?

See below for error message:
sync.contactTrigger: execution of AfterInsert caused by: line 8, column 9: trigger body is invalid and failed recompilation: Dependent class is invalid and needs recompilation
I'm trying to clean up my SalesForce a bit, and realized I have many Opportunities that are duplicates of each other. For me, duplicate Opps means multiple opportunities with the same "Job Number" which is a custom field. I tried to make it a unique field, but it won't allow me to do that until all duplicates are deleted.

So I'm trying to write some code that finds all duplicates at once and lists them so I can go through and delete the redundant ones.

I would like to just write a function that loops through all the Opps and checks like this. (pseudo code)
 
for ( Opportunity O: All Opportunities)
    {
        for ( Opportunity I: All Opportunities)
        {
            if O.jobNumber == I.jobNumber
                display I;
        }
    }
I just don't know if theres anywhere to plug that in. A report maybe? Is there anywhere I can access the entire database of opportunities and find specific ones in this manner?
 
In most of the emails I recieve, the subject contains a 6 digit "job number", which designates which assignment the email is about. Many of these emails come from the same email address, so the job number is the only way I can associate an incoming email with a specific opportunity. 

Is there any way to parse each incoming email subject to look for a 6 digit code?
Hi,

Does anyone know how to fix this issue when adding a contact?

See below for error message:
sync.contactTrigger: execution of AfterInsert caused by: line 8, column 9: trigger body is invalid and failed recompilation: Dependent class is invalid and needs recompilation