• Anoop Patel 7
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 8
    Replies
I have written the code below to stop any users from deleting a record on my custom object (Service Items) if the related Opportunity is Closed Won. This is within another trigger that I have already developed and tested but now when I try to save I get a error message 'Error: Compile Error: line breaks not allowed in string literals at line 36 column -1'. I'm not even sure if the new piece of code will do what I want.

if(Trigger.isDelete && Trigger.isBefore){
        for (Service_Item__c si: trigger.old){
        if(si.Opportunity__c!= null){
          qoppIds.add(si.Opportunity__c);
            system.debug('oqppid++'+ qoppIds);
             }  
           }    
      qoppdetails = [select Id,StageName from Opportunity where Id in : qoppIds];
        system.debug('qoppdetails++'+ qoppdetails);           
       
       for(Opportunity q : qoppdetails){
       if(q.StageName=='Closed Won') - this is line 36 in my code.
      {
       q.adderror(‘Do Not Delete.Thank you.');
      }
      }
      }
I'm trying to populate a field from Opportunity to my custom object using a trigger and receiving the following error;

Error: Compile Error: Illegal assignment from LIST<Opportunity> to MAP<Id,Opportunity> at line 13 column 7

My code;

trigger populateAccountfromOpp on Service_Item__c(after insert, after update){

      Set<Id> oppIds = new Set<Id>();
      Map<Id, Opportunity> oppMap;
    
      for(Service_Item__c ser : trigger.new){
        if(ser.Opportunity__c!= null){
          oppIds.add(ser.Opportunity__c);
        }  
    
      }
    
      oppMap = [select Id, Account_Type__c from Opportunity where Id in : oppIds];
    
      for(Service_Item__c ser : trigger.new){
        if(ser.Opportunity__c != null && oppMap.containsKey(ser.Opportunity__c)){  
         ser.Account__c = oppMap.get(ser.Opportunity__c).Account_Type__c;
        }
      }
    }

Thanks in advance for any help that can be provided
I have created 2 VF pages, with one of them redirecting to the other VF form. The script below is the one causing me problems. This is the one that is added to the page layout and currently when saved or refreshed it fires. The apex works as expected however I only want it to fire when the value is changed. i.e from no to yes.

The requirement is to have the Marketing_Contributions VF appear only if the Partner_Agreements__c is equals 'Yes'. This code fires each time the page is refreshed.

<apex:page standardController="account" >
<script src="/soap/ajax/22.0/connection.js"></script>
<script src="/soap/ajax/22.0/apex.js"></script>
<script>
var arrId = '{!$CurrentPage.parameters.id}';
var queryresult = sforce.connection.query("Select Partner_Agreements__c from account where id='"+arrId+"'");
var records = queryresult.getArray("records");
if(records[0].Partner_Agreements__c=='Yes');
var confirmflag = confirm('Do you want to add Marketing Contributions?');
if(confirmflag == true)
{
window.parent.location.href="/apex/Marketing_Contributions";
}

</script>

</apex:page>
I have written the code below to stop any users from deleting a record on my custom object (Service Items) if the related Opportunity is Closed Won. This is within another trigger that I have already developed and tested but now when I try to save I get a error message 'Error: Compile Error: line breaks not allowed in string literals at line 36 column -1'. I'm not even sure if the new piece of code will do what I want.

if(Trigger.isDelete && Trigger.isBefore){
        for (Service_Item__c si: trigger.old){
        if(si.Opportunity__c!= null){
          qoppIds.add(si.Opportunity__c);
            system.debug('oqppid++'+ qoppIds);
             }  
           }    
      qoppdetails = [select Id,StageName from Opportunity where Id in : qoppIds];
        system.debug('qoppdetails++'+ qoppdetails);           
       
       for(Opportunity q : qoppdetails){
       if(q.StageName=='Closed Won') - this is line 36 in my code.
      {
       q.adderror(‘Do Not Delete.Thank you.');
      }
      }
      }
I'm trying to populate a field from Opportunity to my custom object using a trigger and receiving the following error;

Error: Compile Error: Illegal assignment from LIST<Opportunity> to MAP<Id,Opportunity> at line 13 column 7

My code;

trigger populateAccountfromOpp on Service_Item__c(after insert, after update){

      Set<Id> oppIds = new Set<Id>();
      Map<Id, Opportunity> oppMap;
    
      for(Service_Item__c ser : trigger.new){
        if(ser.Opportunity__c!= null){
          oppIds.add(ser.Opportunity__c);
        }  
    
      }
    
      oppMap = [select Id, Account_Type__c from Opportunity where Id in : oppIds];
    
      for(Service_Item__c ser : trigger.new){
        if(ser.Opportunity__c != null && oppMap.containsKey(ser.Opportunity__c)){  
         ser.Account__c = oppMap.get(ser.Opportunity__c).Account_Type__c;
        }
      }
    }

Thanks in advance for any help that can be provided
I have created 2 VF pages, with one of them redirecting to the other VF form. The script below is the one causing me problems. This is the one that is added to the page layout and currently when saved or refreshed it fires. The apex works as expected however I only want it to fire when the value is changed. i.e from no to yes.

The requirement is to have the Marketing_Contributions VF appear only if the Partner_Agreements__c is equals 'Yes'. This code fires each time the page is refreshed.

<apex:page standardController="account" >
<script src="/soap/ajax/22.0/connection.js"></script>
<script src="/soap/ajax/22.0/apex.js"></script>
<script>
var arrId = '{!$CurrentPage.parameters.id}';
var queryresult = sforce.connection.query("Select Partner_Agreements__c from account where id='"+arrId+"'");
var records = queryresult.getArray("records");
if(records[0].Partner_Agreements__c=='Yes');
var confirmflag = confirm('Do you want to add Marketing Contributions?');
if(confirmflag == true)
{
window.parent.location.href="/apex/Marketing_Contributions";
}

</script>

</apex:page>