function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michele ToscanoMichele Toscano 

Unexpected token: '{'

What is wrong with the syntax in this statement?  I have a syntax error on the first if statement line saying unexpected token:

public pagereference savesamp()
        //Prevent user from entering a sample request using an Inactive account or one without an address line 1 -07/19/16 MT
    {    
        if({!ISPICKVAL(Account.Account_Status__c, "Inactive")} || {!Account.Address_Line_1__c} == '')
        
        ApexPages.Message SampleNotAllowed = new ApexPages.Message(ApexPages.Severity.ERROR,'Account must be active and contain           an address in order to raise a sample request.'); 
        ApexPages.addMessage(SampleNotAllowed);
        return null;

try{
          
        upsert samObj;
        
      }Catch(Exception ex)
      {
         ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,ex.getMessage());
         ApexPages.addMessage(errorMessage);
        return null;
      }
     return new pagereference('/'+samObj.id);
    }
 
Best Answer chosen by Michele Toscano
Head In CloudHead In Cloud
By looking at your code, i think the api name for account lookup on your custom object is :"Account_Name__c"
Try this:
public pagereference savesamp()
        //Prevent user from entering a sample request using an Inactive account or one without an address line 1 -07/19/16 MT
    {    
        if(samObj.Account_Name__r.Account_Status__c == 'Inactive' || samObj.Account_Name__r.Address_Line_1__c == ''){
            ApexPages.Message SampleNotAllowed = new ApexPages.Message(ApexPages.Severity.ERROR,'Account must be active and contain an address in order to raise a sample request.'); 
            ApexPages.addMessage(SampleNotAllowed);
            return null;
        }

        
        

try{
          
        upsert samObj;
        
      }Catch(Exception ex)
      {
         ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,ex.getMessage());
         ApexPages.addMessage(errorMessage);
        return null;
      }
     return new pagereference('/'+samObj.id);
    }

 

All Answers

Nayana KNayana K
if({!ISPICKVAL(Account.Account_Status__c, "Inactive")} || {!Account.Address_Line_1__c} == '') is invalid syntax in Apex. It is valid in VF page with standardController="Account".

Refer this link https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_extension.htm

You can use one variable to store account record (say, objAccount) and then you can reframe the condition something like this :
if(objAccount.Account_Status__c == 'Inactive' || objAccount.Address_Line_1__c == '')

Please post VF page and extension code so that I can rectify if needed.
Michele ToscanoMichele Toscano
The controller is actually on a custom object called: Sample_Request_Account_Information__c - which is related to an account. It pulls from the related account to conditionally evaluate those fields. I’ve made a new reference but it’s not working. Here is the code behind the Visualforce page:
Sample Request Header

Sample Request Header Edit:

New Sample Request Header

 

Customer Information

  * = Required Information












{!$User.FirstName} {!$User.LastName} The apex class code is as follows: public with sharing class SampleEditPAge1 { Public Sample_Request_Account_Information__c samObj{set;get;} Public Sample_Request_Account_Information__c samObjTemp{set;get;} public string accName{set;get;} public string lclLan{set;get;} public string SampId = ''; public string OpId = ''; public string AcId = ''; public string RecordTypeVal{set;get;} public boolean hasIdval{set;get;} public boolean hasNotIdval{set;get;} public string gotoNewPage{set;get;} // public Map mapRecTypes = new Map(); public SampleEditPAge1(ApexPages.StandardController controller) { samObj = new Sample_Request_Account_Information__c(); samObjTemp = new Sample_Request_Account_Information__c(); gotoNewPage = 'not sure'; accName = ''; SampId= apexpages.CurrentPage().getParameters().get('id'); OpId= apexpages.CurrentPage().getParameters().get('oppid'); AcId= apexpages.CurrentPage().getParameters().get('accId'); hasNotIdval = false; hasIdval = true; if(SampId != null && SampId !=''){ hasIdval = false; hasNotIdval = true; samObj = [select id,Account_Name__c,Requested_Delivery_Date__c,Freight_Charge__c,Data_Sheet_Required__c,Account_Name__r.Name,Status__c,Approvel_Date__c,Total_weight__c,CABOT_Segment__c,Account_Region__c ,Senior_Approver_Name__c , Customer_Group__c ,OwnerId,Account_Manager__c ,JDE__c,Bill_To_JDE_AB__c,LCL_Address__c,JDE_Order_Number__c,Ship_To_Address_Line_1__c,Ship_To_Address_Line_2__c,Ship_To_Address_Line_3__c,Ship_To_Address_Line_4__c,Ship_To_City__c,Ship_To_Country__c,Ship_To_Postal_Code__c,Ship_To_State__c,Opportunity_Name__c,Notes__c,Is_This_an_SA__c, Requested_Ship_From_Location__c,Planning_Account__c,Transportation_Method__c,Transportation_Notes__c,Invoice_Required__c,COA_Required__c,MSDS_Required__c,Contact_Name__c,Customer_Reference_Number__c,Technical_Manager__c,Account_Manager_Email_Address__c,Other_Person_to_Notify_1__c,Other_Person_to_Notify_2__c,Other_Person_2_Email_Address__c,OAP_Order_Number__c,OAP_URL_Link__c, Other_Person_1_Email_Address__c from Sample_Request_Account_Information__c where id=:SampId ]; accName =samObj.Account_Name__r.name; } else if(OpId != null && OpId !='') { Opportunity opp = [select id,Name,Account.OwnerId,Account.Country__c,Account.City__c,Account.State__c,Account.Technical_Service_Manager__c,Account.ParentId,Account.Postal_Code__c,Account.State_Code__c,Account.Address_Line_1__c,Account.LCL_Address_Line_1__c,Account.Address_Line_2__c,Account.LCL_Address_Line_2__c,Account.Address_Line_3__c,Account.LCL_Address_Line_3__c,Account.Address_Line_4__c,Account.LCL_Address_Line_4__c, Account.LCL_Country__c,Account.LCL_State__c,Account.LCL_State_Code__c,Account.LCL_City__c,Account.LCL_Postal_Code__c,Account.Customer_Care__c,Account.Price_Data_Admin__c,AccountId,Account.Customer_Group_Description__c ,Account.Sub_Region__c,Account.Name,Account.CABOT_Segment__c,Account.Account_Type__c,Account.CABOT_Application__c,Account.Currency_Code__c from Opportunity where id =:OpId limit 1]; if(opp != null && opp.id != null) { system.debug('==opp=='+opp); system.debug('==opp.id=='+opp.id); system.debug('==Technical_Service_Manager__c=='+samObj.Technical_Manager__c); system.debug('==samObj.Account_Manager__c=='+samObj.Account_Manager__c); accname=opp.account.name; samObj.Account_Name__c = opp.AccountId; samObj.Opportunity_Name__c = opp.Id; samObj.Planning_Account__c= opp.Account.ParentId; samObj.Account_Manager__c= opp.Account.OwnerId; samObj.Technical_Manager__c= opp.Account.Technical_Service_Manager__c; samObj.Customer_Group__c= opp.Account.Customer_Group_Description__c; samObj.CABOT_Segment__c= opp.Account.CABOT_Segment__c; samObj.Ship_To_Address_Line_1__c= opp.Account.Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= opp.Account.Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= opp.Account.Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= opp.Account.Address_Line_4__c; samObj.Account_Region__c= opp.Account.Sub_Region__c; samObj.Ship_To_Country__c= opp.Account.Country__c; samObj.Ship_To_State__c= opp.Account.State__c; samObj.Ship_To_City__c= opp.Account.City__c; samObj.Ship_To_Postal_Code__c= opp.Account.Postal_Code__c; } } else if(AcId != null && AcId !=''){ Account acc = [select id,Name,OwnerId,Sub_Region__c,City__c,State__c,Country__c,Postal_Code__c,Technical_Service_Manager__c,ParentId,State_Code__c,Address_Line_1__c,LCL_Address_Line_1__c,Address_Line_2__c,LCL_Address_Line_2__c,Address_Line_3__c,LCL_Address_Line_3__c,Address_Line_4__c,LCL_Address_Line_4__c,LCL_Country__c,LCL_State__c,LCL_State_Code__c,LCL_City__c,LCL_Postal_Code__c,Credit_Manager__c,Account_INCOTERMS__c,CABOT_Business__c,Currency_Code__c,Customer_Care__c,Price_Data_Admin__c ,Customer_Group_Description__c,Account_Type__c,CABOT_Segment__c,CABOT_Application__c from Account where id =:AcId and Account_Status__c ='Active' limit 1]; if(acc != null && acc.id != null) { accName =acc.id; system.debug('==Technical_Service_Manager__c=='+samObj.Technical_Manager__c); system.debug('==samObj.Account_Manager__c=='+samObj.Account_Manager__c); samObj.Account_Name__c = acc.id; samObj.Planning_Account__c= acc.ParentId; samObj.Customer_Group__c= acc.Customer_Group_Description__c; samObj.CABOT_Segment__c= acc.CABOT_Segment__c; samObj.Account_Manager__c=acc.OwnerId; samObj.Technical_Manager__c= acc.Technical_Service_Manager__c; samObj.Ship_To_Address_Line_1__c= acc.Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= acc.Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= acc.Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= acc.Address_Line_4__c; samObj.Account_Region__c= acc.Sub_Region__c; samObj.Ship_To_Country__c= acc.Country__c; samObj.Ship_To_State__c= acc.State__c; samObj.Ship_To_City__c= acc.City__c; samObj.Ship_To_Postal_Code__c= acc.Postal_Code__c; } } else samObj = (Sample_Request_Account_Information__c)controller.getRecord(); } public void populateData() { system.debug('==accName &&&&&==>>'+accName); if(accName != null && accName !='') { List listacc = [select id,Name,OwnerId,Sub_Region__c,City__c,State__c,Country__c,ParentId,Postal_Code__c,Technical_Service_Manager__c,State_Code__c,Address_Line_1__c,LCL_Address_Line_1__c,Address_Line_2__c,LCL_Address_Line_2__c,Address_Line_3__c,LCL_Address_Line_3__c,Address_Line_4__c,LCL_Address_Line_4__c,LCL_Country__c,LCL_State__c,LCL_State_Code__c,LCL_City__c,LCL_Postal_Code__c,Credit_Manager__c,Account_INCOTERMS__c,CABOT_Business__c,Currency_Code__c,Customer_Care__c,Price_Data_Admin__c ,Customer_Group_Description__c,Account_Type__c,CABOT_Segment__c,CABOT_Application__c from Account where id=:accName and Account_Status__c ='Active' limit 1]; if(listacc != null && !listacc.isEmpty()) { system.debug('==accName=='+accName); system.debug('==Technical_Service_Manager__c=='+samObj.Technical_Manager__c); system.debug('==samObj.Account_Manager__c=='+samObj.Account_Manager__c); Account acc = listacc[0]; samObj.Planning_Account__c= acc.ParentId; samObj.Customer_Group__c= acc.Customer_Group_Description__c; samObj.CABOT_Segment__c= acc.CABOT_Segment__c; samObj.Account_Manager__c= acc.OwnerId; samObj.Technical_Manager__c= acc.Technical_Service_Manager__c; samObj.Ship_To_Address_Line_1__c= acc.Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= acc.Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= acc.Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= acc.Address_Line_4__c; samObj.Account_Region__c= acc.Sub_Region__c; samObj.Ship_To_Country__c= acc.Country__c; samObj.Ship_To_State__c= acc.State__c; samObj.Ship_To_City__c= acc.City__c; samObj.Ship_To_Postal_Code__c= acc.Postal_Code__c; } } } public void populatelcladdress() { system.debug('==accName *** =='+accName); if(accName != null && accName !='') { List listacc = [select id,Name,OwnerId,Sub_Region__c,City__c,State__c,ParentId,Country__c,Postal_Code__c,State_Code__c,Address_Line_1__c,Technical_Service_Manager__c,LCL_Address_Line_1__c,Address_Line_2__c,LCL_Address_Line_2__c,Address_Line_3__c,LCL_Address_Line_3__c,Address_Line_4__c,LCL_Address_Line_4__c,LCL_Country__c,LCL_State__c,LCL_State_Code__c,LCL_City__c,LCL_Postal_Code__c,Credit_Manager__c,Account_INCOTERMS__c,CABOT_Business__c,Currency_Code__c,Customer_Care__c,Price_Data_Admin__c ,Customer_Group_Description__c,Account_Type__c,CABOT_Segment__c,CABOT_Application__c from Account where name =:accName and Account_Status__c ='Active' limit 1]; if(listacc != null && !listacc.isEmpty()) { system.debug('==accName=='+accName); Account acc = listacc[0]; if(samObj.LCL_Address__c){ samObj.Ship_To_Address_Line_1__c= acc.LCL_Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= acc.LCL_Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= acc.LCL_Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= acc.LCL_Address_Line_4__c; samObj.Account_Region__c= acc.Sub_Region__c; samObj.Ship_To_Country__c= acc.LCL_Country__c; samObj.Ship_To_State__c= acc.LCL_State__c; samObj.Ship_To_City__c= acc.LCL_City__c; samObj.Ship_To_Postal_Code__c= acc.LCL_State_Code__c; } else{ samObj.Ship_To_Address_Line_1__c= acc.Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= acc.Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= acc.Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= acc.Address_Line_4__c; samObj.Account_Region__c= acc.Sub_Region__c; samObj.Ship_To_Country__c= acc.Country__c; samObj.Ship_To_State__c= acc.State__c; samObj.Ship_To_City__c= acc.City__c; samObj.Ship_To_Postal_Code__c= acc.Postal_Code__c; } } } } public pagereference savesamp() { //Prevent user from entering a sample request using an Inactive account or one without an address line 1 -07/19/16 MT if(acc.Account_Status__c == 'Inactive' || acc.Address_Line_1__c == '') ApexPages.Message SampleNotAllowed = new ApexPages.Message(ApexPages.Severity.ERROR,'Account must be active and contain an address in order to raise a sample request.'); ApexPages.addMessage(SampleNotAllowed); //Return null so the page won't redirect return null; try{ upsert samObj; }Catch(Exception ex) { ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,ex.getMessage()); ApexPages.addMessage(errorMessage); return null; } return new pagereference('/'+samObj.id); } public pagereference saveandnew() { try{ upsert samObj; gotoNewPage = 'sure'; }Catch(Exception ex) { ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,ex.getMessage()); ApexPages.addMessage(errorMessage); return null; } return null; } public pagereference Cancel() { if((SampId == null || SampId =='') && (OpId == null || OpId =='') && (AcId == null || AcId == '') ) return new pagereference('/a0h'); if(SampId != null && SampId !='' && (OpId == null || OpId =='') && (AcId == null || AcId =='')) return new pagereference('/'+SampId); if(AcId != null && AcId !='') return new pagereference('/'+AcId); if(OpId != null && OpId !='') return new pagereference('/'+OpId); return null; } } Regards, Michele Toscano Senior Applications Specialist Cabot Corporation Office: (678) 297-1455
Nayana KNayana K
Can you please format the code with indentation and post here? 
Michele ToscanoMichele Toscano
Let me know if this shows up better………. Visualforce page:
Sample Request Header

Sample Request Header Edit:

New Sample Request Header

 

Customer Information

  * = Required Information












{!$User.FirstName} {!$User.LastName} Apex class: public with sharing class SampleEditPAge1 { Public Sample_Request_Account_Information__c samObj{set;get;} Public Sample_Request_Account_Information__c samObjTemp{set;get;} public string accName{set;get;} public string lclLan{set;get;} public string SampId = ''; public string OpId = ''; public string AcId = ''; public string RecordTypeVal{set;get;} public boolean hasIdval{set;get;} public boolean hasNotIdval{set;get;} public string gotoNewPage{set;get;} // public Map mapRecTypes = new Map(); public SampleEditPAge1(ApexPages.StandardController controller) { samObj = new Sample_Request_Account_Information__c(); samObjTemp = new Sample_Request_Account_Information__c(); gotoNewPage = 'not sure'; accName = ''; SampId= apexpages.CurrentPage().getParameters().get('id'); OpId= apexpages.CurrentPage().getParameters().get('oppid'); AcId= apexpages.CurrentPage().getParameters().get('accId'); hasNotIdval = false; hasIdval = true; if(SampId != null && SampId !=''){ hasIdval = false; hasNotIdval = true; samObj = [select id,Account_Name__c,Requested_Delivery_Date__c,Freight_Charge__c,Data_Sheet_Required__c,Account_Name__r.Name,Status__c,Approvel_Date__c,Total_weight__c,CABOT_Segment__c,Account_Region__c ,Senior_Approver_Name__c , Customer_Group__c ,OwnerId,Account_Manager__c ,JDE__c,Bill_To_JDE_AB__c,LCL_Address__c,JDE_Order_Number__c,Ship_To_Address_Line_1__c,Ship_To_Address_Line_2__c,Ship_To_Address_Line_3__c,Ship_To_Address_Line_4__c,Ship_To_City__c,Ship_To_Country__c,Ship_To_Postal_Code__c,Ship_To_State__c,Opportunity_Name__c,Notes__c,Is_This_an_SA__c, Requested_Ship_From_Location__c,Planning_Account__c,Transportation_Method__c,Transportation_Notes__c,Invoice_Required__c,COA_Required__c,MSDS_Required__c,Contact_Name__c,Customer_Reference_Number__c,Technical_Manager__c,Account_Manager_Email_Address__c,Other_Person_to_Notify_1__c,Other_Person_to_Notify_2__c,Other_Person_2_Email_Address__c,OAP_Order_Number__c,OAP_URL_Link__c, Other_Person_1_Email_Address__c from Sample_Request_Account_Information__c where id=:SampId ]; accName =samObj.Account_Name__r.name; } else if(OpId != null && OpId !='') { Opportunity opp = [select id,Name,Account.OwnerId,Account.Country__c,Account.City__c,Account.State__c,Account.Technical_Service_Manager__c,Account.ParentId,Account.Postal_Code__c,Account.State_Code__c,Account.Address_Line_1__c,Account.LCL_Address_Line_1__c,Account.Address_Line_2__c,Account.LCL_Address_Line_2__c,Account.Address_Line_3__c,Account.LCL_Address_Line_3__c,Account.Address_Line_4__c,Account.LCL_Address_Line_4__c, Account.LCL_Country__c,Account.LCL_State__c,Account.LCL_State_Code__c,Account.LCL_City__c,Account.LCL_Postal_Code__c,Account.Customer_Care__c,Account.Price_Data_Admin__c,AccountId,Account.Customer_Group_Description__c ,Account.Sub_Region__c,Account.Name,Account.CABOT_Segment__c,Account.Account_Type__c,Account.CABOT_Application__c,Account.Currency_Code__c from Opportunity where id =:OpId limit 1]; if(opp != null && opp.id != null) { system.debug('==opp=='+opp); system.debug('==opp.id=='+opp.id); system.debug('==Technical_Service_Manager__c=='+samObj.Technical_Manager__c); system.debug('==samObj.Account_Manager__c=='+samObj.Account_Manager__c); accname=opp.account.name; samObj.Account_Name__c = opp.AccountId; samObj.Opportunity_Name__c = opp.Id; samObj.Planning_Account__c= opp.Account.ParentId; samObj.Account_Manager__c= opp.Account.OwnerId; samObj.Technical_Manager__c= opp.Account.Technical_Service_Manager__c; samObj.Customer_Group__c= opp.Account.Customer_Group_Description__c; samObj.CABOT_Segment__c= opp.Account.CABOT_Segment__c; samObj.Ship_To_Address_Line_1__c= opp.Account.Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= opp.Account.Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= opp.Account.Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= opp.Account.Address_Line_4__c; samObj.Account_Region__c= opp.Account.Sub_Region__c; samObj.Ship_To_Country__c= opp.Account.Country__c; samObj.Ship_To_State__c= opp.Account.State__c; samObj.Ship_To_City__c= opp.Account.City__c; samObj.Ship_To_Postal_Code__c= opp.Account.Postal_Code__c; } } else if(AcId != null && AcId !=''){ Account acc = [select id,Name,OwnerId,Sub_Region__c,City__c,State__c,Country__c,Postal_Code__c,Technical_Service_Manager__c,ParentId,State_Code__c,Address_Line_1__c,LCL_Address_Line_1__c,Address_Line_2__c,LCL_Address_Line_2__c,Address_Line_3__c,LCL_Address_Line_3__c,Address_Line_4__c,LCL_Address_Line_4__c,LCL_Country__c,LCL_State__c,LCL_State_Code__c,LCL_City__c,LCL_Postal_Code__c,Credit_Manager__c,Account_INCOTERMS__c,CABOT_Business__c,Currency_Code__c,Customer_Care__c,Price_Data_Admin__c ,Customer_Group_Description__c,Account_Type__c,CABOT_Segment__c,CABOT_Application__c from Account where id =:AcId and Account_Status__c ='Active' limit 1]; if(acc != null && acc.id != null) { accName =acc.id; system.debug('==Technical_Service_Manager__c=='+samObj.Technical_Manager__c); system.debug('==samObj.Account_Manager__c=='+samObj.Account_Manager__c); samObj.Account_Name__c = acc.id; samObj.Planning_Account__c= acc.ParentId; samObj.Customer_Group__c= acc.Customer_Group_Description__c; samObj.CABOT_Segment__c= acc.CABOT_Segment__c; samObj.Account_Manager__c=acc.OwnerId; samObj.Technical_Manager__c= acc.Technical_Service_Manager__c; samObj.Ship_To_Address_Line_1__c= acc.Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= acc.Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= acc.Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= acc.Address_Line_4__c; samObj.Account_Region__c= acc.Sub_Region__c; samObj.Ship_To_Country__c= acc.Country__c; samObj.Ship_To_State__c= acc.State__c; samObj.Ship_To_City__c= acc.City__c; samObj.Ship_To_Postal_Code__c= acc.Postal_Code__c; } } else samObj = (Sample_Request_Account_Information__c)controller.getRecord(); } public void populateData() { system.debug('==accName &&&&&==>>'+accName); if(accName != null && accName !='') { List listacc = [select id,Name,OwnerId,Sub_Region__c,City__c,State__c,Country__c,ParentId,Postal_Code__c,Technical_Service_Manager__c,State_Code__c,Address_Line_1__c,LCL_Address_Line_1__c,Address_Line_2__c,LCL_Address_Line_2__c,Address_Line_3__c,LCL_Address_Line_3__c,Address_Line_4__c,LCL_Address_Line_4__c,LCL_Country__c,LCL_State__c,LCL_State_Code__c,LCL_City__c,LCL_Postal_Code__c,Credit_Manager__c,Account_INCOTERMS__c,CABOT_Business__c,Currency_Code__c,Customer_Care__c,Price_Data_Admin__c ,Customer_Group_Description__c,Account_Type__c,CABOT_Segment__c,CABOT_Application__c from Account where id=:accName and Account_Status__c ='Active' limit 1]; if(listacc != null && !listacc.isEmpty()) { system.debug('==accName=='+accName); system.debug('==Technical_Service_Manager__c=='+samObj.Technical_Manager__c); system.debug('==samObj.Account_Manager__c=='+samObj.Account_Manager__c); Account acc = listacc[0]; samObj.Planning_Account__c= acc.ParentId; samObj.Customer_Group__c= acc.Customer_Group_Description__c; samObj.CABOT_Segment__c= acc.CABOT_Segment__c; samObj.Account_Manager__c= acc.OwnerId; samObj.Technical_Manager__c= acc.Technical_Service_Manager__c; samObj.Ship_To_Address_Line_1__c= acc.Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= acc.Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= acc.Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= acc.Address_Line_4__c; samObj.Account_Region__c= acc.Sub_Region__c; samObj.Ship_To_Country__c= acc.Country__c; samObj.Ship_To_State__c= acc.State__c; samObj.Ship_To_City__c= acc.City__c; samObj.Ship_To_Postal_Code__c= acc.Postal_Code__c; } } } public void populatelcladdress() { system.debug('==accName *** =='+accName); if(accName != null && accName !='') { List listacc = [select id,Name,OwnerId,Sub_Region__c,City__c,State__c,ParentId,Country__c,Postal_Code__c,State_Code__c,Address_Line_1__c,Technical_Service_Manager__c,LCL_Address_Line_1__c,Address_Line_2__c,LCL_Address_Line_2__c,Address_Line_3__c,LCL_Address_Line_3__c,Address_Line_4__c,LCL_Address_Line_4__c,LCL_Country__c,LCL_State__c,LCL_State_Code__c,LCL_City__c,LCL_Postal_Code__c,Credit_Manager__c,Account_INCOTERMS__c,CABOT_Business__c,Currency_Code__c,Customer_Care__c,Price_Data_Admin__c ,Customer_Group_Description__c,Account_Type__c,CABOT_Segment__c,CABOT_Application__c from Account where name =:accName and Account_Status__c ='Active' limit 1]; if(listacc != null && !listacc.isEmpty()) { system.debug('==accName=='+accName); Account acc = listacc[0]; if(samObj.LCL_Address__c){ samObj.Ship_To_Address_Line_1__c= acc.LCL_Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= acc.LCL_Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= acc.LCL_Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= acc.LCL_Address_Line_4__c; samObj.Account_Region__c= acc.Sub_Region__c; samObj.Ship_To_Country__c= acc.LCL_Country__c; samObj.Ship_To_State__c= acc.LCL_State__c; samObj.Ship_To_City__c= acc.LCL_City__c; samObj.Ship_To_Postal_Code__c= acc.LCL_State_Code__c; } else{ samObj.Ship_To_Address_Line_1__c= acc.Address_Line_1__c; samObj.Ship_To_Address_Line_2__c= acc.Address_Line_2__c; samObj.Ship_To_Address_Line_3__c= acc.Address_Line_3__c; samObj.Ship_To_Address_Line_4__c= acc.Address_Line_4__c; samObj.Account_Region__c= acc.Sub_Region__c; samObj.Ship_To_Country__c= acc.Country__c; samObj.Ship_To_State__c= acc.State__c; samObj.Ship_To_City__c= acc.City__c; samObj.Ship_To_Postal_Code__c= acc.Postal_Code__c; } } } } public pagereference savesamp() { //Prevent user from entering a sample request using an Inactive account or one without an address line 1 -07/19/16 MT if(acc.Account_Status__c == 'Inactive' || acc.Address_Line_1__c == '') ApexPages.Message SampleNotAllowed = new ApexPages.Message(ApexPages.Severity.ERROR,'Account must be active and contain an address in order to raise a sample request.'); ApexPages.addMessage(SampleNotAllowed); //Return null so the page won't redirect return null; try{ upsert samObj; }Catch(Exception ex) { ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,ex.getMessage()); ApexPages.addMessage(errorMessage); return null; } return new pagereference('/'+samObj.id); } public pagereference saveandnew() { try{ upsert samObj; gotoNewPage = 'sure'; }Catch(Exception ex) { ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,ex.getMessage()); ApexPages.addMessage(errorMessage); return null; } return null; } public pagereference Cancel() { if((SampId == null || SampId =='') && (OpId == null || OpId =='') && (AcId == null || AcId == '') ) return new pagereference('/a0h'); if(SampId != null && SampId !='' && (OpId == null || OpId =='') && (AcId == null || AcId =='')) return new pagereference('/'+SampId); if(AcId != null && AcId !='') return new pagereference('/'+AcId); if(OpId != null && OpId !='') return new pagereference('/'+OpId); return null; } } Regards, Michele Toscano Senior Applications Specialist Cabot Corporation Office: (678) 297-1455
Head In CloudHead In Cloud
Hi,

Change this line:
if({!ISPICKVAL(Account.Account_Status__c, "Inactive")} || {!Account.Address_Line_1__c} == '')

to this:
if(Account.Account_Status__c == 'Inactive' || Account.Address_Line_1__c == '')

 
Michele ToscanoMichele Toscano
Awesome, that seems to work! However, it’s complaining that SampleNotAllowed variable doesn’t exist. But I’m instantiating it below. What am I missing? ApexPages.Message SampleNotAllowed = new ApexPages.Message(ApexPages.Severity.ERROR,'Account must be active and contain an address in order to raise a sample request.'); ApexPages.addMessage(SampleNotAllowed); Regards, Michele Toscano Senior Applications Specialist Cabot Corporation Office: (678) 297-1455
Head In CloudHead In Cloud
Here is the updated code for your function. Please try it:
public pagereference savesamp()
        //Prevent user from entering a sample request using an Inactive account or one without an address line 1 -07/19/16 MT
    {    
        if(Account.Account_Status__c == 'Inactive' || Account.Address_Line_1__c == ''){
            ApexPages.Message SampleNotAllowed = new ApexPages.Message(ApexPages.Severity.ERROR,'Account must be active and contain an address in order to raise a sample request.'); 
            ApexPages.addMessage(SampleNotAllowed);
            return null;
        }

        
        

try{
          
        upsert samObj;
        
      }Catch(Exception ex)
      {
         ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,ex.getMessage());
         ApexPages.addMessage(errorMessage);
        return null;
      }
     return new pagereference('/'+samObj.id);
    }

Please mark as solved if it helps. Thanks
Michele ToscanoMichele Toscano
It says on the line with the If – comparison arguments must be compatible types: Schema.SObjectField, String public pagereference savesamp() { //Prevent user from entering a sample request using an Inactive account or one without an address line 1 -07/20/16 MT if(Account.Account_Status__c == 'Inactive' || Account.Address_Line_1__c == ''){ ApexPages.Message SampleNotAllowed = new ApexPages.Message(ApexPages.Severity.ERROR,'Account must be active and contain an address in order to raise a sample request.'); ApexPages.addMessage(SampleNotAllowed); //Return null so the page won't redirect return null; } try{ upsert samObj; }Catch(Exception ex) { ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,ex.getMessage()); ApexPages.addMessage(errorMessage); return null; } return new pagereference('/'+samObj.id); } Regards, Michele Toscano Senior Applications Specialist Cabot Corporation Office: (678) 297-1455
Head In CloudHead In Cloud
By looking at your code, i think the api name for account lookup on your custom object is :"Account_Name__c"
Try this:
public pagereference savesamp()
        //Prevent user from entering a sample request using an Inactive account or one without an address line 1 -07/19/16 MT
    {    
        if(samObj.Account_Name__r.Account_Status__c == 'Inactive' || samObj.Account_Name__r.Address_Line_1__c == ''){
            ApexPages.Message SampleNotAllowed = new ApexPages.Message(ApexPages.Severity.ERROR,'Account must be active and contain an address in order to raise a sample request.'); 
            ApexPages.addMessage(SampleNotAllowed);
            return null;
        }

        
        

try{
          
        upsert samObj;
        
      }Catch(Exception ex)
      {
         ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,ex.getMessage());
         ApexPages.addMessage(errorMessage);
        return null;
      }
     return new pagereference('/'+samObj.id);
    }

 
This was selected as the best answer
Michele ToscanoMichele Toscano
That was exactly correct! Wonderful! Regards, Michele Toscano Senior Applications Specialist Cabot Corporation Office: (678) 297-1455
Head In CloudHead In Cloud
Please mark as solution if it helped you. Thanks