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
ArrgHunterArrgHunter 

complier error in string assignment.

Hi,

 

i am trying to assign a string value to text type custom field on line 7 but getting the complier error "Expression cannot be assigned "

 

any idea what i am missing?

 

 

thanks,

ublic class IRPTemplateSelection {

public PageReference TemplateSelection() {
        
        // String TemplateId = 'a0JP0000001qGwU'; 
        String TemplateId = System.currentPageReference().getParameters().get('Templateid');
        Orphan__c.Biodata_Report_Template_4_Conductor__c = TemplateId ;
        
        PageReference pageRef = new PageReference('https://cs4.salesforce.com/a0A?fcf=00B20000005raAO' );
        pageRef.setRedirect(true);

        return pageRef; 

    }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

Can you try with

String TemplateId = Apexpages.currentPage().getParameters().get('Templateid');


 

All Answers

pradyprady

Hi,

 

Check what value are you getting in TemplateId

String TemplateId = System.currentPageReference().getParameters().get('Templateid');

My guess is you are not getting the values in there

Prafull G.Prafull G.

Can you try with

String TemplateId = Apexpages.currentPage().getParameters().get('Templateid');


 

This was selected as the best answer
ArrgHunterArrgHunter

HI Crmtech21,

 

thanks it error is now gone.

 

but my custom field is still not being updated. it has no value in it. how i can update it ???

 

Biodata_Report_Template_4_Conductor__c is text field.

 

 thanks

 

 

public class IRPTemplateSelection {

public PageReference TemplateSelection() {
        
        Orphan__c MyOrp = new Orphan__c();
        String TemplateId = Apexpages.currentPage().getParameters().get('Templateid');
        
        if (TemplateId != '')
        {myorp.Biodata_Report_Template_4_Conductor__c = TemplateId;}
        else
        {myorp.Biodata_Report_Template_4_Conductor__c = 'a0JP0000001qGwU';}
        
        PageReference pageRef = new PageReference('https://cs4.salesforce.com/a0A?fcf=00B20000005raAO');
        pageRef.setRedirect(true);

        return pageRef;

    }
}
Prafull G.Prafull G.

You are assigning value to the custom field "Biodata_Report_Template_4_Conductor__c" but not performing any DML operations like insert/update.

 

By viewing your below code

 

line1      Orphan__c MyOrp = new Orphan__c();

               String TemplateId = Apexpages.currentPage().getParameters().get('Templateid');

               if (TemplateId != '')

                              {myorp.Biodata_Report_Template_4_Conductor__c = TemplateId;}

               else

                              {myorp.Biodata_Report_Template_4_Conductor__c = 'a0JP0000001qGwU';}

               //you need to put some dml operation here

               insert myorp;

 

P.S. I believe you want to update the myorp.. so you need to get the record which you want to update. The statement at line1 will always create a new instance.

If you are passing the orphan id using query string parameters as well you can do the update using below code

 

String oprId = Apexpages.currentPage().getParameters().get(‘id’);         // id – key which having orp id

Orphan__c MyOrp = new Orphan__c(Id=orpId);

String TemplateId = Apexpages.currentPage().getParameters().get('Templateid');

if (TemplateId != '')

               {myorp.Biodata_Report_Template_4_Conductor__c = TemplateId;}

else

               {myorp.Biodata_Report_Template_4_Conductor__c = 'a0JP0000001qGwU';}

 

//you need to put some dml operation here

update myorp;

 

Let me know if this solves your query.